Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local fs = require("filesystem")
- local shell = require("shell")
- local args, options = shell.parse(...)
- if #args < 2 then
- io.write("Usage:\n")
- io.write(" hddclone <from> <to>")
- return
- end
- local fromstr = args[1]
- local tostr = args[2]
- local from = {
- fs = fs.proxy(args[1]),
- path = nil,
- label = nil
- }
- local to = {
- fs = fs.proxy(args[2]),
- path = nil,
- label = nil
- }
- from.label = from.fs.getLabel() == nil and from.fs.address or from.fs.getLabel()
- to.label = to.fs.getLabel() == nil and to.fs.address or to.fs.getLabel()
- if (from == nil or to == nil) then
- if (from == nil) then
- io.write(args[1] .. " is not valid.")
- return
- end
- io.write(args[2] .. " is not valid.")
- return
- end
- for file, path in fs.mounts() do
- if (file.address == from.fs.address) then
- from.path = path
- end
- if (file.address == to.fs.address) then
- to.path = path
- end
- end
- io.write("Copying files from " .. from.path .. " to " .. to.path .. ".\n")
- shell.execute("cp -v -r " .. from.path .. "* " .. to.path)
- io.write("\27[32mDone!")
- io.write("Moving files in the right directory.\n")
- local fromPath = "/mnt/" .. tostr .. "/" .. fromstr .. "/"
- local toPath = " /mnt/" .. tostr .. "/"
- shell.execute("move " .. fromPath .. "bin " .. toPath)
- io.write(fromPath .. "bin -> " .. toPath)
- shell.execute("move " .. fromPath .. "boot " .. toPath)
- io.write(fromPath .. "boot -> " .. toPath)
- shell.execute("move " .. fromPath .. "etc " .. toPath)
- io.write(fromPath .. "etc -> " .. toPath)
- shell.execute("move " .. fromPath .. "home " .. toPath)
- io.write(fromPath .. "home -> " .. toPath)
- shell.execute("move " .. fromPath .. "init.lua " .. toPath)
- io.write(fromPath .. "init.lua -> " .. toPath)
- shell.execute("move " .. fromPath .. "lib " .. toPath)
- io.write(fromPath .. "lib -> " .. toPath)
- shell.execute("move " .. fromPath .. "mnt " .. toPath)
- io.write(fromPath .. "mnt -> " .. toPath)
- shell.execute("move " .. fromPath .. "usr " .. toPath)
- io.write(fromPath .. "usr -> " .. toPath)
- io.write("\27[32mDone!")
- io.write("Renaming " .. to.label .. " to \"" .. from.label .. "1\".\n")
- shell.execute("label " .. to.path .. " \"" .. from.label .. "1\"\n")
- io.write("\27[32mDone!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement