Advertisement
PrinceOfCookies

Untitled

Aug 3rd, 2024
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. local drive = peripheral.find("drive")
  2.  
  3. if not drive then
  4. cosUtils.error(term, "Disk drive not found, please attach a disk drive")
  5. end
  6.  
  7. if not drive.isDiskPresent() then
  8. cosUtils.error(term, "No disk found, please insert a disk")
  9. end
  10.  
  11. if fs.list("disk")[1] then
  12. cosUtils.error(term, "Disk already has data, please insert a blank disk")
  13. end
  14.  
  15. if drive.getDiskLabel() then
  16. cosUtils.error(term, "Disk has been labeled, please insert a blank disk")
  17. end
  18.  
  19. shell.run("cd os/data/programs/osEdit")
  20.  
  21. local function copyToDisk(file)
  22.  
  23. if fs.isDir(file) then
  24. local files = fs.list(file)
  25. for _, f in ipairs(files) do
  26. copyToDisk(file .. "/" .. f)
  27. end
  28. else
  29. if fs.exists(file) then
  30. local fileHandle = fs.open(file, "r")
  31. local data = fileHandle.readAll()
  32. fileHandle.close()
  33.  
  34. local diskHandle = fs.open(fs.combine("disk", file), "w")
  35. diskHandle.write(data)
  36. diskHandle.close()
  37.  
  38. local side = peripheral.getName(drive)
  39. if not drive.getDiskLabel() then
  40. print("Running label set " .. side .. " COS Edit Check")
  41. shell.run("label set " .. side .. " \"COS Edit Check\"")
  42. end
  43. else
  44. cosUtils.error(term, "File not found: " .. file)
  45. end
  46. end
  47. end
  48.  
  49. local function copyFilesToDiskRoot(startingDir)
  50. -- Copy everything inside this folder to disk/, but not this folder
  51. local files = fs.list(startingDir)
  52. for _, f in ipairs(files) do
  53. if fs.isDir(startingDir .. "/" .. f) then
  54. copyFilesToDiskRoot(startingDir .. "/" .. f)
  55. else
  56. copyToDisk(startingDir .. "/" .. f)
  57. shell.run("rm " .. startingDir .. "/" .. f)
  58. end
  59. end
  60. end
  61.  
  62. local w, h = term.getSize()
  63.  
  64. copyToDisk(shell.dir())
  65. copyFilesToDiskRoot("disk/os/data/programs/osEdit")
  66. shell.run("rm disk/os")
  67. shell.run("os/.command")
  68. shell.run("cd /") -- Just in case
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement