Advertisement
AlexDerErste

OpenComputer-HDDClone

Aug 2nd, 2018
1,077
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.22 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("  hddclone <from> <to>")
  8.   return
  9. end
  10.  
  11. local fromstr = args[1]
  12. local tostr = args[2]
  13.  
  14. local from = {
  15.   fs = fs.proxy(args[1]),
  16.   path = nil,
  17.   label = nil
  18. }
  19. local to = {
  20.   fs = fs.proxy(args[2]),
  21.   path = nil,
  22.   label = nil
  23. }
  24.  
  25. from.label = from.fs.getLabel() == nil and from.fs.address or from.fs.getLabel()
  26. to.label = to.fs.getLabel() == nil and to.fs.address or to.fs.getLabel()
  27.  
  28. if (from == nil or to == nil) then
  29.   if (from == nil) then
  30.     io.write(args[1] .. " is not valid.")
  31.     return
  32.   end
  33.  
  34.   io.write(args[2] .. " is not valid.")
  35.   return
  36. end
  37.  
  38. for file, path in fs.mounts() do
  39.   if (file.address == from.fs.address) then
  40.     from.path = path
  41.   end
  42.  
  43.   if (file.address == to.fs.address) then
  44.     to.path = path
  45.   end
  46. end
  47.  
  48. io.write("Copying files from " .. from.path .. " to " .. to.path .. ".\n")
  49. shell.execute("cp -v -r " .. from.path .. "* " .. to.path)
  50. io.write("\27[32mDone!")
  51.  
  52. io.write("Moving files in the right directory.\n")
  53. local fromPath = "/mnt/" .. tostr .. "/" .. fromstr .. "/"
  54. local toPath = " /mnt/" .. tostr .. "/"
  55. shell.execute("move " .. fromPath .. "bin " .. toPath)
  56. io.write(fromPath .. "bin  ->  " .. toPath)
  57. shell.execute("move " .. fromPath .. "boot " .. toPath)
  58. io.write(fromPath .. "boot  ->  " .. toPath)
  59. shell.execute("move " .. fromPath .. "etc " .. toPath)
  60. io.write(fromPath .. "etc  ->  " .. toPath)
  61. shell.execute("move " .. fromPath .. "home " .. toPath)
  62. io.write(fromPath .. "home  ->  " .. toPath)
  63. shell.execute("move " .. fromPath .. "init.lua " .. toPath)
  64. io.write(fromPath .. "init.lua  ->  " .. toPath)
  65. shell.execute("move " .. fromPath .. "lib " .. toPath)
  66. io.write(fromPath .. "lib  ->  " .. toPath)
  67. shell.execute("move " .. fromPath .. "mnt " .. toPath)
  68. io.write(fromPath .. "mnt  ->  " .. toPath)
  69. shell.execute("move " .. fromPath .. "usr " .. toPath)
  70. io.write(fromPath .. "usr  ->  " .. toPath)
  71. io.write("\27[32mDone!")
  72.  
  73. io.write("Renaming " .. to.label .. " to \"" .. from.label .. "1\".\n")
  74. shell.execute("label " .. to.path .. " \"" .. from.label .. "1\"\n")
  75. io.write("\27[32mDone!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement