Last active
September 23, 2015 15:03
-
-
Save raphink/4fcb67ae9b56675e76a8 to your computer and use it in GitHub Desktop.
Auglua implementation of augeasproviders_shellvar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./shellvar.lua ensure=present target=/tmp/foo key=foo value=bar | |
Saved 1 file(s) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/home/rpinson/dev/hercules-team/augeas/src/augtool -Alf | |
args = {...} | |
params = {} | |
for i, a in ipairs(args) do | |
a:gsub("([^=]+)=([^=]+)", function(k, v) params[k] = v end) | |
end | |
aug.transform("Shellvars.lns", params['target'], false) | |
aug.load() | |
aug.defnode("target", "/files" .. params['target'], nil) | |
resource_path = "$target/" .. params['key'] | |
if ensure == "absent" then | |
aug.rm(resource_path) | |
elseif ensure == "unset" then | |
--- place it properly if it exists | |
if (aug.matches("$target/@unset/*[. = '" .. params['key'] .. "']") == 0) then | |
aug.set("$target/@unset[last()+1]/1", params['key']) | |
end | |
else | |
aug.set(resource_path, params['value']) | |
if ensure == "exported" then | |
aug.clear(resource_path .. "/export") | |
end | |
end | |
aug.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment