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

installer front end

Started by coolmark1995, 10 April 2015 - 05:31 AM
coolmark1995 #1
Posted 10 April 2015 - 07:31 AM
Hello I was wondering is there a way I can make a pastbin run code download another pastebin file install it then reboot OS or is it not possible?
HPWebcamAble #2
Posted 10 April 2015 - 08:31 AM
So basically, you want a single file on pastebin that you can download, which then downloads a bunch of other files?

Well, that just an installer, a lot of programs use it if the program uses more than one file.


You can use 'shell.run("pastebin get <code> <name")', but it doesn't return anything, you'd have to check to see if the file exists to make sure the download worked.

Instead of relying on that, you can use this (slightly modified) function from the pastebin program:

function get(sCode,sFile)
  local sPath = shell.resolve( sFile )
  if fs.exists( sPath ) then
	return false
  end
  local response = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode( sCode ))
  if response then			  
	local sResponse = response.readAll()
	response.close()			
	local file = fs.open( sPath, "w" )
	file.write( sResponse )
	file.close()
	return true		  
  else
	return false
  end	
end
It returns true if the file was downloaded, false if it couldn't for any reason

Then, your 'installer' file would look something like this:

local problem = false

if not get("code1","path1") then
  print("Could not download 'path1' program")
  problem = true
else
  print("Downloaded 'path1' shortcut program")
end

if not get("code2","path2") then
  print("Could not download 'path2' program")
  problem = true
else
  print("Downloaded 'path2' program")
end

--# ect

if problem then
  term.setTextColor(colors.red)
  print("Something when wrong. Program was not installed correctly")
else
  term.setTextColor(colors.lime)
  print("Program installed!")
end


Finally, restarting the computer is really easy, just call this in your program:

os.reboot()
Edited on 10 April 2015 - 06:31 AM