Advertisement
Tinybang_Studio

apt

Feb 13th, 2021 (edited)
1,090
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local version = "0.12"
  2.  
  3. if not http then
  4.   printError( "Script requires http API" )
  5.   printError( "Set http_enable to true in ComputerCraft.cfg" )
  6.   return
  7. end
  8.  
  9. function get(url)
  10.   write( "Connecting to server... " )
  11.  
  12.   http.request("https://meinkraftcult.repl.co/"..url)
  13.  
  14.   local requesting = true
  15.  
  16.   while requesting do
  17.     local event, url, sourceText = os.pullEvent()
  18.  
  19.     if event == "http_success" then
  20.       local respondedText = sourceText.readAll()
  21.       sourceText.close()
  22.    
  23.       requesting = false
  24.       return respondedText
  25.     elseif event == "http_failure" then
  26.             print(url)
  27.       printError("Server didn't respond.")
  28.    
  29.       requesting = false
  30.     end
  31.   end
  32. end
  33.  
  34. function install(program,xpath)
  35.     if fs.exists(xpath) then fs.delete(xpath) end
  36.     local res = get(program..".lua")
  37.     if res then        
  38.         local file = fs.open(xpath, "w" )
  39.         file.write( res )
  40.         file.close()
  41.         print( "Downloaded as "..fs.getName(xpath) )
  42.     end
  43. end
  44.  
  45. -- Update
  46.  
  47. if get("apt/version") ~= version then
  48.     install("apt/get","apt")
  49. end
  50.  
  51. -- Run
  52.  
  53. local Args = {...}
  54.  
  55. if #Args == 2 then
  56.     install(unpack(Args))
  57. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement