Advertisement
Mackan90096

SkyOS Installer

Aug 28th, 2014
604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.26 KB | None | 0 0
  1. -- Get width and height
  2. local w, h = term.getSize()
  3. mY = 8
  4. -- Clear screen
  5. term.clear()
  6.  
  7. -- Function for printing in center of screen
  8.  
  9. function cPrint(msg, y)
  10.   term.setCursorPos(math.floor((w-#msg)/2) + (#msg % 2 == 0 and 1 or 0), y or h/2)
  11.   print(msg)
  12. end
  13.  
  14. function cWrite(msg, y)
  15.   term.setCursorPos(math.floor((w-#msg)/2) + (#msg % 2 == 0 and 1 or 0), y or h/2)
  16.   term.write(msg)
  17. end
  18.  
  19. -- Check if computer is advanced
  20.  
  21. if not term.isColor() then
  22.     error("Sorry, we only support advanced computers")
  23. end
  24.  
  25. -- Check if HTTP is enabled
  26.  
  27. if not http.get("http://example.com/", headers) then
  28.     error("HTTP API not enabled. Please enable this to install")
  29. end
  30.  
  31.     term.setBackgroundColor(2048)
  32.     term.setTextColor(1)
  33.     term.clear()
  34.     cPrint("Welcome!", 2)
  35.     cPrint("We see this is the first time you run SkyOS.", 4)
  36.     cPrint("Choose what you would like to do below: ", 6)
  37.     cPrint("[Install]", mY)
  38.     cPrint("Exit", 10)
  39.  
  40.  
  41. function installFile(url, filename)
  42.     local file = fs.open(filename, 'w')
  43.     file.write(http.get(url).readAll())
  44.     file.close()
  45. end
  46.  
  47. function install()
  48.     term.clear()
  49.     cPrint("Installing. Step [1/2]", 2)
  50.     cWrite("What's your name? ", 4)
  51.     local name = read()
  52.     cPrint("Welcome "..name.."!",6)
  53.     cWrite("What would you like your password to be? ", 8)
  54.     local pass = read('*')
  55.     if not fs.exists("users") then
  56.         fs.makeDir("users")
  57.     end
  58.     if not fs.exists("users/"..name) then
  59.         local file = fs.open("users/"..name, "a")
  60.         file.writeLine(pass)
  61.         file.close()
  62.     end
  63.     cWrite("What would you like to name your computer? ", 10)
  64.     local cName = read()
  65.     os.setComputerLabel(cName)
  66.     cPrint("Your computers name is now "..cName.."!", 12)
  67.     sleep(1)
  68.  
  69.     term.clear()
  70.     cPrint("Installing. Step [2/2]", 2)
  71.     cPrint("Downloading files...", 4)
  72.     cPrint("Getting files!", 6)
  73.     installFile("https://raw.githubusercontent.com/Mackan90096/skyos/master/startup", "startup")
  74.     installFile("https://raw.githubusercontent.com/Mackan90096/skyos/master/api/text", "api/text")
  75.     installFile("https://raw.githubusercontent.com/Mackan90096/skyos/master/programs/pasteget", "programs/pasteget")
  76.     installFile("https://raw.githubusercontent.com/Mackan90096/skyos/master/programs/edit", "programs/edit")
  77.     cPrint("Done! Computer will now reboot", 8)
  78.     sleep(1)
  79.     os.reboot()
  80. end
  81.  
  82. while true do
  83.     e, p1, p2, p3 = os.pullEvent()
  84.     if e == "key" then
  85.         if p1 == 208 then
  86.             if mY == 8 then
  87.                 term.setCursorPos(1, mY)
  88.                 term.clearLine()
  89.                 cPrint("Install", mY)
  90.                 mY = 10
  91.                 term.setCursorPos(1, mY)
  92.                 term.clearLine()
  93.                 cPrint("[Exit]", mY)
  94.             elseif mY == 10 then
  95.                 term.setCursorPos(1, mY)
  96.                 term.clearLine()
  97.                 cPrint("Exit", mY)
  98.                 mY = 8
  99.                 term.setCursorPos(1, mY)
  100.                 term.clearLine()
  101.                 cPrint("[Install]", mY)
  102.             end
  103.         elseif p1 == 200 then
  104.             if mY == 10 then
  105.                 term.setCursorPos(1, mY)
  106.                 term.clearLine()
  107.                 cPrint("Exit", mY)
  108.                 mY = 8
  109.                 term.setCursorPos(1, mY)
  110.                 term.clearLine()
  111.                 cPrint("[Install]", mY)
  112.             elseif mY == 8 then
  113.                 term.setCursorPos(1, mY)
  114.                 term.clearLine()
  115.                 cPrint("Install", mY)
  116.                 mY = 10
  117.                 term.setCursorPos(1, mY)
  118.                 term.clearLine()
  119.                 cPrint("[Exit]", mY)
  120.             end
  121.         elseif p1 == 28 then
  122.             if mY == 10 then
  123.                 os.reboot()
  124.             elseif mY == 8 then
  125.                 install()
  126.             end
  127.         end
  128.     end
  129. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement