Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- GalyOS - Installer
- Location: nil
- Version Number: 0.4.2
- --]]
- -- Variables
- inst = false
- version = false
- yes = false
- no = false
- vn = "0.4.2"
- filedir = {'','','','progs/','progs/','progs/'}
- filenames = {'install.lua','startup.lua','GalyAPI','DigRoom','move','tturn'}
- files = {'V8G8uaMg','cTmW8KS2','aY6Kbsz6','kC5ceV7Y','jU6WCxDA','zJaJZM55'}
- -- Functions
- function fixstartup()
- if fs.exists("/startup.lua") then
- startup = fs.open("/startup.lua","r")
- firstline = startup.readLine()
- if firstline == "shell.run('install.lua')" then
- print("Deleting installer startup line")
- startup.close()
- startup = fs.open("/startup.lua","r")
- startuptext = startup.readAll()
- startup.close()
- newstartuptext = string.sub(startuptext,26)
- startup= fs.open("/startup.lua","w")
- startup.write(newstartuptext)
- startup.close()
- else
- startup.close()
- end
- end
- end
- function mkdir(dir)
- shell.run("mkdir",dir)
- end
- function install(dir,name,pb)
- shell.run("pastebin","get",pb,dir..name)
- end
- function update(name,pb)
- print("Checking if installer is up to date")
- shell.run("pastebin","get",pb,"/temp/" .. name)
- tempfile = fs.open("/temp/" .. name, 'r')
- for i=1,4 do
- line = tempfile.readLine()
- if i==4 then
- pbver = string.sub(line,17)
- if pbver == vn then
- fs.delete("/temp")
- print("Installer is up to date")
- else
- print("Installer is out of date")
- print("New version = |" .. pbver .. "|")
- print("Current version = |" .. vn .. "|")
- print("Would you like me to update you to the new version?")
- print("y = yes - n = no")
- while yes == false and no == false do
- sleep(1)
- end
- if yes == true then
- print("Replacing Installer")
- os.sleep(5)
- term.clear()
- term.setCursorPos(1,1)
- fs.delete("/"..name)
- fs.copy("/temp/" .. name , "/" .. name)
- fs.delete("/temp")
- term.clear()
- term.setCursorPos(1,1)
- startup = fs.open("/startup.lua","r")
- startuptext = startup.readAll()
- startup.close()
- startuptextnew = ("shell.run('install.lua')\n") .. startuptext
- print("Appending startup file")
- fs.delete(shell.getRunningProgram())
- startup = fs.open("/startup.lua","w")
- startup.write(startuptextnew)
- startup.close()
- print("Restarting")
- os.reboot()
- elseif no == true then
- no = false
- fs.delete("/temp")
- end
- end
- end
- end
- end
- function quitProgram()
- local event, param1 = os.pullEvent("char")
- if param1 == "q" then
- quit = true
- elseif param1 == "i" then
- inst = true
- elseif param1 == "v" then
- version = true
- elseif param1 == "y" then
- yes = true
- elseif param1 == "n" then
- no = true
- end
- end
- function Program()
- term.clear()
- term.setCursorPos(1,1)
- print("Welcome to GalyOS")
- fixstartup()
- update(filenames[1],files[1])
- print("At any time you may press Q to quit")
- print("Press I to install")
- print("Press v for version info")
- while inst == false and version == false do
- sleep(1)
- end
- if version == true then
- term.clear()
- term.setCursorPos(1,1)
- --print version info
- print("You are running Galycraft installer version " .. vn .. "\n\n")
- print("To return to the installer press any key")
- print("To quit installer press Q")
- local event, key = os.pullEvent( "key" )
- if key then
- version = false
- Program()
- end
- end
- if inst == true then
- term.clear()
- term.setCursorPos(1,1)
- print("Installing GalyOS\n")
- for i=2,#filenames do
- install(filedir[i],filenames[i],files[i])
- end
- end
- fs.delete(shell.getRunningProgram())
- print("Install Complete")
- print("Press r to restart terminal")
- local event, key = os.pullEvent( "key" )
- if key == keys.r then
- os.reboot()
- end
- end
- while true do
- parallel.waitForAny(quitProgram, Program)
- if quit then
- print("Quitting....")
- break
- end
- --Other code
- sleep(0.05) --Sleep 1 tick
- end
Advertisement
Add Comment
Please, Sign In to add comment