From: Michael Marley Date: Fri, 2 Feb 2024 16:42:16 +0000 (-0500) Subject: Clean up Debian postinst and postrm scripts X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b225e4d6ccb966824f453aeabbd311799d24b471;p=thirdparty%2Ftvheadend.git Clean up Debian postinst and postrm scripts - Fix indentation - Remove unnecessary {} around variables - Double-quote all variables when assigned or used as arguments - Simplify quotes and escaping in creation of the superuser file - Remove needless variable assignments - Use $() for command substitution instead of `` --- diff --git a/debian/tvheadend.postinst b/debian/tvheadend.postinst index cdda7b9b0..eff115c9d 100644 --- a/debian/tvheadend.postinst +++ b/debian/tvheadend.postinst @@ -1,51 +1,50 @@ #!/bin/sh -e -HTS_USER=hts +HTS_USER="hts" . /usr/share/debconf/confmodule db_version 2.0 case "$1" in configure) - - if ! getent passwd $HTS_USER >/dev/null; then + if ! getent passwd "$HTS_USER" >/dev/null; then echo >&2 "Creating user: $HTS_USER..." - adduser --quiet --system --group --home /var/lib/tvheadend $HTS_USER - fi + adduser --quiet --system --group --home /var/lib/tvheadend "$HTS_USER" + fi - HTS_HOMEDIR=`getent passwd $HTS_USER | cut -d':' -f6` + HTS_HOMEDIR="$(getent passwd "$HTS_USER" | cut -d':' -f6)" - # Handle previous configuration directory: If the HTS_USER home directory - # starts with /home/, append "/.hts/tvheadend" so the superuser - # configuration will go in the right place. - if [ -z "${HTS_HOMEDIR##/home/*}" ]; then + # Handle previous configuration directory: If the HTS_USER home directory + # starts with /home/, append "/.hts/tvheadend" so the superuser + # configuration will go in the right place. + if [ -z "${HTS_HOMEDIR##/home/*}" ]; then HTS_CONFDIR="$HTS_HOMEDIR/.hts/tvheadend" echo >&2 "Legacy configuration directory $HTS_CONFDIR is in use." - install -d -g ${HTS_USER} -o ${HTS_USER} "${HTS_CONFDIR}" - else + install -d -g "$HTS_USER" -o "$HTS_USER" "$HTS_CONFDIR" + else HTS_CONFDIR="$HTS_HOMEDIR" - fi + fi - install -d -g ${HTS_USER} -o ${HTS_USER} "${HTS_HOMEDIR}/recordings" + install -d -g "$HTS_USER" -o "$HTS_USER" "$HTS_HOMEDIR/recordings" - HTS_SUPERUSERCONF="${HTS_CONFDIR}/superuser" - rm -f "${HTS_SUPERUSERCONF}" - touch "${HTS_SUPERUSERCONF}" - chmod 600 "${HTS_SUPERUSERCONF}" - chown ${HTS_USER}:${HTS_USER} "${HTS_SUPERUSERCONF}" + HTS_SUPERUSERCONF="${HTS_CONFDIR}/superuser" + rm -f "$HTS_SUPERUSERCONF" + touch "$HTS_SUPERUSERCONF" + chmod 600 "$HTS_SUPERUSERCONF" + chown "$HTS_USER":"$HTS_USER" "$HTS_SUPERUSERCONF" - echo >>"${HTS_SUPERUSERCONF}" "{" + echo >>"$HTS_SUPERUSERCONF" "{" - if db_get tvheadend/admin_username; then - echo >>"${HTS_SUPERUSERCONF}" '"username": "'$RET'",' - fi + if db_get tvheadend/admin_username; then + echo >>"$HTS_SUPERUSERCONF" "\"username\": \"$RET\"," + fi - if db_get tvheadend/admin_password; then - echo >>"${HTS_SUPERUSERCONF}" '"password": "'$RET'"' - fi + if db_get tvheadend/admin_password; then + echo >>"$HTS_SUPERUSERCONF" "\"password\": \"$RET\"" + fi - echo >>"${HTS_SUPERUSERCONF}" "}" - ;; + echo >>"$HTS_SUPERUSERCONF" "}" + ;; esac db_stop diff --git a/debian/tvheadend.postrm b/debian/tvheadend.postrm index 39af2a423..271bf1a11 100644 --- a/debian/tvheadend.postrm +++ b/debian/tvheadend.postrm @@ -1,15 +1,14 @@ #!/bin/sh -e -HTS_USER=hts +HTS_USER="hts" . /usr/share/debconf/confmodule db_version 2.0 case "$1" in purge) - if getent passwd $HTS_USER >/dev/null; then - HTS_HOME=`getent passwd $HTS_USER | cut -d':' -f6` - rm -rf "${HTS_HOME}" + if getent passwd "$HTS_USER" >/dev/null; then + rm -rf "$(getent passwd "$HTS_USER" | cut -d':' -f6)" fi db_purge ;;