Cakejoke

[CC] COS-CJE install script (disk)

Dec 22nd, 2012
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.66 KB | None | 0 0
  1. local tArgs = {...}
  2. local isTurtle = os.version():match("TurtleOS") ~= nil
  3. local isAdvanced = term.isColor()
  4. local flags = tArgs[1]
  5. local availableFlags = "OTot"
  6. local startupFile
  7. local tabSpan
  8. local str
  9.  
  10. local function printProgress(message, color)
  11.     if isAdvanced then
  12.         term.setTextColor(color)
  13.     end
  14.     print(message)
  15.     if isAdvanced then
  16.         term.setTextColor(colors.white)
  17.     end
  18. end
  19.  
  20. local function isFlagSet(flag)
  21.     return flags:match(flag) ~= nil
  22. end
  23.  
  24. if not flags then
  25.     flags = isTurtle and "-t" or "-T"
  26. end
  27.  
  28. if flags == "help" then
  29.     printProgress("Usage: install [-{flags}]", colors.white)
  30.     printProgress("Available flags: "..availableFlags)
  31. end
  32.  
  33. if flags and string.sub(flags, 1, 1) ~= "-" then
  34.     printProgress("Invalid flags", colors.red)
  35.     printProgress("Usage: install [-{flags}]", colors.white)
  36.     printProgress("Available flags: "..availableFlags)
  37. end
  38.  
  39. printProgress("Cakejoke Edition is being installed over "..(isTurtle and
  40.         "TurtleOS" or "CraftOS"), colors.yellow)
  41.  
  42. if fs.exists("cos-cje") and fs.isDir("cos-cje") then
  43.     printProgress("System files already there, overriding", colors.blue)
  44.     fs.delete("/cos-cje")
  45. elseif fs.exists("/cos-cje") and not fs.isDir("/cos-cje") then
  46.     if isFlagSet("O") then
  47.         printProgress("/cos-cje exists, canceling")
  48.         return
  49.     end
  50.     if not isFlagSet("o") then
  51.         printProgress("File exists: /cos-cje; override or cancel? {o|c}", colors.red)
  52.         local input = read()
  53.         if input == "o" then
  54.             fs.delete("/cos-cje")
  55.         elseif input == "c" then
  56.             return
  57.         else
  58.             printProgress("Invalid input, 'o' or 'c'", colors.red)
  59.         end
  60.     end
  61. end
  62.  
  63. printProgress("Copying Files", colors.blue)
  64. fs.copy("/disk/cos-cje", "/cos-cje")
  65. printProgress("Done", colors.lime)
  66.  
  67. printProgress("Setting up startup file", colors.blue)
  68. if fs.exists("/startup") then
  69.     if isFlagSet("O") then
  70.         printProgress("startup exists, canceling")
  71.         return
  72.     end
  73.     if not isFlagSet("o") then
  74.         printProgress("startup exists, override or cancel? {o|c}", colors.orange)
  75.         local input
  76.         while true do
  77.             input = read()
  78.             if input == "o" then
  79.                 break
  80.             elseif input == "c" then
  81.                 return
  82.             else
  83.                 printProgress("Invalid input, 'o' or 'c'", colors.red)
  84.             end
  85.         end
  86.     end
  87. end
  88. fs.delete("/startup")
  89. fs.move("/cos-cje/startup.lua", "/startup")
  90. printProgress("Done", colors.lime)
  91.  
  92. printProgress("Renaming APIs and programs", colors.blue)
  93. fs.move("/cos-cje/apis/common/iox.lua", "/cos-cje/apis/common/iox")
  94. fs.move("/cos-cje/apis/common/fsx.lua", "/cos-cje/apis/common/fsx")
  95. fs.move("/cos-cje/apis/common/property.lua", "/cos-cje/apis/common/property")
  96. fs.move("/cos-cje/programs/common/cjedisk.lua", "/cos-cje/programs/common/cjedisk")
  97. if isFlagSet("T") then
  98.     printProgress("Deleting navigate API and turtle programs", colors.blue)
  99.     fs.delete("/cos-cje/apis/turtle/navigate.lua")
  100.     fs.delete("/cos-cje/programs/turtle/go.lua")
  101.     fs.delete("/cos-cje/programs/turtle/turn.lua")
  102.     fs.delete("/cos-cje/programs/turtle/writepos.lua")
  103. else
  104.     fs.move("/cos-cje/apis/turtle/navigate.lua", "/cos-cje/apis/turtle/navigate")
  105.     fs.move("/cos-cje/programs/turtle/go.lua", "/cos-cje/programs/turtle/go")
  106.     fs.move("/cos-cje/programs/turtle/turn.lua", "/cos-cje/programs/turtle/turn")
  107.     fs.move("/cos-cje/programs/turtle/writepos.lua", "/cos-cje/programs/turtle/writepos")
  108. end
  109. printProgress("Done", colors.lime)
  110.  
  111. printProgress("Creating filelinks", colors.blue)
  112. os.loadAPI("/cos-cje/apis/common/iox")
  113. os.loadAPI("/cos-cje/apis/common/fsx")
  114. if isFlagSet("t") then
  115.     fsx.createLink("/cos-cje/programs/turtle/go")
  116.     fsx.createLink("/cos-cje/programs/turtle/turn")
  117. end
  118. printProgress("Done", colors.lime)
  119.  
  120. printProgress("Cakejoke Edition installation completed", colors.yellow)
Advertisement
Add Comment
Please, Sign In to add comment