Skip to content

Instantly share code, notes, and snippets.

@sandromello
Forked from nickanderson/cfengine_stdlib.cf
Created May 7, 2012 20:34
Show Gist options
  • Save sandromello/2630221 to your computer and use it in GitHub Desktop.
Save sandromello/2630221 to your computer and use it in GitHub Desktop.
bundle edit_line set_variable_values2(file,v)
#
# Another implementation of set_variable_values.
# The input and output should be exactly the same (except the file name),
# but in some Cfengine versions there are bugs,
# so this bundle can be used as a workaround.
#
{
vars:
"index" slist => getindices("$(v)");
# Be careful if the index string contains funny chars
"cindex[$(index)]" string => canonify("$(index)");
"fieldc_$(cindex[$(index)])" int => getfields("$(index).*","$(file)","=","FIELD_$(cindex[$(index)])");
classes:
"$(cindex[$(index)])_in_file" expression => strcmp("$(index)=$($(v)[$(index)])", "$(FIELD_$(index)[1])=$(FIELD_$(index)[2])");
delete_lines: # delete any lhs when no match
"$(index)=.*",
ifvarclass => "!$(cindex[$(index)])_in_file";
insert_lines:
"$(index)=$($(v)[$(index)])",
comment => "Insert a variable definition",
ifvarclass => "!$(cindex[$(index)])_in_file";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment