Professional Documents
Culture Documents
#################
#
#
edit_line bundles
##################################
#################
1) bundle edit_line insert_lines(lines)
{
insert_lines:
"$(lines)"
comment => "Append lines if they don't exist";
}
##
}
##
}
##
}
##
insert_lines:
"search $(search)"
"nameserver $(list)"
##
14) bundle edit_line set_variable_values(v)
# Sets the RHS of variables in the file of the form
#
LHS = RHS
# Adds a new line if no LHS exists, repairs RHS values if one does exist
#
# To use:
#
1) Define an array, where the keys are the LHS and the values are the RHS
#
"stuff[lhs-1]" string => "rhs1";
#
"stuff[lhs-2]" string => "rhs2";
#
2) The parameter passed to the edit_line promise is the fully qualified
#
name of the array (i.e., "bundlename.stuff") WITHOUT any "$" or "@"
{
vars:
"index" slist => getindices("$(v)");
# Be careful if the index string contains funny chars
"cindex[$(index)]" string => canonify("$(index)");
field_edits:
# match a line starting like the key = something
"\s*$(index)\s*=.*"
edit_field => col("=","2","$($(v)[$(index)])","set"),
classes => if_ok("$(cindex[$(index)])_in_file"),
comment => "Match a line starting like key = something";
insert_lines:
"$(index)=$($(v)[$(index)])",
{
vars:
"index"
classes:
"add_$(index)" not => userexists("$(index)");
insert_lines:
"$($(v)[$(index)])",
comment => "Append users into a password file format",
ifvarclass => "add_$(index)";
}
##
classes:
"add_$(index)" not => groupexists("$(index)");
insert_lines:
"$($(v)[$(index)])",
comment => "Append users into a group file format",
ifvarclass => "add_$(index)";
}
##
20) bundle edit_line set_user_field(user,field,val)
# Set the value of field number "field" in
# a :-field formatted file like /etc/passwd
{
field_edits:
"$(user):.*"
comment => "Edit a user attribute in the password file",
edit_field => col(":","$(field)","$(val)","set");
}
##
a single line.
the line to the file.
line (it is automatically
the line) to avoid
{
vars:
"cline" string => canonify("$(line)");
replace_patterns:
"^(?!$(line)$)$(pattern)$"
replace_with => value("$(line)"),