Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = {...}
- --Variable Configuration
- -- 0 = pastebin override used - will not use config file | 1 = use config file for the pastebin code
- files = 0
- -- Pastebin file code
- codeTxt = " "
- prog = " "
- -- Various variables - x is for error checking
- x = 1
- y = 1
- z = 1
- if args[1] == "Help" or args[1] == "help" or args[1] == "HELP" then
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.orange)
- print("Pastebin Updater Help - Page 1")
- print(" ")
- term.setTextColor(colors.white)
- print("Command Usage:")
- print("update [file name] [pastebin code]")
- print("The pastebin code is only needed if you want to use a different one than provided in the configuration file")
- print(" ")
- print("Press any key to continue")
- os.pullEvent( 'key' )
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.orange)
- print("Pastebin Updater Help - Page 2")
- print(" ")
- term.setTextColor(colors.white)
- print("If a config file isn't found for a program, the updater will make one and ask you to provide the pastebin code.")
- print(" ")
- print("The code is the text that comes after pastebin.com/")
- print(" ")
- print("If you incorrectly type the pastebin code, the only way to change it is to either edit the config file, or delete it and have the updater make a new one.")
- print(" ")
- print("Update files are named as \"program.pbu\"")
- print("For example, the update file for the program \"test\" would be \"test.pbu\"")
- print("Press any key to continue")
- os.pullEvent( 'key' )
- print("end of help segment")
- x = 0
- end
- if args[1] == nil then
- x = 0
- term.setTextColor(colors.red)
- print("Error: Missing Parameter! File name is required!")
- else
- prog = args[1]
- end
- if args[2] ~= nil then
- print("Override parameter detected! Using this instead of config file.")
- codeTxt = args[2]
- else
- files = 1
- end
- -- Updater
- term.setTextColor(colors.white)
- if x == 1 then
- term.clear()
- term.setCursorPos(1,1)
- -- checks if it is to use the config file or just use the override if provided
- if files == 1 then
- print("Checking for " .. prog .. "'s config file")
- -- Checks if the config file exists. If it doesn't, it creates one
- if not fs.exists(prog ..".pbu") then
- y = 0
- term.setTextColor(colors.red)
- print("Warning: Config file not found!")
- term.setTextColor(colors.white)
- print("We will now create one for future reference")
- -- Code Input Loop
- while y == 0 do
- term.setTextColor(colors.white)
- print("Please enter the pastebin code we will use to update this program:")
- codeTxt = read()
- z = 0
- -- Code Confirmation Loop
- while z == 0 do
- term.setTextColor(colors.white)
- print(codeTxt .. " - Is this code correct? y/n")
- confirm = read()
- if confirm == "n" then
- z = 1
- elseif confirm == "y" then
- term.setTextColor(colors.green)
- print("Code confirmed!")
- term.setTextColor(colors.white)
- y = 1
- z = 1
- else
- term.setTextColor(colors.red)
- print("Invalid input! Please try again.")
- end
- end
- end
- print("Generating file and updating the program")
- config = fs.open(prog ..".pbu" , "w")
- config.write(codeTxt)
- config.close()
- print("Config file generated! Now updating your program")
- fs.delete(prog)
- shell.run("pastebin get " .. codeTxt .. " " .. prog)
- print("Program updated!")
- else
- print("Config file detected!")
- sleep(1)
- term.clear()
- term.setCursorPos(1,1)
- config = fs.open(prog .. ".pbu", "r")
- codeTxt = config.readLine()
- config.close()
- print("Pastebin code obtained!")
- print("Updating Program!")
- fs.delete(prog)
- shell.run("pastebin get " .. codeTxt .. " " .. prog)
- print("Program updated!")
- end
- else
- print("Updating progam using the override...")
- fs.delete(prog)
- shell.run("pastebin get " .. codeTxt .. " " .. prog)
- print("Program updated!")
- end
- else
- print("Updater Terminated")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement