diff --git a/shared/macros/10-bash.jinja b/shared/macros/10-bash.jinja index c044b9b875fe..626c3accaafd 100644 --- a/shared/macros/10-bash.jinja +++ b/shared/macros/10-bash.jinja @@ -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