This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Andale's profile picture

[1.4] Andale's Auto Updater w/ Startup

Started by Andale, 24 January 2013 - 08:33 AM
Andale #1
Posted 24 January 2013 - 09:33 AM
What it does:
Creates a 'startup' file that will automatically redownload the pastebin file you specify and then run it every time the pc boots.
After startup creation it deletes itself. (Not sure why I thought that was a good idea, I have commented it out for now.)

Why:
Because I do my editing in Notepad2 then upload to pastebin and do small corrections on the site.

Usage:
Download with

/rom/programs/http/pastebin get 2piRGMv2 auto
Name it whatever you want (auto is just what i use for example)

Run and answer the questions or use prompt commands:

auto PaStEbInCoDe nameoffile
(No spaces in filename from command prompt)

http://pastebin.com/2piRGMv2
Spoiler

local tArgs = {...}
local code, filename = tArgs[1], tArgs[2]
if #tArgs ~= 2 then
	print ("Usage: <thisfile> <PasteBINcode> /<filename_to_use>")
	sleep (2)
	print ("That's ok, we can do it now.")
	sleep (1)
	print ("What is your pastebin code? ")
	print ("(Example: pastebin.com/GvwZ4r is GvwZ4r)")
	code = read()
	if code == "2piRGMv2" then
		repeat
			print ("No. That's this program. Try again!")
			code = read()
		until code ~= "2piRGMv2"
	end
	print ("What name do you want for your program?")
	print ("(include /disk/ if used, works in prompt too)")
	filename = read()
	if filename == "startup" or filename == "Startup" then
		repeat
			print ("This program will create a startup file. Choose another!")
			filename = read()
		until filename ~= "startup"
	end
end


while filename == "startup" do
	print ("This program will create a startup file. Choose another.")
	filename = read ()
end

while code == "2piRGMv2" do
	print ("No. That's this program.")
	code = read()
end

-- ADD A PULL EVENT TO WARN/CANCEL DELETING STARTUP
stop=5
repeat
term.clear()
term.setCursorPos(1,1)
print("This WILL delete your current 'startup' file.")
print("Afterwards it will delete itself.")
print("Press CTRL+T to STOP!")
write (stop .. "...")
stop=stop-1
sleep(.8)
until stop == 0

del = shell.getRunningProgram()
fs.delete(del)

print("Deleting most likely copies of startup")
fs.delete("startup")
fs.delete("Startup")
fs.delete("StartUp")
fs.delete("StartUP")
fs.delete("STARTUP")

su=fs.open("startup", "w")
print ("opening file")
print("write")
su.writeLine('filename = "' ..filename.. '"')
su.writeLine('code = "' ..code.. '"')
su.write([[
print ("Deleting current copy!")
shell.run ("delete", filename)
sleep (0.1)
print ("Downloading from pastebin...")
shell.run ("/rom/programs/http/pastebin", "get", code, filename)
print ("Done!")
sleep (0.1)
print ("Running the file..." ..filename)
sleep (1)
shell.run (filename)
]])
print("closing file")
su.close()
sleep(0.5)
os.reboot()
return

Copy and change all you want but please point back to where you got it from if you use the base of it.
bjornir90 #2
Posted 07 February 2013 - 07:13 PM
Why does it delete itself ?
Andale #3
Posted 12 February 2013 - 08:49 PM
i thought it was a good idea for some reason. Something to do with the idea of not using extra space but didn't need it so disabled.
xXLeNinjaXx #4
Posted 12 January 2014 - 04:33 PM
How do ou make an auto updater :L?