Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------
- -- zOS Installer --
- -- Create the system directories --
- --Copy the system programs & apis --
- -- btw:it formats your computer --
- --remember to use update after install--
- --to keep your system updated --
- ----------------------------------------
- local finished = false
- while not finished do
- function Done()
- if term.isColor() then
- term.setTextColor(colors.lime)
- end
- print("Done")
- if term.isColor() then
- term.setTextColor(colors.blue)
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- if term.isColor() then
- term.setTextColor(colors.yellow)
- end
- print("zOS Version 0.3 Installer Part 1")
- print("")
- print("2 branches are available!")
- print("1 : Master (or stable)")
- print("2 : Testing (or unstable)")
- local answered = false
- local _branch = "none"
- while not answered do
- write("Choose the branch (1/2) >")
- answer = read()
- if answer=="2" then
- print("Branch have been set to testing")
- _branch = "testing"
- answered = true
- elseif answer=="1" then
- print("Branch have been set to master")
- _branch = "master"
- answered = true
- else
- print("[Error] Invalid number!")
- end
- end
- print("")
- print("[Warning] zOS is about to delete everything.")
- write("Do you want to continue the installation? (y/n) >")
- local answer = read()
- if answer=="y" then
- if term.isColor() then
- term.setTextColor(colors.blue)
- end
- --Part 1 : format the hard drive
- write("[Info] Deleting all files...")
- local fileList = fs.list("")
- local number = table.getn(fileList, "rom")
- table.remove(fileList, number)
- number = table.getn(fileList, "disk")
- table.remove(fileList, number)
- for i=1, #fileList do
- fs.delete(fileList[i])
- end
- Done()
- --Part 2 : Download the system
- --setting the system branch
- fs.makeDir("/etc")
- fs.makeDir("/etc/zpm")
- local repo = fs.open("/etc/zpm/sysbranch", "w")
- repo.write(_branch)
- repo.close()
- print("[Info] Beginning installation.")
- --Creating the system directories
- write("[Info] Creating directories...")
- fs.makeDir("/api")
- fs.makeDir("/bin")
- fs.makeDir("/etc")
- fs.makeDir("/etc/usrlist")
- fs.makeDir("/etc/usrdata")
- fs.makeDir("/home")
- fs.makeDir("/root")
- fs.makeDir("/tmp")
- fs.makeDir("/usr")
- fs.makeDir("/usr/api")
- fs.makeDir("/usr/bin")
- Done()
- --Copying the basic CC programs and delete those which have been changed
- if not fs.exists("/bin/ccUnchanged") then
- fs.copy("/rom/programs", "/bin/ccUnchanged")
- fs.delete("/bin/ccUnchanged/cd")
- fs.delete("/bin/ccUnchanged/copy")
- fs.delete("/bin/ccUnchanged/delete")
- fs.delete("/bin/ccUnchanged/edit")
- fs.delete("/bin/ccUnchanged/exit")
- fs.delete("/bin/ccUnchanged/lua")
- fs.delete("/bin/ccUnchanged/mkdir")
- fs.delete("/bin/ccUnchanged/move")
- fs.delete("/bin/ccUnchanged/rename")
- fs.delete("/bin/ccUnchanged/shell")
- fs.delete("/bin/ccUnchanged/reboot")
- fs.delete("/bin/ccUnchanged/shutdown")
- end
- --Getting the system API ( this will be changed when zpm will be avaiable)
- local f = fs.open("/etc/zpm/sysbranch", "r")
- branch = f.readLine()
- if branch=="testing" then
- data1 = http.get("https://raw.githubusercontent.com/Zac13422/zOS/testing/api/text")
- data2 = http.get("https://raw.githubusercontent.com/Zac13422/zOS/testing/bin/zpm")
- else
- data1 = http.get("https://raw.githubusercontent.com/Zac13422/zOS/master/api/text")
- data2 = http.get("https://raw.githubusercontent.com/Zac13422/zOS/master/bin/zpm")
- end
- data1 = data1.readAll()
- data2 = data2.readAll()
- local file1 = fs.open("/api/text", "w")
- local file2 = fs.open("/bin/zpm", "w")
- file1.write(data1)
- file2.write(data2)
- file1.close()
- file2.close()
- --First system update:this download all the system programs and APIs
- os.loadAPI("/api/text")
- shell.run("/bin/zpm fetch")
- shell.run("/bin/zpm install zos-"..branch)
- --Creating the files used for accounts management
- file = fs.open("etc/usrdata/userlist", "w")
- file.close()
- file = fs.open("etc/usrdata/usernumber", "w")
- file.write("0")
- file.close()
- --Part 3 : setup the accounts
- os.loadAPI("/api/user")
- os.loadAPI("/api/system")
- system.loadAllSysAPI()
- term.clear()
- text.out("zOS Version 0.3 Installer Part 2", colors.green, colors.blue, 9, 1)
- term.setCursorPos(1,3)
- --Setting a computer label
- write("Enter your computer name:")
- compName = read()
- os.setComputerLabel(compName)
- --Creating root password
- user.passwd("root")
- local validUserName = false
- --Adding the first user
- while not validUserName do
- write("Enter your username:")
- userName = read()
- if userName=="" then
- print("Invalid username")
- else
- validUserName = true
- end
- end
- user.add(userName)
- --Creating a password for the new user
- user.passwd(userName)
- print("Installation finished. Rebooting...")
- os.sleep(1)
- finished = true
- os.reboot()
- elseif answer=="n" then
- print("Installation cancelled.")
- finished = true
- else
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment