Advertisement
Kodos

[OC] clone.lua

Jan 20th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.12 KB | None | 0 0
  1. local fs = require("filesystem")
  2. local shell = require("shell")
  3.  
  4. local args, options = shell.parse(...)
  5. if #args < 2 then
  6.     io.write("Usage:\n")
  7.     io.write("  clone <from> <to>")
  8.     return
  9. end
  10.  
  11. local from = {
  12.     fs = fs.proxy(args[1]),
  13.     path = nil,
  14.     label = nil
  15. }
  16. local to = {
  17.     fs = fs.proxy(args[2]),
  18.     path = nil,
  19.     label = nil
  20. }
  21.  
  22. from.label = from.fs.getLabel() == nil and from.fs.address or from.fs.getLabel()
  23. to.label = to.fs.getLabel() == nil and to.fs.address or to.fs.getLabel()
  24.  
  25. if (from == nil or to == nil) then
  26.     if (from == nil) then
  27.         io.write(args[1] .. " is not valid.")
  28.         return
  29.     end
  30.  
  31.     io.write(args[2] .. " is not valid.")
  32.     return
  33. end
  34.  
  35. for file, path in fs.mounts() do
  36.     if (file.address == from.fs.address) then
  37.         from.path = path
  38.     end
  39.  
  40.     if (file.address == to.fs.address) then
  41.         to.path = path
  42.     end
  43. end
  44.  
  45. io.write("Copying files from " .. from.path .. " to " .. to.path .. ".\n")
  46. shell.execute("cp -v -r " .. from.path .. "* " .. to.path)
  47.  
  48. io.write("Renaming " .. to.label .. " to \"Copy of " .. from.label .. "\".\n")
  49. shell.execute("label " .. to.path .. " \"Copy of " .. from.label .. "\"\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement