Advertisement
quenti77

Installer qloader & qos

Oct 3rd, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.51 KB | None | 0 0
  1. -----------------------------------
  2. -- Installer for qOs and qLoader --
  3. -----------------------------------
  4.  
  5. -- Only advanced terminal
  6. if not term.isColor() then
  7.     os.reboot()
  8. end
  9.  
  10. -- Local variable --
  11. local files = {}
  12.  
  13. local running = true
  14. local qloader = true
  15. local name = "admin"
  16. local pass = "admin"
  17. local textSelect = "none"
  18. local percent = 0
  19. local status = ""
  20. local sX, sY = term.getSize()
  21.  
  22. -- Local function --
  23. local function clearTerm()
  24.     term.setTextColor(colors.white)
  25.     term.setBackgroundColor(colors.black)
  26.  
  27.     term.clear()
  28.     term.setCursorPos(1, 1)
  29. end
  30.  
  31. local function drawCheck(bx, by, colorCase, colorCheck, colorBack, colorText, name)
  32.     term.setBackgroundColor(colorCase)
  33.     term.setTextColor(colorCheck)
  34.     term.setCursorPos(bx, by)
  35.     term.write("   ")
  36.     term.setCursorPos(bx, by + 1)
  37.     term.write("   ")
  38.     term.setCursorPos(bx, by + 2)
  39.     term.write("   ")
  40.  
  41.     term.setBackgroundColor(colorBack)
  42.     term.setTextColor(colorText)
  43.     term.setCursorPos(bx + 4, by + 1)
  44.     term.write(name)
  45. end
  46.  
  47. local function drawNextButton(name)
  48.  
  49.     term.setBackgroundColor(colors.blue)
  50.     term.setTextColor(colors.white)
  51.  
  52.     x = 3
  53.     y = sY - 4
  54.  
  55.     for i = y, y + 2 do
  56.         for j = x, sX - 3 do
  57.             term.setCursorPos(j, i)
  58.             term.write(" ")
  59.         end
  60.     end
  61.  
  62.     taille = string.len(name)
  63.     term.setCursorPos(sX / 2 - taille / 2, y + 1)
  64.     term.write(name)
  65.  
  66. end
  67.  
  68. local function isClicked(x, y, xMin, xMax, yMin, yMax)
  69.     return ( ( x >= xMin and x <= xMax ) and ( y >= yMin and y <= yMax) )
  70. end
  71.  
  72. local function getFile(path)
  73.     local sFile = "http://quenti77.fr/scripts/qos/"..path..".lua"
  74.     local httpFile = http.get(sFile)
  75.  
  76.     local tempFile = fs.open("/"..path, "w")
  77.     tempFile.write(httpFile.readAll())
  78.     tempFile.close()
  79.  
  80.     httpFile.close()
  81.     return fs.getSize("/"..path)
  82. end
  83.  
  84. local function getFiles()
  85.  
  86.     for i = 1, #files do
  87.         getFile(files[i])
  88.         percent = math.floor(i / #files * 100)
  89.         percentShow = math.floor(i / #files * (sX - 6))
  90.         percentString = "Downloading : "..string.format("% 3s", percent).." %"
  91.  
  92.         clearTerm()
  93.  
  94.         term.setCursorPos(3, 3)
  95.         term.write("Installation of qos")
  96.  
  97.         term.setCursorPos(sX / 2 - string.len(percentString) / 2 + 1, 7)
  98.         term.write(percentString)
  99.         for j = 8, 9 do
  100.             for i = 3, sX - 3 do
  101.                 term.setCursorPos(i, j)
  102.  
  103.                 if (i - 3) <= percentShow then
  104.                     term.setBackgroundColor(colors.green)
  105.                 else
  106.                     term.setBackgroundColor(colors.orange)
  107.                 end
  108.  
  109.                 term.write(" ")
  110.             end
  111.         end
  112.     end
  113.  
  114.     for i = 0, 5 do
  115.         percent = 5 - i
  116.         percentShow = math.floor( i / 5 * (sX - 6))
  117.         percentString = "Restarting : "..percent.." s "
  118.  
  119.         clearTerm()
  120.  
  121.         term.setCursorPos(sX / 2 - string.len(percentString) / 2 + 1, 7)
  122.         term.write(percentString)
  123.         for j = 8, 9 do
  124.             for i = 3, sX - 3 do
  125.                 term.setCursorPos(i, j)
  126.  
  127.                 if (i - 3) <= percentShow then
  128.                     term.setBackgroundColor(colors.green)
  129.                 else
  130.                     term.setBackgroundColor(colors.orange)
  131.                 end
  132.  
  133.                 term.write(" ")
  134.             end
  135.         end
  136.  
  137.         sleep(1)
  138.     end
  139. end
  140.  
  141. -- Propose qLoader
  142. while running do
  143.     clearTerm()
  144.  
  145.     term.setCursorPos(3, 3)
  146.     term.write("Components to install: (LCTRL for quit)")
  147.  
  148.     drawCheck(3, 5, colors.lightGray, colors.white, colors.black, colors.lightGray, "installing qOS")
  149.  
  150.     if qloader then
  151.         drawCheck(3, 9, colors.green, colors.white, colors.black, colors.green, "installing qLoader")
  152.     else
  153.         drawCheck(3, 9, colors.red, colors.white, colors.black, colors.red, "installing qLoader")
  154.     end
  155.  
  156.     drawNextButton("Next ==>")
  157.  
  158.     local ev, a, b, c, d, e = os.pullEvent()
  159.  
  160.     if ev == "mouse_click" or ev == "monitor_touch" then
  161.         if isClicked(b, c, 3, 25, 9, 11) then
  162.             qloader = not qloader
  163.         elseif isClicked(b, c, 3, sX - 3,sY - 4, sY - 1) then
  164.             running = false
  165.         end
  166.     end
  167.  
  168.     if ev == "key" then
  169.         if a == 29 then
  170.             os.reboot()
  171.         elseif a == 28 then
  172.             running = false
  173.         elseif a == 57 then
  174.             qloader = not qloader
  175.         end
  176.     end
  177. end
  178.  
  179. -- Permet de changer le nom et le mot de passe
  180. running = true
  181. while running do
  182.     clearTerm()
  183.  
  184.     term.setCursorPos(3, 3)
  185.     term.write("User account: (LCTRL for quit)")
  186.  
  187.     term.setCursorPos(3, 6)
  188.     term.write("User name : ")
  189.  
  190.     term.setCursorPos(3, 10)
  191.     term.write("User password : ")
  192.  
  193.     term.setTextColor(colors.black)
  194.     term.setBackgroundColor(colors.white)
  195.     for i = 3, sX - 3 do
  196.         term.setCursorPos(i, 7)
  197.        
  198.         if (i - 2 <= string.len(name)) then
  199.             term.write(string.sub(name, i - 2, i - 2))
  200.         elseif (i - 2 == (string.len(name) + 1) ) then
  201.             if textSelect == "name" then
  202.                 term.write("_")
  203.             else
  204.                 term.write(" ")
  205.             end
  206.         else
  207.             term.write(" ")
  208.         end
  209.     end
  210.  
  211.     for i = 3, sX - 3 do
  212.         term.setCursorPos(i, 11)
  213.  
  214.         if (i - 2 <= string.len(pass)) then
  215.             term.write("*")
  216.         elseif (i - 2 == (string.len(pass) + 1) ) then
  217.             if textSelect == "pass" then
  218.                 term.write("_")
  219.             else
  220.                 term.write(" ")
  221.             end
  222.         else
  223.             term.write(" ")
  224.         end
  225.     end
  226.  
  227.     drawNextButton("Install ==>")
  228.  
  229.     local ev, a, b, c, d, e = os.pullEvent()
  230.  
  231.     if ev == "mouse_click" or ev == "monitor_touch" then
  232.         if isClicked(b, c, 3, sX - 3, 7, 7) then
  233.             textSelect = "name"
  234.         elseif isClicked(b, c, 3, sX - 3, 11, 11) then
  235.             textSelect = "pass"
  236.         elseif isClicked(b, c, 3, sX - 3,sY - 4, sY - 1) then
  237.             running = false
  238.         else
  239.             textSelect = "none"
  240.         end
  241.     end
  242.  
  243.     if ev == "key" then
  244.         if a == 29 then
  245.             os.reboot()
  246.         elseif a == 28 then
  247.             running = false
  248.         elseif a == 15 then
  249.             if textSelect == "none" then
  250.                 textSelect = "name"
  251.             elseif textSelect == "name" then
  252.                 textSelect = "pass"
  253.             elseif textSelect == "pass" then
  254.                 textSelect = "none"
  255.             end
  256.         elseif a == 14 then
  257.             if textSelect == "name" then
  258.                 name = string.sub(name, 1, string.len(name) - 1)
  259.             elseif textSelect == "pass" then
  260.                 pass = string.sub(pass, 1, string.len(pass) - 1)
  261.             end
  262.         end
  263.     end
  264.  
  265.     if ev == "char" then
  266.         if textSelect == "name" then
  267.             name = name..a
  268.         elseif textSelect == "pass" then
  269.             pass = pass..a
  270.         end
  271.     end
  272. end
  273.  
  274. -- Qloader files
  275. if qloader then
  276.     table.insert(files, "qloader/startup")
  277.     table.insert(files, "qloader/option")
  278.     table.insert(files, "qloader/password")
  279.     table.insert(files, "qloader/ctrl")
  280.  
  281.     if fs.exists("qloader") then
  282.         fs.delete("qloader")
  283.     end
  284. end
  285.  
  286. -- Qos files
  287. table.insert(files, "qOS/startup")
  288.  
  289. -- Startup file for the computer
  290. table.insert(files, "startup")
  291.  
  292. if fs.exists("qos") then
  293.     fs.delete("qos")
  294. end
  295.  
  296. -- Une fois les choix finis on lance l'installation
  297. getFiles()
  298.  
  299. local config = fs.open("qOS/user.cfg", "w")
  300.  
  301. config.writeLine("name="..name)
  302. config.writeLine("pass="..pass)
  303. config.close()
  304.  
  305. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement