Advertisement
AquaJD

[AOS] Installer

Jan 29th, 2014
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.76 KB | None | 0 0
  1. --[[ Local Variables and Tables ]]--
  2.  
  3. local tFiles = {
  4.   textutils.urlEncode("HNJqf0AD"), -- main
  5.   textutils.urlEncode("RWjQFdZX"), -- startup
  6.   textutils.urlEncode("j1s4LwJ9"), -- readme
  7.   textutils.urlEncode("3iFFqppT"), -- icon 1
  8.   textutils.urlEncode("vyAZc6tJ"), -- luaide
  9.   textutils.urlEncode("PARriC6j"), -- icon fm
  10.   textutils.urlEncode("uGWi9Vwa"), -- splash
  11.   textutils.urlEncode("jUjT10uK"), -- login layout
  12.   textutils.urlEncode("SaqqWwWW"), -- main bg
  13.   textutils.urlEncode("RkkQTA9j"), -- main bg 2
  14.   textutils.urlEncode("pnzdr8FB"), -- file manager
  15.   textutils.urlEncode("udDhEHeV"), -- npaintpro
  16.   textutils.urlEncode("Ur9tN2Ct"), -- quicktils API
  17.   textutils.urlEncode("LVtcJbNe"), -- settings API
  18.   textutils.urlEncode("pK5YmEkg"), -- controlpanel
  19.   textutils.urlEncode("byczahQr") -- about
  20. }
  21.  
  22. local w,h = term.getSize()
  23. local selectedItem = 1
  24. local inMainMenu = true
  25. local installing = false
  26. local uninstalling = false
  27. local appsMenu = false
  28.  
  29. startFiles = {
  30.   "fs.delete('/AquaOS')",
  31.   "fs.delete('/startup')",
  32.   "print('Successfully removed!')"
  33. }
  34.  
  35. --[[ Utility Functions ]]--
  36.  
  37. function centerPrint(t)
  38.   local x,y = term.getCursorPos()
  39.   x = math.max(math.floor((w / 2) - (#t / 2)), y)
  40.   term.setCursorPos(x+1,y)
  41.   print(t)
  42. end
  43.  
  44. function centerWrite(t)
  45.   local x,y = term.getCursorPos()
  46.   x = math.max(math.floor((w / 2) - (#t / 2)), y)
  47.   term.setCursorPos(x+1,y)
  48.   write(t)
  49. end
  50.  
  51. function drawTitle()
  52.   term.setBackgroundColor(colors.white)
  53.   term.clear()
  54.   term.setCursorPos(1,1)
  55.   term.setBackgroundColor(colors.blue)
  56.   term.clearLine()
  57.   term.setTextColor(colors.white)
  58.   term.setCursorPos(1,1)
  59.   centerPrint("[ AquaOS Updater/Installer ]")
  60.   term.setBackgroundColor(colors.black)
  61.   centerPrint("")
  62.   centerPrint("")
  63. end
  64.  
  65. function drawDownloadTitle()
  66.   drawTitle()
  67.   term.setBackgroundColor(colors.white)
  68.   term.setTextColor(colors.black)
  69.   term.setCursorPos(5,4)
  70.   write("Downloading:  ")
  71. end
  72.  
  73. --[[ Menu Functions ]]--
  74.  
  75. function aosBack()
  76.   appsMenu = false
  77.   installing = false
  78.   uninstalling = false
  79.   downloadApp = false
  80.   removeApp = false
  81.   inMainMenu = true
  82.   selectedItem = 1
  83. end
  84.  
  85. function aosInstall()
  86.   installing = true
  87.   drawTitle()
  88.   term.setBackgroundColor(colors.white)
  89.   term.setTextColor(colors.black)
  90.   centerPrint("Creating directories...")
  91.   fs.makeDir("/AquaOS")
  92.   fs.makeDir("/AquaOS/Resources")
  93.   fs.makeDir("/AquaOS/.Boot")
  94.   fs.makeDir("/AquaOS/Resources/APIs")
  95.   fs.makeDir("/AquaOS/Resources/Apps")
  96.   fs.makeDir("/AquaOS/Resources/.backgrounds")
  97.   fs.makeDir("/AquaOS/Resources/.icons")
  98.   sleep(3)
  99.   while installing do
  100.     -- File 1
  101.     drawDownloadTitle()
  102.     write("/AquaOS/.Boot/Main")
  103.     sFile = http.get("http://pastebin.com/raw.php?i="..tFiles[1])
  104.     local contents = sFile.readAll()
  105.     sFile.close()
  106.     local file = assert(fs.open("/AquaOS/.Boot/Main","w"))
  107.     file.write(contents)
  108.     file.close()
  109.     sleep(1)
  110.     -- File 2
  111.     drawDownloadTitle()
  112.     write("../Apps/FileManager")
  113.     fmFile = http.get("http://pastebin.com/raw.php?i="..tFiles[11])
  114.     local contents = fmFile.readAll()
  115.     fmFile.close()
  116.     local file = assert(fs.open("/AquaOS/Resources/Apps/FileManager","w"))
  117.     file.write(contents)
  118.     file.close()
  119.     sleep(1)
  120.     -- File 3
  121.     drawDownloadTitle()
  122.     write("../Apps/NPaintPro")
  123.     fsFile = http.get("http://pastebin.com/raw.php?i="..tFiles[12])
  124.     local contents = fsFile.readAll()
  125.     fsFile.close()
  126.     local file = assert(fs.open("/AquaOS/Resources/Apps/NPaintPro","w"))
  127.     file.write(contents)
  128.     file.close()
  129.     sleep(1)
  130.     -- File 4
  131.     drawDownloadTitle()
  132.     write("../APIs/QuickTils")
  133.     qtFile = http.get("http://pastebin.com/raw.php?i="..tFiles[13])
  134.     local contents = qtFile.readAll()
  135.     qtFile.close()
  136.     local file = assert(fs.open("/AquaOS/Resources/APIs/QuickTils","w"))
  137.     file.write(contents)
  138.     file.close()
  139.     sleep(1)
  140.     -- File 5
  141.     drawDownloadTitle()
  142.     write("../APIs/Settings")
  143.     flFile = http.get("http://pastebin.com/raw.php?i="..tFiles[14])
  144.     local contents = flFile.readAll()
  145.     flFile.close()
  146.     local file = assert(fs.open("/AquaOS/Resources/APIs/Settings","w"))
  147.     file.write(contents)
  148.     file.close()
  149.     sleep(1)
  150.     -- File 6
  151.     drawDownloadTitle()
  152.     write("../.icons/.icon")
  153.     ico1File = http.get("http://pastebin.com/raw.php?i="..tFiles[4])
  154.     local contents = ico1File.readAll()
  155.     ico1File.close()
  156.     local file = assert(fs.open("/AquaOS/Resources/.icons/.icon","w"))
  157.     file.write(contents)
  158.     file.close()
  159.     sleep(.5)
  160.     -- File 7
  161.     drawDownloadTitle()
  162.     write("../.backgrounds/.mainBG")
  163.     mainBGFile = http.get("http://pastebin.com/raw.php?i="..tFiles[9])
  164.     local contents = mainBGFile.readAll()
  165.     mainBGFile.close()
  166.     local file = assert(fs.open("/AquaOS/Resources/.backgrounds/.mainBG","w"))
  167.     file.write(contents)
  168.     file.close()
  169.     sleep(.5)
  170.     -- File 8
  171.     drawDownloadTitle()
  172.     write("/startup")
  173.     launchFile = http.get("http://pastebin.com/raw.php?i="..tFiles[2])
  174.     local contents = launchFile.readAll()
  175.     launchFile.close()
  176.     if not fs.exists("/startup") then
  177.       local file = assert(fs.open("/startup","w"))
  178.       file.write(contents)
  179.       file.close()
  180.     else
  181.       local file = assert(fs.open("/startup","r"))
  182.       local oldContents = file.readAll()
  183.       file.close()
  184.       local file = assert(fs.open("/oldStartup","w"))
  185.       file.write(oldContents)
  186.       file.close()
  187.       local file = assert(fs.open("/startup","w"))
  188.       file.write(contents)
  189.       file.close()
  190.     end  
  191.     sleep(1)
  192.     -- File 9
  193.     drawDownloadTitle()
  194.     write("../.backgrounds/.splash")
  195.     splashFile = http.get("http://pastebin.com/raw.php?i="..tFiles[7])
  196.     local contents = splashFile.readAll()
  197.     splashFile.close()
  198.     local file = assert(fs.open("/AquaOS/Resources/.backgrounds/.splash","w"))
  199.     file.write(contents)
  200.     file.close()
  201.     sleep(.5)
  202.     -- File 10
  203.     drawDownloadTitle()
  204.     write("../.backgrounds/.loginLayout")
  205.     lSplashFile = http.get("http://pastebin.com/raw.php?i="..tFiles[8])
  206.     local contents = lSplashFile.readAll()
  207.     lSplashFile.close()
  208.     local file = assert(fs.open("/AquaOS/Resources/.backgrounds/.loginLayout","w"))
  209.     file.write(contents)
  210.     file.close()
  211.     sleep(.5)
  212.     -- File 11
  213.     drawDownloadTitle()
  214.     write("../.icons/.iconFM")
  215.     iconFMFile = http.get("http://pastebin.com/raw.php?i="..tFiles[6])
  216.     local contents = iconFMFile.readAll()
  217.     iconFMFile.close()
  218.     local file = assert(fs.open("/AquaOS/Resources/.icons/.iconFM","w"))
  219.     file.write(contents)
  220.     file.close()
  221.     sleep(.5)
  222.     -- File 12
  223.     drawDownloadTitle()
  224.     write("../.backgrounds/.mainBG2")
  225.     mainBG2File = http.get("http://pastebin.com/raw.php?i="..tFiles[10])
  226.     local contents = mainBG2File.readAll()
  227.     mainBG2File.close()
  228.     local file = assert(fs.open("/AquaOS/Resources/.backgrounds/.mainBG2","w"))
  229.     file.write(contents)
  230.     file.close()
  231.     sleep(.5)
  232.     -- File 13
  233.     drawDownloadTitle()
  234.     write("../Apps/LuaIDE")
  235.     luaFile = http.get("http://pastebin.com/raw.php?i="..tFiles[5])
  236.     local contents = luaFile.readAll()
  237.     luaFile.close()
  238.     local file = assert(fs.open("/AquaOS/Resources/Apps/LuaIDE","w"))
  239.     file.write(contents)
  240.     file.close()
  241.     sleep(1)
  242.     -- File 14
  243.     drawDownloadTitle()
  244.     write("/AquaOS/readme.txt")
  245.     readFile = http.get("http://pastebin.com/raw.php?i="..tFiles[3])
  246.     local contents = readFile.readAll()
  247.     readFile.close()
  248.     local file = assert(fs.open("/AquaOS/readme.txt","w"))
  249.     file.write(contents)
  250.     file.close()
  251.     sleep(.5)
  252.     -- File 15
  253.     drawDownloadTitle()
  254.     write("../Resources/.control")
  255.     readFile = http.get("http://pastebin.com/raw.php?i="..tFiles[15])
  256.     local contents = readFile.readAll()
  257.     readFile.close()
  258.     local file = assert(fs.open("/AquaOS/Resources/.control","w"))
  259.     file.write(contents)
  260.     file.close()
  261.     sleep(1)
  262.     -- File 16
  263.     drawDownloadTitle()
  264.     write("../Resources/.about")
  265.     readFile = http.get("http://pastebin.com/raw.php?i="..tFiles[16])
  266.     local contents = readFile.readAll()
  267.     readFile.close()
  268.     local file = assert(fs.open("/AquaOS/Resources/.about","w"))
  269.     file.write(contents)
  270.     file.close()
  271.     sleep(1)
  272.     -- File Finish
  273.     drawTitle()
  274.     term.setBackgroundColor(colors.white)
  275.     term.setTextColor(colors.black)
  276.     write("Complete. Rebooting...")
  277.     sleep(2)
  278.     os.reboot()
  279.   end
  280. end
  281.  
  282. function aosUninstall()
  283.   uninstalling = true
  284.   while uninstalling do
  285.     drawTitle()
  286.     term.setBackgroundColor(colors.white)
  287.     term.setTextColor(colors.black)
  288.     centerWrite("Please choose Apps/APIs to keep! (t/f)")
  289.     centerWrite("")
  290.     centerWrite("QuickTils:   ")
  291.     local fQT = read()
  292.     drawTitle()
  293.     term.setBackgroundColor(colors.white)
  294.     term.setTextColor(colors.black)
  295.     centerWrite("fLib:        ")
  296.     local fFL = read()
  297.     drawTitle()
  298.     term.setBackgroundColor(colors.white)
  299.     term.setTextColor(colors.black)
  300.     centerWrite("LuaIDE:      ")
  301.     local fIDE = read()
  302.     drawTitle()
  303.     term.setBackgroundColor(colors.white)
  304.     term.setTextColor(colors.black)
  305.     centerWrite("NPaintPro:   ")
  306.     local fNPP = read()
  307.     drawTitle()
  308.     term.setBackgroundColor(colors.white)
  309.     term.setTextColor(colors.black)
  310.     centerWrite("FileManager: ")
  311.     local fFB = read()
  312.     drawTitle()
  313.     centerPrint("Removing AquaOS...")
  314.     fs.makeDir("/AOSLeftovers")
  315.     if fQT == "t" then
  316.       fs.move("/AquaOS/Resources/APIs/QuickTils","/AOSLeftovers/QuickTils")
  317.     elseif fQT == "f" then
  318.       return false
  319.     else
  320.       error("Input recognisation failure.")
  321.     end
  322.     if fFL == "t" then
  323.       fs.move("/AquaOS/Resources/APIs/fLib","AOSLeftovers/fLib")
  324.     elseif fFL == "f" then
  325.       return false
  326.     else
  327.       error("Input recognisation failure.")
  328.     end
  329.     if fIDE == "t" then
  330.       fs.move("/AquaOS/Resources/Apps/LuaIDE","AOSLeftovers/LuaIDE")
  331.     elseif fIDE == "f" then
  332.       return false
  333.     else
  334.       error("Input recognisation failure.")
  335.     end
  336.     if fNPP == "t" then
  337.       fs.move("/AquaOS/Resources/Apps/NPaintPro","AOSLeftovers/NPaintPro")
  338.     elseif fNPP == "f" then
  339.       return false
  340.     else
  341.       error("Input recognisation failure.")
  342.     end
  343.     if fFB == "t" then
  344.       fs.move("/AquaOS/Resources/Apps/FileManager","AOSLeftovers/FileManager")
  345.     elseif fFB == "f" then
  346.       return false
  347.     else
  348.       error("Input recognisation failure.")
  349.     end
  350.     local file = fs.open("/startup","w")
  351.     for i=1,#startFiles do
  352.       file.writeLine(startFiles[i])
  353.     end
  354.     sleep(2)
  355.     drawTitle()
  356.     term.setBackgroundColor(colors.white)
  357.     term.setTextColor(colors.black)
  358.     centerPrint("Rebooting..")
  359.     sleep(2)
  360.     uninstalling = false
  361.     os.reboot()
  362.   end
  363. end
  364.  
  365. function aosDownloads()
  366.   appsMenu = true
  367.   selectedItem = 1
  368.   while appsMenu do
  369.     drawTitle()
  370.     term.setBackgroundColor(colors.blue)
  371.     centerPrint("    [ App Menu ]    ")
  372.     centerPrint("                    ")
  373.     printMenu(downloadsMenu)
  374.     term.setBackgroundColor(colors.blue)
  375.     centerPrint("                    ")
  376.     local event, key = os.pullEvent("key")
  377.     oKeyPressed(key,downloadsMenu)
  378.   end
  379. end
  380.  
  381. function aosExit()
  382.   inMainMenu = false
  383.   term.setBackgroundColor(colors.black)
  384.   term.clear()
  385.   term.setCursorPos(1,1)
  386. end
  387.  
  388. function aosDownloadApp()
  389.   downloadApp = true
  390.   while downloadApp do
  391.     drawTitle()
  392.     term.setBackgroundColor(colors.white)
  393.     term.setTextColor(colors.black)
  394.     centerWrite("Pastebin ID:  ")
  395.     local code = read()
  396.     drawTitle()
  397.     term.setBackgroundColor(colors.white)
  398.     term.setTextColor(colors.black)
  399.     centerWrite("App name:  ")
  400.     local appName = read()
  401.     drawTitle()
  402.     term.setBackgroundColor(colors.white)
  403.     term.setTextColor(colors.black)
  404.     centerPrint("Downloading app...")
  405.     if not fs.exists("/AquaOS/Apps/"..appName) then
  406.       local httpCode = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode(code))
  407.       local contents = httpCode.readAll()
  408.       local file = assert(fs.open(filename,"w"))
  409.       file.write(contents)
  410.       file.close()
  411.     else
  412.       error("File already exists!")
  413.     end
  414.     sleep(2)
  415.     centerPrint("Complete! Moved file to /AquaOS/Apps/.")
  416.     aosBack()
  417.   end
  418. end
  419.  
  420. function aosRemoveApp()
  421.   removeApp = true
  422.   while removeApp do
  423.     drawTitle()
  424.     term.setBackgroundColor(colors.white)
  425.     term.setTextColor(colors.black)
  426.     centerWrite("App name:  ")
  427.     local appName = read()
  428.     if fs.exists("/AquaOS/Apps/"..appName) then
  429.       if appName == "LuaIDE" then
  430.         error("You cannot delete this app!")
  431.       elseif appName == "FileManager" then
  432.         error("You cannot delete this app!")
  433.       elseif appName == "NPaintPro" then
  434.         error("You cannot delete this app!")
  435.       else
  436.         drawTitle()
  437.         term.setBackgroundColor(colors.white)
  438.         term.setTextColor(colors.black)
  439.         fs.delete("/AquaOS/Resources/Apps/"..appName)
  440.         centerPrint("Removed!")
  441.         sleep(2)
  442.         aosBack()
  443.       end
  444.     else
  445.       error("File does not exist!")
  446.     end
  447.   end
  448. end
  449.  
  450. --[[ Menus ]]--
  451.  
  452. mainMenu = {
  453.   [1] = { text = "Install  ", handler = aosInstall },
  454.   [2] = { text = "Uninstall", handler = aosUninstall },
  455.   [3] = { text = "Downloads", handler = aosDownloads },
  456.   [4] = { text = "Quit     ", handler = aosExit }
  457. }
  458.  
  459. downloadsMenu = {
  460.   [1] = { text = "Download App", handler = aosDownloadApp },
  461.   [2] = { text = "Remove App  ", handler = aosRemoveApp },
  462.   [3] = { text = "Back        ", handler = aosBack }
  463. }
  464.  
  465.  
  466. --[[ Drawing Methods ]]--
  467.  
  468. function printMenu( menu )
  469.   for i=1,#menu do
  470.     if i == selectedItem then
  471.       term.setBackgroundColor(colors.yellow)
  472.       term.setTextColor(colors.black)
  473.       centerPrint("    "..menu[i].text.."    ")
  474.     else
  475.       term.setBackgroundColor(colors.blue)
  476.       term.setTextColor(colors.white)
  477.       centerPrint("    "..menu[i].text.."    ")
  478.     end
  479.   end
  480. end
  481.  
  482. --[[ Handlers ]]--
  483.  
  484. function oKeyPressed( key,menu )
  485.   if key == keys.enter then
  486.     oItemSelected(menu)
  487.   elseif key == keys.up then
  488.     if selectedItem > 1 then
  489.       selectedItem = selectedItem - 1
  490.     end
  491.   elseif key == keys.down then
  492.     if selectedItem < #menu then
  493.       selectedItem = selectedItem + 1
  494.     end
  495.   end
  496. end
  497.  
  498. function oItemSelected( menu )
  499.   menu[selectedItem].handler()
  500. end
  501.  
  502. function main()
  503.   while inMainMenu do
  504.     drawTitle()
  505.     term.setBackgroundColor(colors.blue)
  506.     centerPrint("  [ Main Menu ]  ")
  507.     centerPrint("                 ")
  508.     printMenu(mainMenu)
  509.     term.setBackgroundColor(colors.blue)
  510.     centerPrint("                 ")
  511.     local event, key = os.pullEvent("key")
  512.     oKeyPressed(key,mainMenu)
  513.   end
  514. end
  515.  
  516. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement