sysusers.generate-pre.sh: properly escape quotes in description strings

... (rhbz#2104141)

In the first version, I wanted to use POSIX quotes with $''. But that required
'printf %q', which brings in a dependency on coreutils.

Following mcr0mmand's suggestion, ${foo@Q} is used instead, which should work
equivalently, and does not require anything new.

Tested with 'sysusers.generate-pre.sh /usr/lib/sysusers.d/*conf'. The output is
the same before and after, apart from the dovecot user with a quote.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2023-04-26 09:52:35 +02:00
parent ef79df9490
commit 7e62bd0762

View File

@ -20,15 +20,15 @@ user() {
if [ "$uid" = '-' ] || [ "$uid" = '' ]; then if [ "$uid" = '-' ] || [ "$uid" = '' ]; then
cat <<-EOF cat <<-EOF
getent passwd '$user' >/dev/null || \\ getent passwd '$user' >/dev/null || \\
useradd -r -g '$group' -d '$home' -s '$shell' -c '$desc' '$user' || : useradd -r -g ${group@Q} -d ${home@Q} -s ${shell@Q} -c ${desc@Q} ${user@Q} || :
EOF EOF
else else
cat <<-EOF cat <<-EOF
if ! getent passwd '$user' >/dev/null; then if ! getent passwd ${user@Q} >/dev/null; then
if ! getent passwd '$uid' >/dev/null; then if ! getent passwd ${uid@Q} >/dev/null; then
useradd -r -u '$uid' -g '$group' -d '$home' -s '$shell' -c '$desc' '$user' || : useradd -r -u ${uid@Q} -g ${group@Q} -d ${home@Q} -s ${shell@Q} -c ${desc@Q} ${user@Q} || :
else else
useradd -r -g '$group' -d '$home' -s '$shell' -c '$desc' '$user' || : useradd -r -g ${group@Q} -d ${home@Q} -s ${shell@Q} -c ${desc@Q} ${user@Q} || :
fi fi
fi fi
@ -42,11 +42,11 @@ group() {
if [ "$gid" = '-' ]; then if [ "$gid" = '-' ]; then
cat <<-EOF cat <<-EOF
getent group '$group' >/dev/null || groupadd -r '$group' || : getent group ${group@Q} >/dev/null || groupadd -r ${group@Q} || :
EOF EOF
else else
cat <<-EOF cat <<-EOF
getent group '$group' >/dev/null || groupadd -f -g '$gid' -r '$group' || : getent group ${group@Q} >/dev/null || groupadd -f -g ${gid@Q} -r ${group@Q} || :
EOF EOF
fi fi
} }
@ -56,8 +56,8 @@ usermod() {
group="$2" group="$2"
cat <<-EOF cat <<-EOF
if getent group '$group' >/dev/null; then if getent group ${group@Q} >/dev/null; then
usermod -a -G '$group' '$user' || : usermod -a -G ${group@Q} '$user' || :
fi fi
EOF EOF
} }