@@ -39,35 +39,51 @@ Changes are immediate, there is no need to reboot.
3939
4040DO_NOT_ASK=" Do you wish to not see this message again about unprivileged user-namespaces?"
4141
42- # if this fails, namespaces are disabled
42+ # do not bother if unshare or /bin/true are missing
43+ _sanity_check () {
44+ if command -v unshare && command -v /bin/true; then
45+ return 0
46+ fi
47+ return 1
48+ }
49+
4350_check_usernamespaces_work () {
44- if command -v /bin/true && unshare --help | grep -q -- ' --user' ; then
51+ if unshare --help | grep -q -- ' --user' ; then
4552 unshare --user -p /bin/true && return 0
4653 fi
4754 return 1
4855}
4956
50- _fix_usernamespaces () {
51- if command -v sysctl 1> /dev/null && [ -d /etc/sysctl.d ] \
52- && command -v pkexec 1> /dev/null \
53- && [ -e /proc/sys/kernel/apparmor_restrict_unprivileged_userns ]; then
54- apparmor_based=1
55- elif command -v ujust 1> /dev/null \
56- && ujust | grep -q toggle-unconfined-domain-userns-creation; then
57- secureblue_based=1
57+ _is_apparmor () {
58+ if [ -d /etc/sysctl.d ] && command -v sysctl && command -v pkexec; then
59+ if [ -e /proc/sys/kernel/apparmor_restrict_unprivileged_userns ]; then
60+ return 0
61+ fi
62+ fi
63+ return 1
64+ }
65+
66+ _is_secureblue () {
67+ if command -v ujust; then
68+ if ujust | grep -q toggle-unconfined-domain-userns-creation; then
69+ return 0
5870 fi
59-
60- if [ " $apparmor_based " = 1 ]; then
71+ fi
72+ return 1
73+ }
74+
75+ _fix_usernamespaces () {
76+ if _is_apparmor 1> /dev/null; then
6177 if notify --display-question " $INFO_MESSAGE_FIX_APPARMOR " ; then
6278 pkexec /bin/sh -c "
63- echo 'kernel.apparmor_restrict_unprivileged_userns = 0' \
64- | tee /etc/sysctl.d/20-fix-namespaces.conf
65- sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
79+ echo 'kernel.apparmor_restrict_unprivileged_userns = 0' \
80+ | tee /etc/sysctl.d/20-fix-namespaces.conf
81+ sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
6682 "
6783 else
6884 return 1
6985 fi
70- elif [ " $secureblue_based " = 1 ] ; then
86+ elif _is_secureblue 1> /dev/null ; then
7187 if notify --display-question " $INFO_MESSAGE_FIX_SECUREBLUE " ; then
7288 ujust toggle-unconfined-domain-userns-creation
7389 else
@@ -85,7 +101,9 @@ _do_not_ask_again() {
85101
86102if [ -f " $LOCKFILEPATH " ]; then
87103 exit 0
88- elif _check_usernamespaces_work > /dev/null 2>&1 ; then
104+ elif ! _sanity_check 1> /dev/null; then
105+ exit 0
106+ elif _check_usernamespaces_work 1> /dev/null; then
89107 exit 0
90108elif _fix_usernamespaces; then
91109 exit 0
0 commit comments