zac13422

OsInstaller

Jul 15th, 2016
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.19 KB | None | 0 0
  1. ----------------------------------------
  2. --        zOS Installer               --
  3. -- Create the system directories      --
  4. --Copy the system programs & apis     --
  5. -- btw:it formats your computer       --
  6. --remember to use update after install--
  7. --to keep your system updated         --
  8. ----------------------------------------
  9.  
  10. local finished = false
  11.  
  12. while not finished do
  13.  
  14.     function Done()
  15.         if term.isColor() then
  16.             term.setTextColor(colors.lime)
  17.         end
  18.         print("Done")
  19.         if term.isColor() then
  20.             term.setTextColor(colors.blue)
  21.         end
  22.     end
  23.  
  24.     term.clear()
  25.     term.setCursorPos(1,1)
  26.     if term.isColor() then
  27.         term.setTextColor(colors.yellow)
  28.     end
  29.  
  30.     print("zOS Version 0.3 Installer  Part 1")
  31.     print("")
  32.     print("2 branches are available!")
  33.     print("1 : Master (or stable)")
  34.     print("2 : Testing (or unstable)")
  35.         local answered = false
  36.         local _branch = "none"
  37.         while not answered do
  38.             write("Choose the branch (1/2) >")
  39.             answer = read()
  40.        
  41.             if answer=="2" then
  42.                 print("Branch have been set to testing")
  43.                 _branch = "testing"
  44.                 answered = true
  45.             elseif answer=="1" then
  46.                 print("Branch have been set to master")
  47.                 _branch = "master"
  48.                 answered = true
  49.             else
  50.                 print("[Error] Invalid number!")
  51.             end
  52.         end
  53.    
  54.     print("")  
  55.     print("[Warning] zOS is about to delete everything.")
  56.     write("Do you want to continue the installation? (y/n) >")
  57.     local answer = read()
  58.    
  59.     if answer=="y" then
  60.            
  61.         if term.isColor() then
  62.             term.setTextColor(colors.blue)
  63.         end
  64. --Part 1 : format the hard drive
  65.        
  66.         write("[Info] Deleting all files...")
  67.         local fileList = fs.list("")
  68.         local number = table.getn(fileList, "rom")
  69.         table.remove(fileList, number)
  70.         number = table.getn(fileList, "disk")
  71.         table.remove(fileList, number)
  72.         for i=1, #fileList do
  73.             fs.delete(fileList[i])
  74.         end
  75.         Done() 
  76.        
  77. --Part 2 : Download the system
  78.        
  79.    
  80. --setting the system branch
  81.         fs.makeDir("/etc")
  82.         fs.makeDir("/etc/zpm")
  83.         local repo = fs.open("/etc/zpm/sysbranch", "w")
  84.         repo.write(_branch)
  85.         repo.close()
  86.        
  87.         print("[Info] Beginning installation.")
  88.        
  89.    
  90. --Creating the system directories
  91.         write("[Info] Creating directories...")
  92.         fs.makeDir("/api")
  93.         fs.makeDir("/bin")
  94.         fs.makeDir("/etc")
  95.         fs.makeDir("/etc/usrlist")
  96.         fs.makeDir("/etc/usrdata")
  97.         fs.makeDir("/home")
  98.         fs.makeDir("/root")
  99.         fs.makeDir("/tmp")
  100.         fs.makeDir("/usr")
  101.         fs.makeDir("/usr/api")
  102.         fs.makeDir("/usr/bin")
  103.         Done()
  104.        
  105. --Copying the basic CC programs and delete those which have been changed
  106.             if not fs.exists("/bin/ccUnchanged") then
  107.             fs.copy("/rom/programs", "/bin/ccUnchanged")
  108.             fs.delete("/bin/ccUnchanged/cd")
  109.             fs.delete("/bin/ccUnchanged/copy")
  110.             fs.delete("/bin/ccUnchanged/delete")
  111.             fs.delete("/bin/ccUnchanged/edit")
  112.             fs.delete("/bin/ccUnchanged/exit")
  113.             fs.delete("/bin/ccUnchanged/lua")
  114.             fs.delete("/bin/ccUnchanged/mkdir")
  115.             fs.delete("/bin/ccUnchanged/move")
  116.             fs.delete("/bin/ccUnchanged/rename")
  117.             fs.delete("/bin/ccUnchanged/shell")
  118.             fs.delete("/bin/ccUnchanged/reboot")
  119.             fs.delete("/bin/ccUnchanged/shutdown")
  120.             end
  121.    
  122. --Getting the system API ( this will be changed when zpm will be avaiable)
  123.         local f = fs.open("/etc/zpm/sysbranch", "r")
  124.             branch = f.readLine()
  125.         if branch=="testing" then
  126.             data1 = http.get("https://raw.githubusercontent.com/Zac13422/zOS/testing/api/text")
  127.             data2 = http.get("https://raw.githubusercontent.com/Zac13422/zOS/testing/bin/zpm")
  128.             else
  129.                     data1 = http.get("https://raw.githubusercontent.com/Zac13422/zOS/master/api/text")
  130.             data2 = http.get("https://raw.githubusercontent.com/Zac13422/zOS/master/bin/zpm")
  131.             end    
  132.        
  133.         data1 = data1.readAll()
  134.         data2 = data2.readAll()
  135.             local file1 = fs.open("/api/text", "w")
  136.         local file2 = fs.open("/bin/zpm", "w")
  137.             file1.write(data1)
  138.         file2.write(data2)
  139.             file1.close()
  140.         file2.close()
  141.  
  142. --First system update:this download all the system programs and APIs
  143.         os.loadAPI("/api/text")
  144.         shell.run("/bin/zpm fetch")
  145.         shell.run("/bin/zpm install zos-"..branch)
  146. --Creating the files used for accounts management      
  147.         file = fs.open("etc/usrdata/userlist", "w")
  148.         file.close()
  149.         file = fs.open("etc/usrdata/usernumber", "w")
  150.         file.write("0")
  151.         file.close()
  152.  
  153.  
  154.  
  155. --Part 3 : setup the accounts
  156.         os.loadAPI("/api/user")
  157.         os.loadAPI("/api/system")
  158.         system.loadAllSysAPI()
  159.  
  160.         term.clear()
  161.         text.out("zOS Version 0.3 Installer  Part 2", colors.green, colors.blue, 9, 1)
  162.         term.setCursorPos(1,3)
  163.        
  164. --Setting a computer label
  165.         write("Enter your computer name:")
  166.         compName = read()
  167.         os.setComputerLabel(compName)
  168.        
  169. --Creating root password
  170.         user.passwd("root")
  171.        
  172.         local validUserName = false
  173.        
  174. --Adding the first user
  175.         while not validUserName do
  176.             write("Enter your username:")
  177.             userName = read()
  178.             if userName=="" then
  179.                 print("Invalid username")
  180.             else
  181.                 validUserName = true
  182.             end
  183.         end
  184.         user.add(userName)
  185.  
  186. --Creating a password for the new user
  187.         user.passwd(userName)
  188.        
  189.         print("Installation finished. Rebooting...")
  190.         os.sleep(1)
  191.         finished = true
  192.         os.reboot()
  193.        
  194.     elseif answer=="n" then
  195.         print("Installation cancelled.")
  196.         finished = true
  197.     else
  198.        
  199.     end
  200.  
  201. end
Advertisement
Add Comment
Please, Sign In to add comment