Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local drive = peripheral.find("drive")
- if not drive then
- cosUtils.error(term, "Disk drive not found, please attach a disk drive")
- end
- if not drive.isDiskPresent() then
- cosUtils.error(term, "No disk found, please insert a disk")
- end
- if fs.list("disk")[1] then
- cosUtils.error(term, "Disk already has data, please insert a blank disk")
- end
- if drive.getDiskLabel() then
- cosUtils.error(term, "Disk has been labeled, please insert a blank disk")
- end
- shell.run("cd os/data/programs/osEdit")
- local function copyToDisk(file)
- if fs.isDir(file) then
- local files = fs.list(file)
- for _, f in ipairs(files) do
- copyToDisk(file .. "/" .. f)
- end
- else
- if fs.exists(file) then
- local fileHandle = fs.open(file, "r")
- local data = fileHandle.readAll()
- fileHandle.close()
- local diskHandle = fs.open(fs.combine("disk", file), "w")
- diskHandle.write(data)
- diskHandle.close()
- local side = peripheral.getName(drive)
- if not drive.getDiskLabel() then
- print("Running label set " .. side .. " COS Edit Check")
- shell.run("label set " .. side .. " \"COS Edit Check\"")
- end
- else
- cosUtils.error(term, "File not found: " .. file)
- end
- end
- end
- local function copyFilesToDiskRoot(startingDir)
- -- Copy everything inside this folder to disk/, but not this folder
- local files = fs.list(startingDir)
- for _, f in ipairs(files) do
- if fs.isDir(startingDir .. "/" .. f) then
- copyFilesToDiskRoot(startingDir .. "/" .. f)
- else
- copyToDisk(startingDir .. "/" .. f)
- shell.run("rm " .. startingDir .. "/" .. f)
- end
- end
- end
- local w, h = term.getSize()
- copyToDisk(shell.dir())
- copyFilesToDiskRoot("disk/os/data/programs/osEdit")
- shell.run("rm disk/os")
- shell.run("os/.command")
- shell.run("cd /") -- Just in case
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement