Advertisement
Guest User

dcopy.lua

a guest
Jun 8th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.13 KB | None | 0 0
  1. local ecc = require "./ecc"
  2. local t = ecc "ecc"
  3.  
  4. local thing = ...
  5. local function fread(thing)
  6.     local f = fs.open(thing, "r")
  7.     local text = f.readAll()
  8.     f.close()
  9.     return text
  10. end
  11.  
  12. local function hexize(key)
  13.     local out = ""
  14.     for _, v in pairs(key) do
  15.         out = out .. string.format("%.2x", v)
  16.     end
  17.     return out
  18. end
  19.  
  20. local function fwrite(fname, text)
  21.     local f = fs.open(fname, "w")
  22.     f.write(text)
  23.     f.close()
  24. end
  25.  
  26. local pkey = textutils.unserialise(fread ".potato_rds_priv")
  27.  
  28. while true do
  29.     local _, side = os.pullEvent "disk"
  30.     local mp = disk.getMountPath(side)
  31.     local path = fs.combine(mp, "startup")
  32.     local sig_path = fs.combine(mp, "signature")
  33.     local UUID_path = fs.combine(mp, "UUID")
  34.     local UUID = math.random(0, 1000000)
  35.     print(UUID)
  36.     disk.setLabel(side, thing)
  37.     local text = fread(thing):gsub("@UUID@", tostring(UUID))
  38.     --print(text, path)
  39.     fwrite(path, text)
  40.     print "Written data."
  41.     fwrite(sig_path, hexize(t.sign(
  42.         pkey,
  43.         text
  44.     )))
  45.     fwrite(UUID_path, tostring(UUID))
  46.     print "Written signature."
  47. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement