Advertisement
Guest User

startup.lua

a guest
May 21st, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.06 KB | None | 0 0
  1. if fs.exists("blueos/") == false then
  2.     fs.makeDir("blueos")
  3. end
  4. if fs.exists("blueos/home") == false then
  5.     fs.makeDir("blueos/home")
  6. end
  7. if fs.exists("blueos/data") == false then
  8.     local file = fs.open("blueos/data","w")
  9.     file.write("0")
  10.     file.close()
  11. end
  12. local file = fs.open("blueos/data","r")
  13. local startups = file.readLine()
  14. file.close()
  15.  
  16. if tonumber(startups) ~= nil then
  17.     local file = fs.open("blueos/data","w")
  18.     file.write(tostring(startups + 1))
  19.     local startups = startups + 1
  20.     file.close()
  21. else
  22.     startups = "error"
  23. end
  24. term.clear()
  25. term.setCursorPos(1,2)
  26. term.setTextColor(colors.blue)
  27. write("Blue OS")
  28. local width, height = term.getSize()
  29. paintutils.drawLine(1,3,width,3,colors.lightGray)
  30. term.setTextColor(colors.black)
  31. term.setCursorPos(1,3)
  32. local motd = {
  33.     [1] = "Blue OS: It's terrible!",
  34.     [2] = "Why are you using this?",
  35.     [3] = "Hey, got anything better to do?",
  36.     [4] = "Made by MinerMan132 (god what have I done)",
  37.     [5] = "Hi diddly ho neighborino!",
  38.     [6] = "Color or colour?",
  39.     [7] = "You've used this terrible OS "..startups.." times!",
  40.     [8] = "The BlueOS help program is simpley called \"help\""
  41.     }
  42. write("  ")
  43. print(motd[math.random(1,#motd)])
  44. print("")
  45. term.setBackgroundColor(colors.black)
  46. shell.setDir("blueos/home")
  47.  
  48. local function main()
  49. while true do
  50.     term.setTextColor(colors.blue)
  51.     write(" ")
  52.     if shell.dir() ~= "" then
  53.         write("/")
  54.     end
  55.     write(shell.dir().." > ")
  56.     term.setTextColor(colors.cyan)
  57.     local command = read()
  58.     if command ~= "uninstall" then
  59.         shell.run(command)
  60.     else
  61.         if fs.exists(shell.dir().."/uninstall") then
  62.             print("Do you want to run the program \"uninstall\", instead of uninstalling BlueOS? (y/n)")
  63.             local awnser = read()
  64.             if awnser == "y" or "yes" then
  65.                 uninstallc = true
  66.             else
  67.                 shell.run("uninstall")
  68.             end
  69.         else
  70.             uninstallc = true
  71.         end
  72.         if uninstallc == true then
  73.             term.setTextColor(colors.blue)
  74.             print("Are you absolutely sure you want to uninstall BlueOS?")
  75.             print("This will delete ALL files you have stored under the BlueOS directory!")
  76.             print("(y/n)")
  77.             term.setTextColor(colors.red)
  78.             local awnser = read()
  79.             if awnser == "y" or awnser == "yes" then
  80.                 term.setTextColor(colors.blue)
  81.                 print("Final confirmation. Please don't. (y/n)")
  82.                 term.setTextColor(colors.red)
  83.                 local awnser = read()
  84.                 if awnser == "y" or awnser == "yes" then
  85.                     write("Ok, bye  ")
  86.                     sleep(1)
  87.                     write(":")
  88.                     sleep(1)
  89.                     write("'")
  90.                     sleep(1)
  91.                     write("(")
  92.                     sleep(2)
  93.                     term.setTextColor(colors.red)
  94.                     print("")
  95.                     print("Removing Directory")
  96.                     fs.delete("blueos/")
  97.                     print("Removing Startupfile")
  98.                     fs.delete(shell.getRunningProgram())
  99.                 else
  100.                 term.setTextColor(colors.lightBlue)
  101.                 print("Yay! Thanks! :D")
  102.                 uninstallc = nil
  103.                 end
  104.             else
  105.             uninstallc = nil
  106.             end
  107.         end
  108.     end
  109. end
  110. end
  111.  
  112. function stop()
  113. while true do
  114.     local ok, msg = pcall(main)
  115.     if not ok then
  116.         print("")
  117.         printError("Whoopsie it crashed!")
  118.         printError("Error: "..msg)
  119.         term.setTextColor(colors.lightBlue)
  120.         term.setCursorBlink(false)
  121.        
  122.         print("Restarting in 5 seconds . . .")
  123.         sleep(5)
  124.         os.reboot()
  125.     end
  126. end
  127. end
  128.  
  129. while true do
  130.     local ok2, msg2 = pcall(stop)
  131.     if not ok then
  132.         term.setTextColor(colors.yellow)
  133.         print("Returning to shell...")
  134.         shell.setDir("")
  135.         sleep(0.3)
  136.         break
  137.     end
  138. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement