diff --git a/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/ansible/shared.yml b/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/ansible/shared.yml index 4b96087f59b..3cc2f3b32b0 100644 --- a/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/ansible/shared.yml +++ b/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/ansible/shared.yml @@ -14,7 +14,7 @@ - name: Check if umask in {{{ etc_bash_rc }}} is already set ansible.builtin.lineinfile: path: {{{ etc_bash_rc }}} - regexp: ^(\s*)umask\s+.* + regexp: ^[^#]*\bumask\s+ state: absent check_mode: true changed_when: false @@ -23,7 +23,7 @@ - name: Replace user umask in {{{ etc_bash_rc }}} ansible.builtin.replace: path: {{{ etc_bash_rc }}} - regexp: ^(\s*)umask(\s+).* + regexp: ^([^#]*\b)umask(\s*) replace: \g<1>umask\g<2>{{ var_accounts_user_umask }} when: - umask_replace.found > 0 diff --git a/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/bash/shared.sh b/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/bash/shared.sh index 7c030200334..675ff67789e 100644 --- a/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/bash/shared.sh +++ b/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/bash/shared.sh @@ -8,8 +8,8 @@ {{% set etc_bash_rc = "/etc/bashrc" %}} {{% endif %}} -grep -q "^\s*umask" {{{ etc_bash_rc }}} && \ - sed -i -E -e "s/^(\s*umask).*/\1 $var_accounts_user_umask/g" {{{ etc_bash_rc }}} +grep -q "^[^#]*\bumask" {{{ etc_bash_rc }}} && \ + sed -i -E -e "s/^([^#]*\bumask).*/\1 $var_accounts_user_umask/g" {{{ etc_bash_rc }}} if ! [ $? -eq 0 ]; then echo "umask $var_accounts_user_umask" >> {{{ etc_bash_rc }}} fi diff --git a/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/oval/shared.xml b/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/oval/shared.xml index fddd9ddb8e9..597758a90df 100644 --- a/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/oval/shared.xml +++ b/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/oval/shared.xml @@ -16,7 +16,7 @@ {{{ etc_bash_rc }}} - ^[\s]*umask[\s]+([^#\s]*) + ^[^#]*\bumask\s+([^#\s]*) 1 diff --git a/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/tests/wrong_and_not_at_the_begining_of_line.fail.sh b/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/tests/wrong_and_not_at_the_begining_of_line.fail.sh new file mode 100644 index 00000000000..7a70747b3ae --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/tests/wrong_and_not_at_the_begining_of_line.fail.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# packages = bash + +sed -i '/umask/d' /etc/bashrc +echo " [ `umask` -eq 0 ] && umask 022" >> /etc/bashrc +umask 000