Skip to content

Commit

Permalink
WIP: Update more macros regarding variables
Browse files Browse the repository at this point in the history
Signed-off-by: Marcus Burghardt <[email protected]>
  • Loading branch information
marcusburghardt committed Jul 9, 2024
1 parent e3a7916 commit 408120a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions shared/macros/10-bash.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2158,22 +2158,22 @@ fi

#}}
{{%- macro bash_ensure_pam_module_line(pam_file, group, control, module, after_match='') -%}}
if ! grep -qP '^\s*{{{ group }}}\s+'"{{{ control }}}"'\s+{{{ module }}}\s*.*' "{{{ pam_file }}}"; then
if ! grep -qP "^\s*{{{ group }}}\s+{{{ control }}}\s+{{{ module }}}\s*.*{{{ pam_file }}}"; then
# Line matching group + control + module was not found. Check group + module.
if [ "$(grep -cP '^\s*{{{ group }}}\s+.*\s+{{{ module }}}\s*' "{{{ pam_file }}}")" -eq 1 ]; then
# The control is updated only if one single line matches.
sed -i -E --follow-symlinks 's/^(\s*{{{ group }}}\s+).*(\b{{{ module }}}.*)/\1'"{{{ control }}}"' \2/' "{{{ pam_file }}}"
sed -i -E --follow-symlinks "s/^(\s*{{{ group }}}\s+).*(\b{{{ module }}}.*)/\1{{{ control }}} \2/" "{{{ pam_file }}}"
else
{{%- if after_match == '' %}}
echo '{{{ group }}} '"{{{ control }}}"' {{{ module }}}' >> "{{{ pam_file }}}"
echo "{{{ group }}} {{{ control }}} {{{ module }}}" >> "{{{ pam_file }}}"
{{%- elif after_match == 'BOF' %}}
sed -i --follow-symlinks '1i {{{ group }}} '"{{{ control }}}"' {{{ module }}}' "{{{ pam_file }}}"
sed -i --follow-symlinks "1i {{{ group }}} {{{ control }}} {{{ module }}}" "{{{ pam_file }}}"
{{%- else %}}
LAST_MATCH_LINE=$(grep -nP "{{{ after_match }}}" "{{{ pam_file }}}" | tail -n 1 | cut -d: -f 1)
if [ ! -z $LAST_MATCH_LINE ]; then
sed -i --follow-symlinks $LAST_MATCH_LINE' a {{{ group }}} '"{{{ control }}}"' {{{ module }}}' "{{{ pam_file }}}"
sed -i --follow-symlinks $LAST_MATCH_LINE" a {{{ group }}} {{{ control }}} {{{ module }}}" "{{{ pam_file }}}"
else
echo '{{{ group }}} '"{{{ control }}}"' {{{ module }}}' >> "{{{ pam_file }}}"
echo "{{{ group }}} {{{ control }}} {{{ module }}}" >> "{{{ pam_file }}}"
fi
{{%- endif %}}
fi
Expand Down

0 comments on commit 408120a

Please sign in to comment.