Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local shell = require("shell")
- local orig = [[return serial.unserialize(sRepos)]]
- local repl = [[local result = serial.unserialize(sRepos)
- local config = io.open("/etc/oppm-repo.cfg","r")
- if config then
- config:close()
- for line in io.lines("/etc/oppm-repo.cfg") do
- result[line] = {repo=line}
- end
- end
- return result]]
- function escape(str)
- return str:gsub("[%(%)%.%%%+%-%*%?%[%]%^%$]", function(c) return "%" .. c end)
- end
- local path, revert = ...
- if path == "revert" then
- revert = true
- path = nil
- end
- if not path then
- path = shell.resolve("oppm.lua", shell.getPath())
- if not path then
- print("oppm.lua not found")
- os.exit(1)
- return
- end
- end
- local file = io.open(path, "rb")
- if not file then
- print("File not found: " .. path)
- os.exit(1)
- return
- end
- print("Patching the file " .. path)
- local content = file:read("*a")
- file:close()
- local pattern = nil
- if revert then
- pattern = escape(repl)
- repl = orig
- else
- pattern = escape(orig)
- end
- local patched = content:gsub(pattern, repl)
- if patched == content then
- print("The file was not changed!")
- return
- end
- file = io.open(path, "w")
- file:write(patched)
- file:close()
- print("The file was patched successfully")
- file = io.open("/etc/oppm-repo.cfg", "a")
- file:close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement