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

Get startup from HTTP

Started by Dark Shadow, 20 October 2012 - 09:34 PM
Dark Shadow #1
Posted 20 October 2012 - 11:34 PM
Okay, so what I wanted to do was to create a startup file that would delete the original, get a new one from pastebin and save it as startup, this way I could edit the code in pastebin realtime and just update the computer and everything would be there…

what I got is this:



while true do
 term.clear()
 delete startup
 sleep(2)
 pastebin get km4CH8UV startup
 print("YAY!")
 end
end

although when i type in

pastebin get km4CH8UV startup

and then reboot the computer i get this error:

bios:206 [string "startup"]:3: '=' expected

I'm not really sure what I'm doing wrong, and I cant seem to find any tutorials about this
jag #2
Posted 21 October 2012 - 12:05 AM
Pastebin is a built in program, not a API or command.
If you want to use the pastebin program, try

shell.run("pastebin", "get", "km4CH8UV", "startup")

This is the same with delete.
The best way to delete a file is just to use the file system, like so

fs.delete("startup")

And I'm not totally sure why you got an end at line 7.
I guess that you thought that the pastebin program would act like an if statement or something…
Lasere123456 #3
Posted 21 October 2012 - 05:54 PM

shell.run("pastebin", "get", "km4CH8UV", "startup")

this returns no such program wend i run it.
jag #4
Posted 21 October 2012 - 11:36 PM
Well you need to have http on for this (you find it in the config)
ChaddJackson12 #5
Posted 22 October 2012 - 03:39 AM
Also, this post belongs in "Ask A Pro", not in Programs.
Dark Shadow #6
Posted 22 October 2012 - 06:53 PM
Hi again, first of all, sorry for posting in the wrong board, I'm new here, I'll improve next time! :)/>/>

Thank you for the help jag_e_nummer_ett

This is my startup program:



while true do
 term.clear()
 term.setCursorPos(1, 1)
 print("NewkOS has been locked nPlease enterpassword:")
 input = read("*")
 if input == "password" then
  term.clear()
  term.setCursorPos(1, 1)
  print("Password correctnWelcome to NewkOS")
  fs.delete("NewkOS")
  sleep(1)
  shell.run("pastebin", "get", "TWvZAJWq", "NewkOS")
  sleep(1)
  os.loadAPI("NewkOS", "test", "ing")
  shell.run("NewkOS", "test", "ing")
  shell.exit()
 else
  print("ACCESS DENIED")
  sleep(3)
  end
 end

and my main program, which it will download and run from the startup (lock)


while true do
 term.clear()
 term.setCursorPos(1, 1)
 print("NewkOS")
 input = read()
 if input == "shutdown" then
  os.shutdown()
 end

I'm not really sure this is the right way to make a password protection for the program. But when i type in "password" which should lead me to my main program it just restarts the startup program…

I'm not sure whats the problem here, any help would be great!

http://pastebin.com/km4CH8UV

http://pastebin.com/TWvZAJWq
Cranium #7
Posted 22 October 2012 - 07:50 PM

local version =
1.0

local code = "pastebin code you want here"

--check version
term.clear()
term.setCursorPos(1,1)
print("Program loading...")
print("Current version: "..version)
local updateSite= http.get("http://pastebin.com/raw.php?i="..code)
updateSite.readLine()
local newVersion = updateSite.readLine()
if tonumber(newVersion) > version then
	print("Update required. Updating now...")
	local updateSite = http.get("http://pastebin.com/raw.php?i="..code)
	local siteFile = updateSite.readAll()
	local writeFile = fs.open(shell.getRunningProgram(),"w")
	writeFile.write(siteFile)
	writeFile.close()
	print("The program will now restart your computer.")
	sleep(1)
	os.reboot()
end
This is the updating code I use on my programs. Just add your version number, (add higher numbers to update) and your pastebin code. It will automagically update your code with the current version on the pastebin site you specify.

Edit: ARGH!! DARN YOU FORUM SOFTWARE. Messed up my perfectly legible spacing :)/>/>
Edited on 22 October 2012 - 05:52 PM
Dark Shadow #8
Posted 22 October 2012 - 09:21 PM
That looks great Cranium!

I'll look into that as soon as possible…

About the security, is it possible to make it as an "overlay" running "above" the program, so that the main program is still running? Since the main program will controle a nuclear reactor it would be great if it could run, and still be locked :)/>/>