Fix indentation in %sysusers_create_compat macro (rhbz#2132835)

Automatic unindentation after <<-EOF only works with tabs. Jesus.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-10-09 15:12:53 +02:00
parent b2ad8fb38b
commit 3c5b26ff79

View File

@ -1,92 +1,93 @@
#!/bin/bash #!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: true; tab-width: 4; -*-
# This script turns sysuser.d files into scriptlets mandated by Fedora # This script turns sysuser.d files into scriptlets mandated by Fedora
# packaging guidelines. The general idea is to define users using the # packaging guidelines. The general idea is to define users using the
# declarative syntax but to turn this into traditional scriptlets. # declarative syntax but to turn this into traditional scriptlets.
user() { user() {
user="$1" user="$1"
uid="$2" uid="$2"
desc="$3" desc="$3"
group="$4" group="$4"
home="$5" home="$5"
shell="$6" shell="$6"
[ "$desc" = '-' ] && desc= [ "$desc" = '-' ] && desc=
{ [ "$home" = '-' ] || [ "$home" = '' ]; } && home=/ { [ "$home" = '-' ] || [ "$home" = '' ]; } && home=/
{ [ "$shell" = '-' ] || [ "$shell" = '' ]; } && shell=/usr/sbin/nologin { [ "$shell" = '-' ] || [ "$shell" = '' ]; } && shell=/usr/sbin/nologin
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' -d '$home' -s '$shell' -c '$desc' '$user' || :
EOF EOF
else else
cat <<EOF cat <<-EOF
if ! getent passwd '$user' >/dev/null; then if ! getent passwd '$user' >/dev/null; then
if ! getent passwd '$uid' >/dev/null; then if ! getent passwd '$uid' >/dev/null; then
useradd -r -u '$uid' -g '$group' -d '$home' -s '$shell' -c '$desc' '$user' || : useradd -r -u '$uid' -g '$group' -d '$home' -s '$shell' -c '$desc' '$user' || :
else else
useradd -r -g '$group' -d '$home' -s '$shell' -c '$desc' '$user' || : useradd -r -g '$group' -d '$home' -s '$shell' -c '$desc' '$user' || :
fi fi
fi fi
EOF EOF
fi fi
} }
group() { group() {
group="$1" group="$1"
gid="$2" gid="$2"
if [ "$gid" = '-' ]; then if [ "$gid" = '-' ]; then
cat <<-EOF cat <<-EOF
getent group '$group' >/dev/null || groupadd -r '$group' || : getent group '$group' >/dev/null || groupadd -r '$group' || :
EOF EOF
else else
cat <<-EOF cat <<-EOF
getent group '$group' >/dev/null || groupadd -f -g '$gid' -r '$group' || : getent group '$group' >/dev/null || groupadd -f -g '$gid' -r '$group' || :
EOF EOF
fi fi
} }
usermod() { usermod() {
user="$1" user="$1"
group="$2" group="$2"
cat <<-EOF cat <<-EOF
if getent group '$group' >/dev/null; then if getent group '$group' >/dev/null; then
usermod -a -G '$group' '$user' || : usermod -a -G '$group' '$user' || :
fi fi
EOF EOF
} }
parse() { parse() {
while read -r line || [ -n "$line" ] ; do while read -r line || [ -n "$line" ] ; do
{ [ "${line:0:1}" = '#' ] || [ "${line:0:1}" = ';' ]; } && continue { [ "${line:0:1}" = '#' ] || [ "${line:0:1}" = ';' ]; } && continue
line="${line## *}" line="${line## *}"
[ -z "$line" ] && continue [ -z "$line" ] && continue
eval "arr=( $line )" eval "arr=( $line )"
case "${arr[0]}" in case "${arr[0]}" in
('u') ('u')
group "${arr[1]}" "${arr[2]}" group "${arr[1]}" "${arr[2]}"
user "${arr[1]}" "${arr[2]}" "${arr[3]}" "${arr[1]}" "${arr[4]}" "${arr[5]}" user "${arr[1]}" "${arr[2]}" "${arr[3]}" "${arr[1]}" "${arr[4]}" "${arr[5]}"
# TODO: user:group support # TODO: user:group support
;; ;;
('g') ('g')
group "${arr[1]}" "${arr[2]}" group "${arr[1]}" "${arr[2]}"
;; ;;
('m') ('m')
group "${arr[2]}" "-" group "${arr[2]}" "-"
user "${arr[1]}" "-" "" "${arr[1]}" "" "" user "${arr[1]}" "-" "" "${arr[1]}" "" ""
usermod "${arr[1]}" "${arr[2]}" usermod "${arr[1]}" "${arr[2]}"
;; ;;
esac esac
done done
} }
for fn in "$@"; do for fn in "$@"; do
[ -e "$fn" ] || continue [ -e "$fn" ] || continue
echo "# generated from $(basename "$fn")" echo "# generated from $(basename "$fn")"
parse <"$fn" parse <"$fn"
done done