SHOW:
|
|
- or go back to the newest paste.
| 1 | - | -- Table of program name - pastebin string pairs |
| 1 | + | ------------------------------------------------------------ |
| 2 | -- fetch | |
| 3 | -- This program fetches pastebins based on an internal table | |
| 4 | - | {"stripmine", "7Q3kjTQB"}
|
| 4 | + | -- To use run: fetch programname |
| 5 | ------------------------------------------------------------ | |
| 6 | ||
| 7 | -- Table of <program name, pastebin string> pairs | |
| 8 | local progTable = {
| |
| 9 | {"quarry", "HKvSqARi"},
| |
| 10 | {"stripmine", "7Q3kjTQB"},
| |
| 11 | {"fetch", "313muKuG"}
| |
| 12 | } | |
| 13 | ||
| 14 | - | -- get the value from the table |
| 14 | + | |
| 15 | -- Get the target | |
| 16 | if (arg[1] == nil) then | |
| 17 | print("Specify a program")
| |
| 18 | return | |
| 19 | end | |
| 20 | ||
| 21 | -- Check if the target exists in the table | |
| 22 | target = nil | |
| 23 | for i = 1, #progTable do | |
| 24 | if (arg[1] == progTable[i][1]) then | |
| 25 | target = progTable[i][2] | |
| 26 | end | |
| 27 | end | |
| 28 | ||
| 29 | if (target == nil) then | |
| 30 | print("Target not found.")
| |
| 31 | return | |
| 32 | end | |
| 33 | ||
| 34 | -- the program was found | |
| 35 | name = arg[1] .. ".lua" | |
| 36 | -- remove the current version | |
| 37 | res1 = shell.run("rm", name)
| |
| 38 | -- get the new version | |
| 39 | res2 = shell.run("pastebin", "get", target, name)
| |
| 40 | ||
| 41 | if (res1 and res2) then | |
| 42 | print("Fetched " .. name)
| |
| 43 | else | |
| 44 | print("Fetch failed")
| |
| 45 | end | |
| 46 | end | |
| 47 | ||
| 48 | main() |