Advertisement
Tatantyler

MuSeOS Program Installer

Sep 14th, 2012
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.27 KB | None | 0 0
  1. --program code starts here
  2.  
  3. local turtleSettingsCode = [[
  4. -- Turtle Settings Manager
  5.  
  6. local args = {...}
  7.  
  8. local function listSettings()
  9.     local settingsFile = fs.open("os/turtle", "r")
  10.     local canMove = settingsFile.readLine()
  11.     local canDig = settingsFile.readLine()
  12.     local canPlace = settingsFile.readLine()
  13.     local canSuck = settingsFile.readLine()
  14.     settingsFile.close()
  15.     return canMove, canDig, canPlace, canSuck
  16. end
  17.  
  18. local function changeSettings(canMove, canDig, canPlace, canSuck)
  19.     local settingsFile = fs.open("os/turtle", "w")
  20.     settingsFile.writeLine(canMove)
  21.     settingsFile.writeLine(canDig)
  22.     settingsFile.writeLine(canPlace)
  23.     settingsFile.writeLine(canSuck)
  24.     settingsFile.close()
  25. end
  26.  
  27. if museOS.getCurrentUser() == "root" then
  28.     if args[1] ~= "get" then
  29.         if #args == 5 then
  30.             changeSettings(args[2], args[3], args[4], args[5])
  31.         else
  32.             print("USAGE: turtleSettings [get/set] [canMove] [canDig] [canPlace] [canSuck]")
  33.         end
  34.     else
  35.         local canMove,canDig,canPlace,canSuck = listSettings()
  36.         print("Can Move: "..canMove)
  37.         print("Can Dig: "..canDig)
  38.         print("Can Place: "..canPlace)
  39.         print("Can Suck: "..canSuck)
  40.     end
  41. else
  42.     print("You need to be root to do this!")
  43. end
  44.  
  45. ]]
  46.  
  47. local updaterCode = [[
  48. function update()
  49.     fs.delete("MuSeOS")
  50.     fs.delete("bin/man")
  51.  
  52.     shell.run("pastebin", "get", "fquZgJ5p", "MuSeOS")
  53.     shell.run("pastebin", "get", "G33dymxf", "programInstaller")
  54.     shell.run("pastebin", "get", "wfeGgwQH", "bin/man")
  55.  
  56.     shell.run("programInstaller")
  57.     fs.delete("programInstaller")
  58.     os.reboot()
  59. end
  60.  
  61. if http then
  62.     if museOS.getCurrentUser() == "root" then
  63.  
  64.         fs.makeDir("temp")
  65.         shell.run("pastebin", "get", "j8qj82d1", "temp/version")
  66.  
  67.         if not fs.exists("os/version") then
  68.             print("os/version does not exist, updating...")
  69.             fs.move("temp/version", "os/version")
  70.             update()
  71.         else
  72.             local versionFile = fs.open("os/version", "r")
  73.             local newVersionFile = fs.open("temp/version", "r")
  74.             local newVersion = newVersionFile.readAll()
  75.             local version = versionFile.readAll()
  76.             newVersionFile.close()
  77.             versionFile.close()
  78.             if newVersion > version then
  79.                 print("New version found: "..newVersion)
  80.                 fs.delete("os/version")
  81.                 fs.move("temp/version", "os/version")
  82.                 update()
  83.             else
  84.                 print("You are running the latest version!")
  85.             end
  86.             fs.delete("temp")
  87.         end
  88.  
  89.     else
  90.         print("You need to be root to do this!")
  91.     end
  92. else
  93.     print("HTTP API disabled, not checking for updates...")
  94. end
  95. ]]
  96.  
  97. local diskInfoCode = [[
  98. args = {...}
  99.  
  100. local function displayLoop()
  101.     term.clear()
  102.     term.setCursorPos(1,1)
  103.     local side = args[1]
  104.     print("Press any key to exit.")
  105.     if not disk.isPresent(side) then
  106.         print("No disk inserted.")
  107.         return
  108.     else
  109.         print("Disk mounted.")
  110.         if disk.hasData(side) then
  111.             print("Floppy disk inserted.")
  112.             print("Mount path: "..disk.getMountPath(side))
  113.             if disk.getLabel(side) == nil then
  114.                 print("Label not set.")
  115.             else
  116.                 print("Label: "..disk.getLabel(side))
  117.             end
  118.             print("ID: "..tostring(disk.getDiskID(side)))
  119.         elseif disk.hasAudio(side) then
  120.             print("Audio disk inserted.")
  121.             print("Title: "..disk.getAudioTitle(side))
  122.             print("Press ENTER to stop or start audio.")
  123.         end
  124.         print("Press SPACE to eject disk.")
  125.     end
  126. end
  127.  
  128. local audioStarted = false
  129.  
  130. while true do
  131.     displayLoop()
  132.     event, key = os.pullEvent()
  133.     if event == "key" then
  134.         if key == 57 then
  135.             disk.eject(args[1])
  136.         elseif key == 28 then
  137.             audioStarted = not audioStarted
  138.             if audioStarted then
  139.                 disk.playAudio(args[1])
  140.             else
  141.                 disk.stopAudio(args[1])
  142.             end
  143.         elseif key ~= 1 then
  144.             break
  145.         end
  146.     end
  147. end
  148. ]]
  149.  
  150. local logViewerCode = [[
  151. args = {...}
  152. local maxX, maxY = term.getSize()
  153.  
  154. local function writeAvailable(lines, offsetY)
  155.     term.clear()
  156.     term.setCursorPos(1,1)
  157.     for i=1, maxY do
  158.         print(lines[i+offsetY])
  159.     end
  160. end
  161.  
  162. local function viewLog()
  163.     if museOS.getCurrentUser() == "root" then
  164.         if not fs.exists("os/logs/"..args[1]) then
  165.             print("That log doesn't exist!")
  166.             return
  167.         end
  168.         local lines = {}
  169.         local logHandle = fs.open("os/logs/"..args[1], "r")
  170.         print("Press any key other than the up/down arrows to exit.")
  171.         os.sleep(0.5)
  172.         while true do
  173.             local line = logHandle.readLine()
  174.             if line == nil then
  175.                 break
  176.             else
  177.                 table.insert(lines, line)
  178.             end
  179.         end
  180.         logHandle.close()
  181.         writeAvailable(lines, 1)
  182.         local offset = 1
  183.         while true do
  184.             event, key = os.pullEvent("key")
  185.             if key == 200 then
  186.                 offset = offset-1
  187.                 if offset < 1 then
  188.                     offset = 1
  189.                 end
  190.             elseif key == 208 then
  191.                 offset = offset+1
  192.                 if offset > #lines then
  193.                     offset = #lines
  194.                 end
  195.             else
  196.                 term.clear()
  197.                 term.setCursorPos(1,1)
  198.                 return
  199.             end
  200.             writeAvailable(lines, offset)
  201.         end
  202.     else
  203.         print("You need to be running as root to do this!")
  204.         return
  205.     end
  206. end
  207.  
  208. if #args == 1 then
  209.     term.clear()
  210.     term.setCursorPos(1,1)
  211.     viewLog()
  212. else
  213.     print("USAGE:log [log name]")
  214. end
  215. ]]
  216.  
  217. local sudoCode = [[
  218. args = {...}
  219.  
  220. local function doSudo()
  221.     if museOS.getCurrentUser() == "root" then
  222.         print("You are already root!")
  223.         return
  224.     end
  225.     local programArgs = {}
  226.     local password = args[1]
  227.     local program = args[2]
  228.     for i,v in ipairs(args) do
  229.         if i ~= 1 and i ~= 2 then
  230.             table.insert(programArgs, v)
  231.         end
  232.     end
  233.     museOS.sudo(password, args[2], unpack(programArgs))
  234. end
  235.  
  236. if #args >= 2 then
  237.     doSudo()
  238. else
  239.     print("USAGE: sudo [password] [program] [args]")
  240. end
  241. ]]
  242.  
  243. local addUserCode = [[
  244. args = {...}
  245.  
  246. function addUser()
  247.     if museOS.getCurrentUser() == "root" then
  248.         if fs.exists("os/users/"..args[1]) then
  249.             print("ERROR: User already exists!")
  250.             return
  251.         end
  252.         io.write("Do you want to add a user called "..args[1].." with a password of "..args[2].."? (Y/N)>")
  253.         local yn = io.read()
  254.         yn = string.upper(yn)
  255.         if yn == "Y" then
  256.             local userFile = fs.open("os/users/"..args[1], "w")
  257.             userFile.writeLine(args[2])
  258.             userFile.close()
  259.             fs.makeDir(args[1])
  260.             fs.makeDir("os/userSettings/"..args[1])
  261.             shell.run("protect", args[1])
  262.         else
  263.             return
  264.         end
  265.     else
  266.         print("You need to be root to do this!")
  267.         return
  268.     end
  269. end
  270.  
  271. if #args == 2 then
  272.     addUser()
  273. else
  274.     print("USAGE: addUser [username] [password]")
  275. end
  276. ]]
  277.  
  278.  
  279. local systemInfoCode = [[
  280. term.clear()
  281. term.setCursorPos(1,1)
  282. print("SYSTEM INFORMATION:")
  283. print("museOS Version: "..os.version())
  284. print("Computer ID: "..tostring(os.getComputerID()))
  285. if os.getComputerLabel() ~= nil then
  286.     print("Computer Label: "..os.getComputerLabel())
  287. else
  288.     print("Computer Label: not set")
  289. end
  290. if museOS.getCurrentUser() == "root" then
  291.     print(" ")
  292.     print("LOGFILE INFORMATION:")
  293.     print("FS Log Size: "..tostring(fs.getSize("os/logs/fileLog")).." bytes")
  294.     print("RS Log Size: "..tostring(fs.getSize("os/logs/RSLog")).." bytes")
  295.     print("OS Log Size: "..tostring(fs.getSize("os/logs/OSLog")).." bytes")
  296.     print("HTTP Log Size: "..tostring(fs.getSize("os/logs/HTTPLog")).." bytes")
  297. end
  298. print("Press any key to exit.")
  299. os.pullEvent("key")
  300. term.clear()
  301. term.setCursorPos(1,1)
  302. ]]
  303.  
  304. local whoamiCode =[[
  305. print("You are: "..museOS.getCurrentUser())
  306. print("ID: "..museOS.getUserID())
  307. ]]
  308.  
  309. local protectCode = [[
  310. args = {...}
  311.  
  312. local function addProtectedFolder()
  313.     if museOS.getCurrentUser() == "root" then
  314.         if not fs.exists(args[1]) then
  315.             print("ERROR: Target directory does not exist!")
  316.         end
  317.         if not fs.isDir(args[1]) then
  318.             print("ERROR: Target is not a directory!")
  319.         end
  320.         local protectedList = fs.open("os/protected", "a")
  321.         protectedList.writeLine(args[1])
  322.         protectedList.close()
  323.         print("Folder protected.")
  324.         print("You need to reboot to complete changes.")
  325.     else
  326.         print("You need to be root to do this!")
  327.     end
  328. end
  329.  
  330. if #args == 1 then
  331.     addProtectedFolder()
  332. else
  333.     print("USAGE: protect [path/to/folder]")
  334. end
  335. ]]
  336.  
  337. local delUserCode = [[
  338. args = {...}
  339.  
  340. function delUser()
  341.     if museOS.getCurrentUser() == "root" then
  342.         if args[1] == "root" then
  343.             print("ERROR: Cannot delete root!")
  344.             return
  345.         end
  346.         if not fs.exists("os/users/"..args[1]) then
  347.             print("ERROR: User does not exist!")
  348.             return
  349.         end
  350.         io.write("Are you sure you want to delete user "..args[1].."? (Y/N)>")
  351.         local yn = io.read()
  352.         yn = string.upper(yn)
  353.         if yn == "Y" then
  354.             fs.delete("os/users/"..args[1])
  355.             if fs.exists("os/userSettings/"..args[1]) then
  356.                 fs.delete("os/userSettings/"..args[1])
  357.             end
  358.             if fs.exists(args[1]) then
  359.                 fs.delete(args[1])
  360.             end
  361.         else
  362.             return
  363.         end
  364.     else
  365.         print("You need to be root to do this!")
  366.         return
  367.     end
  368. end
  369.  
  370. if #args == 1 then
  371.     delUser()
  372. else
  373.     print("USAGE: delUser [username]")
  374. end
  375. ]]
  376.  
  377. local suCode = [[
  378. args = {...}
  379.  
  380. local function switchUser()
  381.     if museOS.getCurrentUser() == args[1] then
  382.         print("You are already "..args[1].."!")
  383.         return
  384.     end
  385.     if fs.exists("os/users/"..args[1]) then
  386.         if museOS.switchUser(args[2], args[1]) then
  387.             print("Successfully switched user!")
  388.             print("You are now: "..args[1])
  389.         end
  390.     else
  391.         print("ERROR: User does not exist!")
  392.     end
  393. end
  394.  
  395. if #args == 2 then
  396.     switchUser()
  397. else
  398.     print("USAGE: su [target user] [target password]")
  399. end
  400. ]]
  401.  
  402. local changePasswordCode = [[
  403. args = {...}
  404.  
  405. if #args == 3 then
  406.     if museOS.authenticate(args[1], args[2]) then
  407.         local userHandle = fs.open("os/users/"..args[1], "w")
  408.         userHandle.write(args[3])
  409.         userHandle.close()
  410.         print("Done.")
  411.         print("The new password is: "..args[3])
  412.     else
  413.         print("ERROR: Incorrect password!")
  414.     end
  415. else
  416.     print("USAGE: changePassword [target] [old password] [new password]")
  417. end
  418. ]]
  419.  
  420. local function install(file,code)
  421.     if not fs.exists("bin") then
  422.         fs.makeDir("bin")
  423.     end
  424.     local handle = fs.open(fs.combine("bin/", file), "w")
  425.     handle.write(code)
  426.     handle.close()
  427. end
  428.  
  429. print("MuSeOS Program Installer")
  430. print("Installing programs...")
  431. install("logViewer", logViewerCode)
  432. install("sudo", sudoCode)
  433. install("su", suCode)
  434. install("addUser", addUserCode)
  435. install("systemInfo", systemInfoCode)
  436. install("whoami", whoamiCode)
  437. install("protect", protectCode)
  438. install("delUser", delUserCode)
  439. install("changePassword", changePasswordCode)
  440. install("diskInfo", diskInfoCode)
  441. install("updater", updaterCode)
  442. if turtle then
  443.     install("turtleSettings", turtleSettingsCode)
  444. end
  445. shell.run("pastebin", "get", "PN57E2qM", "bin/backup")
  446. shell.run("pastebin", "get", "yj5kcKfV", "bin/backupServer")
  447. print("All done here.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement