From 150ab76174394b430d4ba1c5eb0a9d7f847db6ff Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Sun, 16 Jul 2023 01:39:03 +1200 Subject: [PATCH] Make shell scripts cleaner for shellcheck --- ChangeLog | 2 ++ bin/mythtv-update-motd | 10 +++++----- bin/mythtv_recording_now | 2 +- bin/mythtv_recording_soon | 2 +- molly-guard/40-mythtv-recording-soon | 18 ++++++++++++------ 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index db8a145..6b368f0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ Include my Makefile in the tarball, this allows using "make install" to install mythtv-status. + Make all shell scripts much clenaer according to shellcheck. + Refresh URLs in FAQ, update libmythtv-perl package name. Remove obsolete question/answer from FAQ as my patch for improving storage diff --git a/bin/mythtv-update-motd b/bin/mythtv-update-motd index fce90c6..7f613f1 100755 --- a/bin/mythtv-update-motd +++ b/bin/mythtv-update-motd @@ -16,9 +16,9 @@ NAME=mythtv-update-motd [ -r /etc/sysconfig/mythtv-status ] && . /etc/sysconfig/mythtv-status # Support the old RUN variable -[ x$UPDATE_MOTD = x ] && UPDATE_MOTD=$RUN +[ "$UPDATE_MOTD" = "" ] && UPDATE_MOTD=$RUN -if [ x$UPDATE_MOTD != xyes -o -f /var/lib/mythtv-status/motd_update_disabled ] +if [ "$UPDATE_MOTD" != "yes" ] || [ -f /var/lib/mythtv-status/motd_update_disabled ] then exit fi @@ -49,7 +49,7 @@ else DISTRO='unknown' fi - if [ $DISTRO = 'fedora' ] + if [ "$DISTRO" = 'fedora' ] then WORKFILE=/etc/motd STUBFILE=/etc/motd.stub @@ -79,11 +79,11 @@ else fi # Support the old ARGS variable -[ x$UPDATE_MOTD_ARGS = x ] && UPDATE_MOTD_ARGS=$ARGS +[ "$UPDATE_MOTD_ARGS" = "" ] && UPDATE_MOTD_ARGS=$ARGS ret=0 mythtv-status $UPDATE_MOTD_ARGS -h $HOST >> $TEMPFILE || ret=$? -if [ $ret -eq 0 -o $ret -eq 1 ]; then +if [ $ret -eq 0 ] || [ $ret -eq 1 ]; then if [ ! -f $TEMPFILE ]; then echo My temporary file has gone away, failed. exit 1 diff --git a/bin/mythtv_recording_now b/bin/mythtv_recording_now index d321029..ebff386 100755 --- a/bin/mythtv_recording_now +++ b/bin/mythtv_recording_now @@ -15,7 +15,7 @@ then . /etc/default/mythtv-status fi -/usr/bin/mythtv-status -h ${HOST:=localhost} --return-code-only --recording-now +/usr/bin/mythtv-status -h "${HOST:=localhost}" --return-code-only --recording-now if [ $? -eq 1 ] then diff --git a/bin/mythtv_recording_soon b/bin/mythtv_recording_soon index d92d889..44d4abb 100755 --- a/bin/mythtv_recording_soon +++ b/bin/mythtv_recording_soon @@ -22,7 +22,7 @@ else ARGS="--recording-in-warn 600" fi -/usr/bin/mythtv-status -h ${HOST:=localhost} --return-code-only \ +/usr/bin/mythtv-status -h "${HOST:=localhost}" --return-code-only \ --recording-now --next-recording $ARGS if [ $? -eq 1 ] diff --git a/molly-guard/40-mythtv-recording-soon b/molly-guard/40-mythtv-recording-soon index d241dd8..09a3506 100755 --- a/molly-guard/40-mythtv-recording-soon +++ b/molly-guard/40-mythtv-recording-soon @@ -1,10 +1,16 @@ #!/bin/sh +# Copyright (c) 2008-2023 Andrew Ruthven +# This code is hereby licensed for public consumption under the GNU GPL v3. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ME=molly-guard if [ ! -f /usr/bin/mythtv_recording_soon ]; then - echo "I: I can't find /usr/bin/mythtv_recording_soon, skipping check" >&2 - exit 0; + echo "I: $ME: I can't find /usr/bin/mythtv_recording_soon, skipping check" >&2 + exit 0 fi HOSTNAME="$(hostname --short)" @@ -17,13 +23,13 @@ sigh() if /usr/bin/mythtv_recording_soon; then - trap 'echo;sigh' 1 2 3 9 10 12 15 - echo -n "MythTV is either recording now, or will be soon. Type YES to $MOLLYGUARD_CMD: " + trap 'echo;sigh' 1 2 3 10 12 15 + printf "MythTV is either recording now, or will be soon. Type YES to %s: " "$MOLLYGUARD_CMD" read CONFIRM || : - [ $(echo "x$CONFIRM" | tr 'A-Z' 'a-z') = "xyes" ] || sigh + [ "$(echo "$CONFIRM" | tr 'A-Z' 'a-z')" = "yes" ] || sigh - trap - 1 2 3 9 10 12 15 + trap - 1 2 3 10 12 15 fi exit 0 -- 2.30.2