Advertisement
soee

update

Sep 19th, 2014
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.92 KB | None | 0 0
  1. local targs = {...}
  2. --pastebin:bZWkfTbQ
  3.  
  4. local function grepFirst(filename, pattern)
  5.   local match  = ""
  6.   local rf = fs.open(filename, "r")
  7.   if (rf ~= nil) then
  8.     local line = rf.readLine()
  9.     local count = 0
  10.     while (line ~= nil) do
  11.       for token in string.gmatch(line, pattern) do
  12.         match = token
  13.         break
  14.       end
  15.  
  16.       line = rf.readLine()
  17.       count = count + 1
  18.       if ((match ~= "") or (count > 10)) then
  19.         break
  20.       end
  21.     end
  22.     rf:close()
  23.   end
  24.   return match
  25. end
  26.  
  27. local filename = targs[1]
  28. print("Updating :", filename)
  29.  
  30. if fs.exists(filename) then
  31.   local pastebinId = grepFirst(filename, "--pastebin:(%w+)")
  32.   if (pastebinId == "") then
  33.     print("No pastebin id found in ", filename)
  34.   else
  35.     print("found : ", pastebinId)
  36.     shell.run("rm ", filename)
  37.     shell.run("pastebin get ", pastebinId, filename)
  38.   end
  39. else
  40.   print(filename, " not found !")
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement