galygious

Installer

Feb 21st, 2020
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.06 KB | None | 0 0
  1. --[[
  2. GalyOS - Installer
  3. Location: nil
  4. Version Number: 0.4.2
  5. --]]
  6.  
  7. -- Variables
  8.     inst = false
  9.     version = false
  10.     yes = false
  11.     no = false
  12.     vn = "0.4.2"
  13.     filedir = {'','','','progs/','progs/','progs/'}
  14.     filenames = {'install.lua','startup.lua','GalyAPI','DigRoom','move','tturn'}
  15.     files = {'V8G8uaMg','cTmW8KS2','aY6Kbsz6','kC5ceV7Y','jU6WCxDA','zJaJZM55'}
  16.    
  17.  
  18. -- Functions
  19.     function fixstartup()
  20.         if fs.exists("/startup.lua") then
  21.             startup = fs.open("/startup.lua","r")
  22.             firstline = startup.readLine()
  23.             if firstline == "shell.run('install.lua')" then
  24.                 print("Deleting installer startup line")
  25.                 startup.close()
  26.                 startup = fs.open("/startup.lua","r")
  27.                 startuptext = startup.readAll()
  28.                 startup.close()
  29.                 newstartuptext = string.sub(startuptext,26)
  30.                 startup= fs.open("/startup.lua","w")
  31.                 startup.write(newstartuptext)
  32.                 startup.close()
  33.             else
  34.                 startup.close()
  35.             end
  36.         end
  37.     end
  38.    
  39.     function mkdir(dir)
  40.         shell.run("mkdir",dir)
  41.     end
  42.  
  43.     function install(dir,name,pb)
  44.         shell.run("pastebin","get",pb,dir..name)
  45.     end
  46.    
  47.     function update(name,pb)
  48.         print("Checking if installer is up to date")
  49.         shell.run("pastebin","get",pb,"/temp/" .. name)
  50.         tempfile = fs.open("/temp/" .. name, 'r')
  51.         for i=1,4 do
  52.             line = tempfile.readLine()
  53.             if i==4 then
  54.                 pbver = string.sub(line,17)
  55.                 if pbver == vn then
  56.                     fs.delete("/temp")
  57.                     print("Installer is up to date")
  58.                 else
  59.                     print("Installer is out of date")
  60.                     print("New version = |" .. pbver .. "|")
  61.                     print("Current version = |" .. vn .. "|")
  62.                     print("Would you like me to update you to the new version?")
  63.                     print("y = yes - n = no")
  64.                     while yes == false and no == false do
  65.                         sleep(1)
  66.                     end
  67.                     if yes == true then
  68.                         print("Replacing Installer")
  69.                         os.sleep(5)
  70.                         term.clear()
  71.                         term.setCursorPos(1,1)
  72.                         fs.delete("/"..name)
  73.                         fs.copy("/temp/" .. name , "/" .. name)
  74.                         fs.delete("/temp")
  75.                         term.clear()
  76.                         term.setCursorPos(1,1)
  77.                         startup = fs.open("/startup.lua","r")
  78.                         startuptext = startup.readAll()
  79.                         startup.close()
  80.                         startuptextnew = ("shell.run('install.lua')\n") .. startuptext
  81.                         print("Appending startup file")
  82.                         fs.delete(shell.getRunningProgram())
  83.                         startup = fs.open("/startup.lua","w")
  84.                         startup.write(startuptextnew)
  85.                         startup.close()        
  86.                         print("Restarting")
  87.                         os.reboot()
  88.                     elseif no == true then
  89.                         no = false
  90.                         fs.delete("/temp")
  91.                     end
  92.                 end
  93.             end
  94.         end
  95.     end
  96.  
  97.     function quitProgram()
  98.         local event, param1 = os.pullEvent("char")
  99.         if param1 == "q" then
  100.             quit = true
  101.         elseif param1 == "i" then
  102.             inst = true
  103.         elseif param1 == "v" then
  104.             version = true
  105.         elseif param1 == "y" then
  106.             yes = true
  107.         elseif param1 == "n" then
  108.             no = true
  109.         end
  110.     end
  111.  
  112.     function Program()
  113.         term.clear()
  114.         term.setCursorPos(1,1)
  115.         print("Welcome to GalyOS")
  116.         fixstartup()
  117.         update(filenames[1],files[1])
  118.         print("At any time you may press Q to quit")
  119.         print("Press I to install")
  120.         print("Press v for version info")
  121.         while inst == false and version == false do
  122.             sleep(1)
  123.         end
  124.         if version == true then
  125.             term.clear()
  126.             term.setCursorPos(1,1)
  127.             --print version info
  128.             print("You are running Galycraft installer version " .. vn .. "\n\n")
  129.             print("To return to the installer press any key")
  130.             print("To quit installer press Q")
  131.             local event, key = os.pullEvent( "key" )
  132.             if key then
  133.                 version = false
  134.                 Program()
  135.             end
  136.         end
  137.         if inst == true then
  138.             term.clear()
  139.             term.setCursorPos(1,1)
  140.             print("Installing GalyOS\n")
  141.             for i=2,#filenames do
  142.                 install(filedir[i],filenames[i],files[i])
  143.             end
  144.         end
  145.         fs.delete(shell.getRunningProgram())
  146.         print("Install Complete")
  147.         print("Press r to restart terminal")
  148.         local event, key = os.pullEvent( "key" )
  149.         if key == keys.r then
  150.             os.reboot()
  151.         end
  152.        
  153.     end
  154.  
  155.    
  156.     while true do
  157.         parallel.waitForAny(quitProgram, Program)
  158.         if quit then
  159.             print("Quitting....")
  160.             break
  161.         end
  162.  
  163.         --Other code
  164.         sleep(0.05) --Sleep 1 tick
  165.     end
Advertisement
Add Comment
Please, Sign In to add comment