more robust dockerd-rootless-setuptools.sh
Fixing case where username may contain a backslash. This case can happen for winbind/samba active directory domain users. Signed-off-by: Jean-Michel Rouet <jean-michel.rouet@philips.com> Use more meaningful variable name Signed-off-by: Jean-Michel Rouet <jean-michel.rouet@philips.com> Update contrib/dockerd-rootless-setuptool.sh Co-authored-by: Akihiro Suda <suda.kyoto@gmail.com> Signed-off-by: Jean-Michel Rouet <jean-michel.rouet@philips.com> Use more meaningful variable name Signed-off-by: Jean-Michel Rouet <jean-michel.rouet@philips.com> Update contrib/dockerd-rootless-setuptool.sh Co-authored-by: Akihiro Suda <suda.kyoto@gmail.com> Signed-off-by: Jean-Michel Rouet <jean-michel.rouet@philips.com>
This commit is contained in:
parent
8d15e7d742
commit
2f0ba0a7e5
1 changed files with 14 additions and 7 deletions
|
@ -37,6 +37,8 @@ BIN=""
|
||||||
SYSTEMD=""
|
SYSTEMD=""
|
||||||
CFG_DIR=""
|
CFG_DIR=""
|
||||||
XDG_RUNTIME_DIR_CREATED=""
|
XDG_RUNTIME_DIR_CREATED=""
|
||||||
|
USERNAME=""
|
||||||
|
USERNAME_ESCAPED=""
|
||||||
|
|
||||||
# run checks and also initialize global vars
|
# run checks and also initialize global vars
|
||||||
init() {
|
init() {
|
||||||
|
@ -78,6 +80,11 @@ init() {
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Set USERNAME from `id -un` and potentially protect backslash
|
||||||
|
# for windbind/samba domain users
|
||||||
|
USERNAME=$(id -un)
|
||||||
|
USERNAME_ESCAPED=$(echo $USERNAME | sed 's/\\/\\\\/g')
|
||||||
|
|
||||||
# set CFG_DIR
|
# set CFG_DIR
|
||||||
CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}"
|
CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}"
|
||||||
|
|
||||||
|
@ -222,21 +229,21 @@ init() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# instructions: validate subuid/subgid files for current user
|
# instructions: validate subuid/subgid files for current user
|
||||||
if ! grep -q "^$(id -un):\|^$(id -u):" /etc/subuid 2> /dev/null; then
|
if ! grep -q "^$USERNAME_ESCAPED:\|^$(id -u):" /etc/subuid 2> /dev/null; then
|
||||||
instructions=$(
|
instructions=$(
|
||||||
cat <<- EOI
|
cat <<- EOI
|
||||||
${instructions}
|
${instructions}
|
||||||
# Add subuid entry for $(id -un)
|
# Add subuid entry for ${USERNAME}
|
||||||
echo "$(id -un):100000:65536" >> /etc/subuid
|
echo "${USERNAME}:100000:65536" >> /etc/subuid
|
||||||
EOI
|
EOI
|
||||||
)
|
)
|
||||||
fi
|
fi
|
||||||
if ! grep -q "^$(id -un):\|^$(id -u):" /etc/subgid 2> /dev/null; then
|
if ! grep -q "^$USERNAME_ESCAPED:\|^$(id -u):" /etc/subgid 2> /dev/null; then
|
||||||
instructions=$(
|
instructions=$(
|
||||||
cat <<- EOI
|
cat <<- EOI
|
||||||
${instructions}
|
${instructions}
|
||||||
# Add subgid entry for $(id -un)
|
# Add subgid entry for ${USERNAME}
|
||||||
echo "$(id -un):100000:65536" >> /etc/subgid
|
echo "${USERNAME}:100000:65536" >> /etc/subgid
|
||||||
EOI
|
EOI
|
||||||
)
|
)
|
||||||
fi
|
fi
|
||||||
|
@ -340,7 +347,7 @@ install_systemd() {
|
||||||
)
|
)
|
||||||
INFO "Installed ${SYSTEMD_UNIT} successfully."
|
INFO "Installed ${SYSTEMD_UNIT} successfully."
|
||||||
INFO "To control ${SYSTEMD_UNIT}, run: \`systemctl --user (start|stop|restart) ${SYSTEMD_UNIT}\`"
|
INFO "To control ${SYSTEMD_UNIT}, run: \`systemctl --user (start|stop|restart) ${SYSTEMD_UNIT}\`"
|
||||||
INFO "To run ${SYSTEMD_UNIT} on system startup, run: \`sudo loginctl enable-linger $(id -un)\`"
|
INFO "To run ${SYSTEMD_UNIT} on system startup, run: \`sudo loginctl enable-linger ${USERNAME}\`"
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue