Advertisement
programcreator

OmniOS: Installer

Mar 24th, 2015
11,675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.15 KB | None | 0 0
  1. --[[
  2.     OmniOS Installer
  3. ]]
  4.  
  5. term.clear()
  6. term.setCursorPos(1,1)
  7. term.setTextColor(colors.white)
  8.  
  9.  
  10.  
  11. print("Welcome to the OmniOS Installer.")
  12. print("To proceed press enter.")
  13. read("")
  14.  
  15.  
  16. term.clear()
  17. term.setCursorPos(1,1)
  18.  
  19. print("Fetching versions...")
  20.  
  21. local handle = http.get("http://pastebin.com/raw/TuBL454Z")
  22. local data = handle.readAll()
  23.  
  24. print("Loading versions...")
  25.  
  26. local choices = loadstring(data)()
  27. local max = #choices
  28.  
  29. local selection = 1
  30.  
  31. local w, h = term.getSize()
  32.  
  33. local function draw()
  34.     term.clear()
  35.     for i,v in pairs(choices) do
  36.         if i == selection then
  37.             term.setTextColor(colors.cyan)
  38.             term.setCursorPos(math.floor((w-#v.name)/2 - 1), (i - selection) + math.floor(h/2))
  39.             term.write("["..v.name.."]")
  40.             term.setTextColor(colors.white)
  41.         else
  42.             term.setCursorPos(math.floor((w-#v.name)/2), (i - selection) + math.floor(h/2))
  43.             term.write(v.name)
  44.         end
  45.     end
  46. end
  47.  
  48. local function getURL(id)
  49.     local url = choices[id].source
  50.     if type(url) == "number" then
  51.         return getURL(url)
  52.     else
  53.         return url
  54.     end
  55. end
  56.  
  57. local go = true
  58.  
  59. while go do
  60.     draw()
  61.     local e, id = os.pullEvent("key")
  62.     if id == keys.up then
  63.         selection = selection - 1
  64.         if selection < 1 then
  65.             selection = 1
  66.         end
  67.     elseif id == keys.down then
  68.         selection = selection + 1
  69.         if selection > max then
  70.             selection = max
  71.         end
  72.     elseif id == keys.enter then
  73.         break
  74.     end
  75. end
  76.  
  77. term.clear()
  78. term.setCursorPos(1,1)
  79.  
  80. local url = getURL(selection)
  81. print("Are you sure you want to proceed? <y/n>")
  82.  
  83. local r = read()
  84.  
  85. if r == "y" then
  86.     local func = loadstring(http.get(url).readAll())
  87.     setfenv(func,_G)
  88.     func("OmniOS")
  89.     print("Thank you for installing OmniOS.")
  90. else
  91.     print("Thank you for not installing OmniOS.")
  92.     return
  93. end
  94.  
  95. print("Do you wish to boot OmniOS on startup? <y/n>")
  96.  
  97. local r = read()
  98.  
  99. if r == "y" then
  100.     if fs.exists("startup") then
  101.         fs.copy("startup", "startupbackup")
  102.     end
  103.     local file = fs.open("startup", "w")
  104.     file.write("dofile(\""..choices[selection].boot.."\")")
  105.     file.close()
  106. else
  107.     print("Boot OmniOS by running "..choices[selection].boot)
  108. end
  109.  
  110. print("Press ENTER to reboot")
  111. read()
  112. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement