Advertisement
LegoStax

Lithium OS Installer

Jul 24th, 2013
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.60 KB | None | 0 0
  1. --[[
  2.     Lithium OS Launcher by LegoStax
  3. ]]--
  4. function download(url, fn)
  5.     -- Download Function --
  6.     -- check for http api
  7.     if not http then
  8.         print("The HTTP API is not enabled.")
  9.         print("Please enable the API in ComputerCraft settings.")
  10.         return
  11.     else
  12.         -- if it's enabled then we download the file into the variable response and then write response to the file specified when the function is called
  13.         local response = http.get(url)
  14.         if response then
  15.             local data = response.readAll()
  16.             response.close()
  17.             local file = fs.open(fn, "w")
  18.             file.write(data)
  19.             file.close()
  20.         else
  21.             -- if there's no response or response is nil
  22.             print("No Response.  Are you connected to the internet?")
  23.             print("If you are, then Pastebin is down.")
  24.             return
  25.         end
  26.     end
  27. end
  28.  
  29. -- OS installation.  I'm going to replace this with a gui sooner or later
  30. if not fs.exists(".programs") then
  31.     shell.run("delete", "lithos")
  32.     print("Installing Lithium OS")
  33.     download("http://pastebin.com/raw.php?i=m5vPnePf", "lithos")
  34.     print("Installing Programs")
  35.     shell.run("mkdir", ".programs")
  36.     download("http://pastebin.com/raw.php?i=JSFdbuSJ", ".programs/lith")
  37.     download("http://pastebin.com/raw.php?i=aH3S7VhP", ".programs/login")
  38.     download("http://pastebin.com/raw.php?i=Mipa0pFt", ".programs/settings")
  39.     download("http://pastebin.com/raw.php?i=XcSsVkiN", ".programs/sha")
  40.     download("http://pastebin.com/raw.php?i=pnzdr8FB", ".programs/explorer")
  41.     print("Installing Images")
  42.     download("http://pastebin.com/raw.php?i=VjMZQdCX", ".programs/set-bg")
  43.     download("http://pastebin.com/raw.php?i=Uy34X768", ".programs/login_img")
  44.     download("http://pastebin.com/raw.php?i=WPUztxL0", ".programs/update_img")
  45.     download("http://pastebin.com/raw.php?i=Hdwh8X1C", ".programs/desktop")
  46.     print("Finished.")
  47.     print("NOTE: Anything seen in red is an unfinished feature")
  48.     print("Setup:")
  49.     write "Username: "
  50.     user = read()
  51.     x,y = term.getCursorPos()
  52.     term.setCursorPos(x,y+1)
  53.     write "Password: "
  54.     cpass = read("*")
  55.     os.loadAPI(".programs/sha")
  56.     cpass = sha.sha256(cpass)
  57.     info = {
  58.         user = nil;
  59.         cpass = nil;
  60.     }
  61.     info.user = user
  62.     info.cpass = cpass
  63.     local file = fs.open(".programs/user", "w")
  64.     file.write(info)
  65.     file.close()
  66.     print("Rebooting...")
  67.     sleep(2)
  68.     os.reboot()
  69. else
  70.     if not fs.exists(".programs/config") then
  71.         config = {
  72.             autoupdate = nil,
  73.             desktop_img = ".programs/desktop",
  74.             bgcolor = colors.white,
  75.             taskside = "top"
  76.         }
  77.         running = true
  78.         while running do
  79.             term.clear()
  80.             term.setCursorPos(1,1)
  81.             term.write("Autoupdate? (y/n)")
  82.             e = {os.pullEvent("key")}
  83.             if e[2] == keys.y then
  84.                 config.autoupdate = true
  85.                 running = false
  86.             elseif e[2] == keys.n then
  87.                 config.autoupdate = false
  88.                 running = false
  89.             end
  90.         end
  91.         local file = fs.open(".programs/config", "w")
  92.         file.write(textutils.serialize(config))
  93.         file.close()
  94.     end
  95.     if not fs.exists(".programs/user") then
  96.         write "Username: "
  97.         user = read()
  98.         x,y = term.getCursorPos()
  99.         term.setCursorPos(x,y+1)
  100.         write "Password: "
  101.         cpass = read("*")
  102.         os.loadAPI(".programs/sha")
  103.         cpass = sha.sha256(cpass)
  104.         info = {
  105.             user = nil;
  106.             cpass = nil;
  107.         }
  108.         info.user = user
  109.         info.cpass = cpass
  110.         local file = fs.open(".programs/user", "w")
  111.         file.write(textutils.serialize(info))
  112.         file.close()
  113.     end
  114.     config = {}
  115.     local file = fs.open(".programs/config", "r")
  116.     config = textutils.unserialize(file.readAll())
  117.     file.close()
  118.     if config.autoupdate == true then
  119.         bg = paintutils.loadImage(".programs/update_img")
  120.         paintutils.drawImage(bg, 1, 1)
  121.         term.setBackgroundColor(colors.lightGray)
  122.         term.setCursorPos(3,1)
  123.         term.write("Lithium OS - Update")
  124.         term.setCursorPos(26,14)
  125.         term.write(" Checking for updates...")
  126.         if not http then
  127.             -- tell user to turn on http api
  128.             term.setCursorPos(26,14)
  129.             term.write(" LithOS Updater cannot  ")
  130.             term.setCursorPos(26,15)
  131.             term.write(" work without the HTTP API")
  132.             sleep(3)
  133.         else
  134.             -- download file
  135.             local response = http.get("http://pastebin.com/raw.php?i=8Kvh0Sze")
  136.             if response then
  137.                 local data = response.readAll()
  138.                 response.close()
  139.                 local file = fs.open(".programs/update", "w")
  140.                 file.write(data)
  141.                 file.close()
  142.                 shell.run(".programs/update")
  143.                 if ver > 2.03 then
  144.                     term.setCursorPos(26,15)
  145.                     term.write(" New Version Available ")
  146.                     term.setCursorPos(26,16)
  147.                     term.write(" ")
  148.                     term.setBackgroundColor(colors.gray)
  149.                     term.setCursorPos(27,16)
  150.                     term.write("Update")
  151.                     term.setCursorPos(34,16)
  152.                     term.write("Later")
  153.                     choice = false
  154.                     while not choice do
  155.                         local event, button, x, y = os.pullEvent("mouse_click")
  156.                         if button == 1 then
  157.                             if x >= 27 and x <= 32 and y == 16 then
  158.                                 choice = true
  159.                                 -- Download new installer
  160.                                 local response = http.get("http://pastebin.com/raw.php?i=XYLELffE")
  161.                                 if response then
  162.                                     local data = response.readAll()
  163.                                     response.close()
  164.                                     local file = fs.open(".programs/startup", "w")
  165.                                     file.write(data)
  166.                                     file.close()
  167.                                     shell.run("delete", ".programs")
  168.                                     sleep(1)
  169.                                     os.reboot()
  170.                                 end
  171.                             elseif x >= 34 and x <= 38 and y == 16 then
  172.                                 choice = true
  173.                                 -- Begin OS
  174.                             end
  175.                         end
  176.                     end
  177.                 else
  178.                     term.setCursorPos(26,14)
  179.                     term.write(" No Updates Found       ")
  180.                     sleep(3)
  181.                 end
  182.             else
  183.                 -- if no response, we assume this
  184.                 term.setCursorPos(26,14)
  185.                 term.write(" Unable to connect     ")
  186.                 term.setCursorPos(26,15)
  187.                 term.write(" to the internet.")
  188.                 sleep(3)
  189.             end
  190.         end
  191.     end
  192.     shell.run(".programs/login")
  193. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement