Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --program code starts here
- local turtleSettingsCode = [[
- -- Turtle Settings Manager
- local args = {...}
- local function listSettings()
- local settingsFile = fs.open("os/turtle", "r")
- local canMove = settingsFile.readLine()
- local canDig = settingsFile.readLine()
- local canPlace = settingsFile.readLine()
- local canSuck = settingsFile.readLine()
- settingsFile.close()
- return canMove, canDig, canPlace, canSuck
- end
- local function changeSettings(canMove, canDig, canPlace, canSuck)
- local settingsFile = fs.open("os/turtle", "w")
- settingsFile.writeLine(canMove)
- settingsFile.writeLine(canDig)
- settingsFile.writeLine(canPlace)
- settingsFile.writeLine(canSuck)
- settingsFile.close()
- end
- if museOS.getCurrentUser() == "root" then
- if args[1] ~= "get" then
- if #args == 5 then
- changeSettings(args[2], args[3], args[4], args[5])
- else
- print("USAGE: turtleSettings [get/set] [canMove] [canDig] [canPlace] [canSuck]")
- end
- else
- local canMove,canDig,canPlace,canSuck = listSettings()
- print("Can Move: "..canMove)
- print("Can Dig: "..canDig)
- print("Can Place: "..canPlace)
- print("Can Suck: "..canSuck)
- end
- else
- print("You need to be root to do this!")
- end
- ]]
- local updaterCode = [[
- function update()
- fs.delete("MuSeOS")
- fs.delete("bin/man")
- shell.run("pastebin", "get", "fquZgJ5p", "MuSeOS")
- shell.run("pastebin", "get", "G33dymxf", "programInstaller")
- shell.run("pastebin", "get", "wfeGgwQH", "bin/man")
- shell.run("programInstaller")
- fs.delete("programInstaller")
- os.reboot()
- end
- if http then
- if museOS.getCurrentUser() == "root" then
- fs.makeDir("temp")
- shell.run("pastebin", "get", "j8qj82d1", "temp/version")
- if not fs.exists("os/version") then
- print("os/version does not exist, updating...")
- fs.move("temp/version", "os/version")
- update()
- else
- local versionFile = fs.open("os/version", "r")
- local newVersionFile = fs.open("temp/version", "r")
- local newVersion = newVersionFile.readAll()
- local version = versionFile.readAll()
- newVersionFile.close()
- versionFile.close()
- if newVersion > version then
- print("New version found: "..newVersion)
- fs.delete("os/version")
- fs.move("temp/version", "os/version")
- update()
- else
- print("You are running the latest version!")
- end
- fs.delete("temp")
- end
- else
- print("You need to be root to do this!")
- end
- else
- print("HTTP API disabled, not checking for updates...")
- end
- ]]
- local diskInfoCode = [[
- args = {...}
- local function displayLoop()
- term.clear()
- term.setCursorPos(1,1)
- local side = args[1]
- print("Press any key to exit.")
- if not disk.isPresent(side) then
- print("No disk inserted.")
- return
- else
- print("Disk mounted.")
- if disk.hasData(side) then
- print("Floppy disk inserted.")
- print("Mount path: "..disk.getMountPath(side))
- if disk.getLabel(side) == nil then
- print("Label not set.")
- else
- print("Label: "..disk.getLabel(side))
- end
- print("ID: "..tostring(disk.getDiskID(side)))
- elseif disk.hasAudio(side) then
- print("Audio disk inserted.")
- print("Title: "..disk.getAudioTitle(side))
- print("Press ENTER to stop or start audio.")
- end
- print("Press SPACE to eject disk.")
- end
- end
- local audioStarted = false
- while true do
- displayLoop()
- event, key = os.pullEvent()
- if event == "key" then
- if key == 57 then
- disk.eject(args[1])
- elseif key == 28 then
- audioStarted = not audioStarted
- if audioStarted then
- disk.playAudio(args[1])
- else
- disk.stopAudio(args[1])
- end
- elseif key ~= 1 then
- break
- end
- end
- end
- ]]
- local logViewerCode = [[
- args = {...}
- local maxX, maxY = term.getSize()
- local function writeAvailable(lines, offsetY)
- term.clear()
- term.setCursorPos(1,1)
- for i=1, maxY do
- print(lines[i+offsetY])
- end
- end
- local function viewLog()
- if museOS.getCurrentUser() == "root" then
- if not fs.exists("os/logs/"..args[1]) then
- print("That log doesn't exist!")
- return
- end
- local lines = {}
- local logHandle = fs.open("os/logs/"..args[1], "r")
- print("Press any key other than the up/down arrows to exit.")
- os.sleep(0.5)
- while true do
- local line = logHandle.readLine()
- if line == nil then
- break
- else
- table.insert(lines, line)
- end
- end
- logHandle.close()
- writeAvailable(lines, 1)
- local offset = 1
- while true do
- event, key = os.pullEvent("key")
- if key == 200 then
- offset = offset-1
- if offset < 1 then
- offset = 1
- end
- elseif key == 208 then
- offset = offset+1
- if offset > #lines then
- offset = #lines
- end
- else
- term.clear()
- term.setCursorPos(1,1)
- return
- end
- writeAvailable(lines, offset)
- end
- else
- print("You need to be running as root to do this!")
- return
- end
- end
- if #args == 1 then
- term.clear()
- term.setCursorPos(1,1)
- viewLog()
- else
- print("USAGE:log [log name]")
- end
- ]]
- local sudoCode = [[
- args = {...}
- local function doSudo()
- if museOS.getCurrentUser() == "root" then
- print("You are already root!")
- return
- end
- local programArgs = {}
- local password = args[1]
- local program = args[2]
- for i,v in ipairs(args) do
- if i ~= 1 and i ~= 2 then
- table.insert(programArgs, v)
- end
- end
- museOS.sudo(password, args[2], unpack(programArgs))
- end
- if #args >= 2 then
- doSudo()
- else
- print("USAGE: sudo [password] [program] [args]")
- end
- ]]
- local addUserCode = [[
- args = {...}
- function addUser()
- if museOS.getCurrentUser() == "root" then
- if fs.exists("os/users/"..args[1]) then
- print("ERROR: User already exists!")
- return
- end
- io.write("Do you want to add a user called "..args[1].." with a password of "..args[2].."? (Y/N)>")
- local yn = io.read()
- yn = string.upper(yn)
- if yn == "Y" then
- local userFile = fs.open("os/users/"..args[1], "w")
- userFile.writeLine(args[2])
- userFile.close()
- fs.makeDir(args[1])
- fs.makeDir("os/userSettings/"..args[1])
- shell.run("protect", args[1])
- else
- return
- end
- else
- print("You need to be root to do this!")
- return
- end
- end
- if #args == 2 then
- addUser()
- else
- print("USAGE: addUser [username] [password]")
- end
- ]]
- local systemInfoCode = [[
- term.clear()
- term.setCursorPos(1,1)
- print("SYSTEM INFORMATION:")
- print("museOS Version: "..os.version())
- print("Computer ID: "..tostring(os.getComputerID()))
- if os.getComputerLabel() ~= nil then
- print("Computer Label: "..os.getComputerLabel())
- else
- print("Computer Label: not set")
- end
- if museOS.getCurrentUser() == "root" then
- print(" ")
- print("LOGFILE INFORMATION:")
- print("FS Log Size: "..tostring(fs.getSize("os/logs/fileLog")).." bytes")
- print("RS Log Size: "..tostring(fs.getSize("os/logs/RSLog")).." bytes")
- print("OS Log Size: "..tostring(fs.getSize("os/logs/OSLog")).." bytes")
- print("HTTP Log Size: "..tostring(fs.getSize("os/logs/HTTPLog")).." bytes")
- end
- print("Press any key to exit.")
- os.pullEvent("key")
- term.clear()
- term.setCursorPos(1,1)
- ]]
- local whoamiCode =[[
- print("You are: "..museOS.getCurrentUser())
- print("ID: "..museOS.getUserID())
- ]]
- local protectCode = [[
- args = {...}
- local function addProtectedFolder()
- if museOS.getCurrentUser() == "root" then
- if not fs.exists(args[1]) then
- print("ERROR: Target directory does not exist!")
- end
- if not fs.isDir(args[1]) then
- print("ERROR: Target is not a directory!")
- end
- local protectedList = fs.open("os/protected", "a")
- protectedList.writeLine(args[1])
- protectedList.close()
- print("Folder protected.")
- print("You need to reboot to complete changes.")
- else
- print("You need to be root to do this!")
- end
- end
- if #args == 1 then
- addProtectedFolder()
- else
- print("USAGE: protect [path/to/folder]")
- end
- ]]
- local delUserCode = [[
- args = {...}
- function delUser()
- if museOS.getCurrentUser() == "root" then
- if args[1] == "root" then
- print("ERROR: Cannot delete root!")
- return
- end
- if not fs.exists("os/users/"..args[1]) then
- print("ERROR: User does not exist!")
- return
- end
- io.write("Are you sure you want to delete user "..args[1].."? (Y/N)>")
- local yn = io.read()
- yn = string.upper(yn)
- if yn == "Y" then
- fs.delete("os/users/"..args[1])
- if fs.exists("os/userSettings/"..args[1]) then
- fs.delete("os/userSettings/"..args[1])
- end
- if fs.exists(args[1]) then
- fs.delete(args[1])
- end
- else
- return
- end
- else
- print("You need to be root to do this!")
- return
- end
- end
- if #args == 1 then
- delUser()
- else
- print("USAGE: delUser [username]")
- end
- ]]
- local suCode = [[
- args = {...}
- local function switchUser()
- if museOS.getCurrentUser() == args[1] then
- print("You are already "..args[1].."!")
- return
- end
- if fs.exists("os/users/"..args[1]) then
- if museOS.switchUser(args[2], args[1]) then
- print("Successfully switched user!")
- print("You are now: "..args[1])
- end
- else
- print("ERROR: User does not exist!")
- end
- end
- if #args == 2 then
- switchUser()
- else
- print("USAGE: su [target user] [target password]")
- end
- ]]
- local changePasswordCode = [[
- args = {...}
- if #args == 3 then
- if museOS.authenticate(args[1], args[2]) then
- local userHandle = fs.open("os/users/"..args[1], "w")
- userHandle.write(args[3])
- userHandle.close()
- print("Done.")
- print("The new password is: "..args[3])
- else
- print("ERROR: Incorrect password!")
- end
- else
- print("USAGE: changePassword [target] [old password] [new password]")
- end
- ]]
- local function install(file,code)
- if not fs.exists("bin") then
- fs.makeDir("bin")
- end
- local handle = fs.open(fs.combine("bin/", file), "w")
- handle.write(code)
- handle.close()
- end
- print("MuSeOS Program Installer")
- print("Installing programs...")
- install("logViewer", logViewerCode)
- install("sudo", sudoCode)
- install("su", suCode)
- install("addUser", addUserCode)
- install("systemInfo", systemInfoCode)
- install("whoami", whoamiCode)
- install("protect", protectCode)
- install("delUser", delUserCode)
- install("changePassword", changePasswordCode)
- install("diskInfo", diskInfoCode)
- install("updater", updaterCode)
- if turtle then
- install("turtleSettings", turtleSettingsCode)
- end
- shell.run("pastebin", "get", "PN57E2qM", "bin/backup")
- shell.run("pastebin", "get", "yj5kcKfV", "bin/backupServer")
- print("All done here.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement