Skip to content

Instantly share code, notes, and snippets.

@raphink
Last active September 23, 2015 15:03
Show Gist options
  • Save raphink/4fcb67ae9b56675e76a8 to your computer and use it in GitHub Desktop.
Save raphink/4fcb67ae9b56675e76a8 to your computer and use it in GitHub Desktop.
Auglua implementation of augeasproviders_shellvar
$ ./shellvar.lua ensure=present target=/tmp/foo key=foo value=bar
Saved 1 file(s)
#!/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