Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Puppy OS 1.0 (Simplified Version)
- local systemName = "Puppy OS"
- local username = nil
- local password = nil
- local configPath = "/PuppyOS/config.txt"
- local recoveryPath = "/PuppyOS/recovery/"
- local pastebinURL = "https://pastebin.com/jMuSk5UJ" -- URL for new "startup" file
- -- Ensure config folder exists
- if not fs.exists("/PuppyOS") then fs.makeDir("/PuppyOS") end
- if not fs.exists(recoveryPath) then fs.makeDir(recoveryPath) end
- -- Load Config
- local function loadConfig()
- if fs.exists(configPath) then
- local file = fs.open(configPath, "r")
- local data = textutils.unserialize(file.readAll())
- file.close()
- if data then
- systemName = data.systemName or systemName
- username = data.username or username
- password = data.password or password
- end
- end
- end
- -- Save Config
- local function saveConfig()
- local data = {
- systemName = systemName,
- username = username,
- password = password
- }
- local file = fs.open(configPath, "w")
- file.write(textutils.serialize(data))
- file.close()
- end
- -- Boot Menu: Allows user to choose between regular boot or recovery mode
- local function bootMenu()
- term.clear()
- term.setCursorPos(1, 1)
- print("Welcome to ".. systemName)
- print("[1] Boot into OS")
- print("[2] Enter Recovery Mode")
- write("Select an option: ")
- local choice = read()
- if choice == "1" then
- boot()
- elseif choice == "2" then
- recoveryMenu()
- else
- print("Invalid option. Restarting boot menu...")
- sleep(2)
- bootMenu()
- end
- end
- -- Booting into the system
- local function boot()
- term.clear()
- term.setCursorPos(1, 1)
- print("Booting ".. systemName .." ...")
- sleep(1)
- loadConfig()
- if not username or not password then
- systemSetup()
- end
- if loginScreen() then
- desktop()
- end
- end
- -- Recovery: Download system from Pastebin
- local function downloadSystem()
- print("Downloading the system...")
- local success, error = pcall(function()
- local response = http.get(pastebinURL)
- if not response then
- error("Download failed")
- end
- local file = fs.open(recoveryPath.."/startup.lua", "w")
- file.write(response.readAll())
- file.close()
- print("Download successful! Reinstalling system...")
- sleep(1)
- end)
- if not success then
- print("Error: " .. error)
- sleep(2)
- end
- end
- -- Factory Reset
- local function factoryReset()
- print("Performing factory reset...")
- fs.delete(configPath) -- Remove user configurations
- fs.delete("/PuppyOS") -- Remove all data in /PuppyOS
- print("System reset. Restarting...")
- sleep(2)
- os.reboot()
- end
- -- Recovery Menu
- local function recoveryMenu()
- term.clear()
- term.setCursorPos(1, 1)
- print("Recovery Menu")
- print("[1] Factory Reset")
- print("[2] Reinstall System")
- print("[3] Return to Boot Menu")
- write("Select an option: ")
- local choice = read()
- if choice == "1" then
- factoryReset()
- elseif choice == "2" then
- downloadSystem()
- print("Reinstall completed! Rebooting...")
- sleep(2)
- os.reboot()
- elseif choice == "3" then
- bootMenu() -- Go back to the Boot Menu
- else
- print("Invalid option. Returning to Boot Menu...")
- sleep(2)
- bootMenu() -- Go back to the Boot Menu
- end
- end
- -- System Setup (simple setup process)
- local function systemSetup()
- term.clear()
- term.setCursorPos(1, 1)
- print("Initial System Setup")
- write("Enter System Name: ")
- local newName = read()
- systemName = newName ~= "" and newName or systemName
- while not username do
- write("Set new username: ")
- local newUser = read()
- if newUser ~= "" then username = newUser end
- end
- while not password do
- write("Set new password: ")
- local newPass = read("*")
- if newPass ~= "" then password = newPass end
- end
- saveConfig()
- print("Setup Complete! Rebooting...")
- sleep(2)
- os.reboot()
- end
- -- Login Screen
- local function loginScreen()
- while true do
- term.clear()
- term.setCursorPos(1, 1)
- print("Welcome to ".. systemName .."!")
- write("Username: ")
- local inputUser = read()
- write("Password: ")
- local inputPass = read("*")
- if inputUser == username and inputPass == password then
- print("Login successful!")
- sleep(1)
- return true
- else
- print("Invalid credentials. Try again.")
- sleep(1)
- end
- end
- end
- -- Draw Desktop
- local function drawDesktop()
- term.setBackgroundColor(colors.cyan)
- term.clear()
- term.setCursorPos(1, 1)
- print("Welcome to ".. systemName)
- print("[1] File Explorer")
- print("[2] Settings")
- print("[3] Terminal")
- print("[4] Power Menu")
- end
- -- Desktop: Main interface
- local function desktop()
- while true do
- drawDesktop()
- local event, key = os.pullEvent("key")
- if key == keys.one then fileExplorer()
- elseif key == keys.two then settingsMenu()
- elseif key == keys.three then terminal()
- elseif key == keys.four then powerMenu()
- end
- end
- end
- -- Simple File Explorer
- local function fileExplorer()
- term.clear()
- term.setCursorPos(1, 1)
- print("File Explorer")
- print("------------")
- local files = fs.list("/")
- for i, file in ipairs(files) do
- print(i .. ". " .. file)
- end
- print("Press any key to return...")
- os.pullEvent("key")
- end
- -- Settings Menu
- local function settingsMenu()
- term.clear()
- term.setCursorPos(1, 1)
- print("System Settings")
- print("--------------")
- print("[1] Change System Name")
- print("[2] Change Username")
- print("[3] Change Password")
- print("[4] Back to Desktop")
- write("Select an option: ")
- local choice = read()
- if choice == "1" then
- write("New System Name: ")
- systemName = read()
- print("System name updated!")
- elseif choice == "2" then
- write("New Username: ")
- username = read()
- print("Username updated!")
- elseif choice == "3" then
- write("New Password: ")
- password = read("*")
- print("Password updated!")
- end
- saveConfig()
- sleep(1)
- end
- -- Terminal
- local function terminal()
- while true do
- term.clear()
- term.setCursorPos(1, 1)
- print("Puppy OS Terminal")
- print("Type 'exit' to leave terminal.")
- write("> ")
- local command = read()
- if command == "exit" then
- return
- else
- shell.run(command)
- end
- end
- end
- -- Power Menu
- local function powerMenu()
- term.clear()
- term.setCursorPos(1, 1)
- print("Power Menu")
- print("[1] Restart")
- print("[2] Shutdown")
- print("[3] Back to Desktop")
- write("Select an option: ")
- local choice = read()
- if choice == "1" then
- print("Restarting...")
- sleep(2)
- os.reboot()
- elseif choice == "2" then
- print("Shutting down...")
- sleep(2)
- os.shutdown()
- end
- end
- -- Start Puppy OS
- bootMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement