Skip to content

Commit

Permalink
Merge pull request #11822 from vojtapolasek/extend_umask_bashrc_rule
Browse files Browse the repository at this point in the history
accounts_umask_etc_bashrc: extend handled cases of umask
  • Loading branch information
jan-cerny authored Apr 17, 2024
2 parents d3fef69 + ad4277c commit f35e3a3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<ind:textfilecontent54_object id="obj_umask_from_etc_bashrc"
comment="Umask value from {{{ etc_bash_rc }}}" version="1">
<ind:filepath>{{{ etc_bash_rc }}}</ind:filepath>
<ind:pattern operation="pattern match">^[\s]*umask[\s]+([^#\s]*)</ind:pattern>
<ind:pattern operation="pattern match">^[^#]*\bumask\s+([^#\s]*)</ind:pattern>
<ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
</ind:textfilecontent54_object>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# packages = bash

sed -i '/umask/d' /etc/bashrc
echo " [ `umask` -eq 0 ] && umask 022" >> /etc/bashrc
umask 000

0 comments on commit f35e3a3

Please sign in to comment.