From 5db964e7edc3283d7f0a0bb5f55e749743402d69 Mon Sep 17 00:00:00 2001 From: Bertho Stultiens Date: Thu, 30 Jan 2025 22:53:20 +0100 Subject: [PATCH 1/4] Fix most cd || exit problems noted by shellcheck. Also includes missing double quotes and few other simple changes. --- .../animated-backdrop/animated-backdrop.demo | 2 +- configs/apps/gladevcp/by-widget/combobox.demo | 2 +- .../by-widget/combobox_manual_list.demo | 2 +- .../apps/gladevcp/by-widget/radiobutton.demo | 2 +- .../apps/gladevcp/by-widget/sourceview.demo | 2 +- .../apps/gladevcp/by-widget/spinbutton.demo | 2 +- .../class-callback/class_callback.demo | 2 +- .../gladevcp/colored-label/coloredlabel.demo | 2 +- configs/apps/gladevcp/complex/complex.demo | 2 +- configs/apps/gladevcp/glade-manual.demo | 2 +- configs/apps/gladevcp/gladevcp-test.demo | 2 +- .../apps/gladevcp/helloWorld/helloworld.demo | 2 +- .../mdi-command-example/owordsub.demo | 2 +- .../gladevcp/mdi-command-example/speed.demo | 2 +- .../mdi-command-example/whoareyou.demo | 2 +- .../simple-callback/simple-callback.demo | 2 +- .../apps/gladevcp/templates/classhandler.demo | 2 +- .../classhandler_persistent.demo_notworking | 2 +- .../gladevcp/templates/functionhandler.demo | 2 +- configs/apps/halrun/halrun.demo | 23 ++++++----- configs/apps/xhc-hb04/xhc-hb04-layout1.demo | 2 +- configs/apps/xhc-hb04/xhc-hb04-layout2.demo | 2 +- configs/apps/xhc-hb04/xhc-hb04.demo | 2 +- configs/apps/xhc-hb04/xhc-hb04.sh | 10 ++--- .../sim/axis/gladevcp/set-param-from-ini.sh | 2 +- scripts/hal_demo | 32 +++++++++------ scripts/make-docs-pdf-index | 20 +++++---- scripts/pyvcp_demo | 41 ++++++++++--------- scripts/swish | 17 ++++---- 29 files changed, 102 insertions(+), 87 deletions(-) diff --git a/configs/apps/gladevcp/animated-backdrop/animated-backdrop.demo b/configs/apps/gladevcp/animated-backdrop/animated-backdrop.demo index 767e1fd3b32..c6192efc4d0 100755 --- a/configs/apps/gladevcp/animated-backdrop/animated-backdrop.demo +++ b/configs/apps/gladevcp/animated-backdrop/animated-backdrop.demo @@ -2,6 +2,6 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } gladevcp_demo -u ./cairodraw.py ./cairodraw.ui diff --git a/configs/apps/gladevcp/by-widget/combobox.demo b/configs/apps/gladevcp/by-widget/combobox.demo index 188ddcb2610..677a86d9bf8 100755 --- a/configs/apps/gladevcp/by-widget/combobox.demo +++ b/configs/apps/gladevcp/by-widget/combobox.demo @@ -2,6 +2,6 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } gladevcp_demo -u combobox.py combobox.ui diff --git a/configs/apps/gladevcp/by-widget/combobox_manual_list.demo b/configs/apps/gladevcp/by-widget/combobox_manual_list.demo index 7f8ddc7843f..afd51ecdccf 100755 --- a/configs/apps/gladevcp/by-widget/combobox_manual_list.demo +++ b/configs/apps/gladevcp/by-widget/combobox_manual_list.demo @@ -2,6 +2,6 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } gladevcp_demo -u ./combobox_manual_list.py ./combobox_manual_list.ui diff --git a/configs/apps/gladevcp/by-widget/radiobutton.demo b/configs/apps/gladevcp/by-widget/radiobutton.demo index 8de1bf118fb..a32d62beb5f 100755 --- a/configs/apps/gladevcp/by-widget/radiobutton.demo +++ b/configs/apps/gladevcp/by-widget/radiobutton.demo @@ -2,6 +2,6 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } gladevcp_demo -u ./radio.py ./radio.ui diff --git a/configs/apps/gladevcp/by-widget/sourceview.demo b/configs/apps/gladevcp/by-widget/sourceview.demo index 24aa5d253fe..1b136b0a768 100755 --- a/configs/apps/gladevcp/by-widget/sourceview.demo +++ b/configs/apps/gladevcp/by-widget/sourceview.demo @@ -2,6 +2,6 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } gladevcp_demo -u ./sourceview.py ./sourceview.ui diff --git a/configs/apps/gladevcp/by-widget/spinbutton.demo b/configs/apps/gladevcp/by-widget/spinbutton.demo index 2f1414a5d85..450c8b8dd9d 100755 --- a/configs/apps/gladevcp/by-widget/spinbutton.demo +++ b/configs/apps/gladevcp/by-widget/spinbutton.demo @@ -2,6 +2,6 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } gladevcp_demo -u spinbutton.py spinbutton.ui diff --git a/configs/apps/gladevcp/class-callback/class_callback.demo b/configs/apps/gladevcp/class-callback/class_callback.demo index 03121a0227b..322c261315b 100755 --- a/configs/apps/gladevcp/class-callback/class_callback.demo +++ b/configs/apps/gladevcp/class-callback/class_callback.demo @@ -2,6 +2,6 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } gladevcp_demo -u ./class_callback.py -H ./class_callback.hal ./class_callback.ui diff --git a/configs/apps/gladevcp/colored-label/coloredlabel.demo b/configs/apps/gladevcp/colored-label/coloredlabel.demo index 489198f4b2b..282dc028570 100755 --- a/configs/apps/gladevcp/colored-label/coloredlabel.demo +++ b/configs/apps/gladevcp/colored-label/coloredlabel.demo @@ -2,6 +2,6 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } gladevcp_demo -u ./coloredlabel.py -H ./coloredlabel.hal ./coloredlabel.ui diff --git a/configs/apps/gladevcp/complex/complex.demo b/configs/apps/gladevcp/complex/complex.demo index 4443609d401..180ba23c52c 100755 --- a/configs/apps/gladevcp/complex/complex.demo +++ b/configs/apps/gladevcp/complex/complex.demo @@ -2,6 +2,6 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } gladevcp_demo -u ./complex.py -H ./complex.hal ./complex.ui diff --git a/configs/apps/gladevcp/glade-manual.demo b/configs/apps/gladevcp/glade-manual.demo index 91a14eee1f1..c402750cb23 100755 --- a/configs/apps/gladevcp/glade-manual.demo +++ b/configs/apps/gladevcp/glade-manual.demo @@ -2,6 +2,6 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } gladevcp_demo ./glade-manual.ui diff --git a/configs/apps/gladevcp/gladevcp-test.demo b/configs/apps/gladevcp/gladevcp-test.demo index 4f2c4fb0918..42895631f84 100755 --- a/configs/apps/gladevcp/gladevcp-test.demo +++ b/configs/apps/gladevcp/gladevcp-test.demo @@ -2,6 +2,6 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } gladevcp_demo ./gladevcp-test.ui diff --git a/configs/apps/gladevcp/helloWorld/helloworld.demo b/configs/apps/gladevcp/helloWorld/helloworld.demo index b7e7dd447f9..34373b6ba41 100755 --- a/configs/apps/gladevcp/helloWorld/helloworld.demo +++ b/configs/apps/gladevcp/helloWorld/helloworld.demo @@ -2,6 +2,6 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } gladevcp_demo -H ./hw.hal ./hw.ui diff --git a/configs/apps/gladevcp/mdi-command-example/owordsub.demo b/configs/apps/gladevcp/mdi-command-example/owordsub.demo index cf8f2e6ba25..7aaed73a548 100755 --- a/configs/apps/gladevcp/mdi-command-example/owordsub.demo +++ b/configs/apps/gladevcp/mdi-command-example/owordsub.demo @@ -2,6 +2,6 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } gladevcp_demo ./owordsub.ui diff --git a/configs/apps/gladevcp/mdi-command-example/speed.demo b/configs/apps/gladevcp/mdi-command-example/speed.demo index 01cada7e8bd..c272c32d6e6 100755 --- a/configs/apps/gladevcp/mdi-command-example/speed.demo +++ b/configs/apps/gladevcp/mdi-command-example/speed.demo @@ -2,6 +2,6 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } gladevcp_demo ./speed.ui diff --git a/configs/apps/gladevcp/mdi-command-example/whoareyou.demo b/configs/apps/gladevcp/mdi-command-example/whoareyou.demo index b4d69e4d296..f08317c6597 100755 --- a/configs/apps/gladevcp/mdi-command-example/whoareyou.demo +++ b/configs/apps/gladevcp/mdi-command-example/whoareyou.demo @@ -2,6 +2,6 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } gladevcp_demo ./whoareyou.ui diff --git a/configs/apps/gladevcp/simple-callback/simple-callback.demo b/configs/apps/gladevcp/simple-callback/simple-callback.demo index 8a627fafce3..20ec4ce1356 100755 --- a/configs/apps/gladevcp/simple-callback/simple-callback.demo +++ b/configs/apps/gladevcp/simple-callback/simple-callback.demo @@ -2,6 +2,6 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } gladevcp_demo -u ./simplecallback.py ./simplecallback.ui diff --git a/configs/apps/gladevcp/templates/classhandler.demo b/configs/apps/gladevcp/templates/classhandler.demo index ea800f6bd4a..bb0cb66f836 100755 --- a/configs/apps/gladevcp/templates/classhandler.demo +++ b/configs/apps/gladevcp/templates/classhandler.demo @@ -2,6 +2,6 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } gladevcp_demo -u ./classhandler.py ./button.ui diff --git a/configs/apps/gladevcp/templates/classhandler_persistent.demo_notworking b/configs/apps/gladevcp/templates/classhandler_persistent.demo_notworking index bd27c7fa5bb..5b3cdde88bd 100755 --- a/configs/apps/gladevcp/templates/classhandler_persistent.demo_notworking +++ b/configs/apps/gladevcp/templates/classhandler_persistent.demo_notworking @@ -2,6 +2,6 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } gladevcp_demo -u ./classhandler_persistent.py -U debug=2 -U "print 'debug=%d' % debug" ./button.ui diff --git a/configs/apps/gladevcp/templates/functionhandler.demo b/configs/apps/gladevcp/templates/functionhandler.demo index 17ab3158bff..bb613484231 100755 --- a/configs/apps/gladevcp/templates/functionhandler.demo +++ b/configs/apps/gladevcp/templates/functionhandler.demo @@ -2,6 +2,6 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } gladevcp_demo -u ./functionhandler.py ./button.ui diff --git a/configs/apps/halrun/halrun.demo b/configs/apps/halrun/halrun.demo index 09101691590..fdc876a2642 100755 --- a/configs/apps/halrun/halrun.demo +++ b/configs/apps/halrun/halrun.demo @@ -1,11 +1,12 @@ #!/bin/bash -prog=$(basename $0) +prog=$(basename "$0") thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") HALFILE="$thisdir"/help.hal -cd ;# so user can use halcmd 'save' to create a file +# Don't care if cd succeeds. Just so user can use halcmd 'save' to create a file in $HOME +cd || true function popup () { msg="$*" @@ -21,9 +22,9 @@ EOF } ;# popup -[ X"$TERM" = Xdumb ] && TERM=xterm -[ -x "$(which $COLORTERM)" ] && TERM=$COLORTERM -[ -z $TERM ] && TERM=xterm +[ "$TERM" = "dumb" ] && TERM=xterm +[ -x "$(which "$COLORTERM")" ] && TERM=$COLORTERM +[ -z "$TERM" ] && TERM=xterm # wip: xterm is well-behaved, some other terminals are not # for now: force to xterm @@ -33,11 +34,11 @@ REALTIME=$(linuxcnc_var REALTIME) # make sure TERM uses the expected halrun (rip or install) HALRUN=$(which halrun) -if [ ! -z "$debug" ] ; then - echo COLORTERM=$COLORTERM - echo TERM=$TERM - echo HALRUN=$HALRUN - echo REALTIME=$REALTIME +if [ -n "$debug" ] ; then + echo "COLORTERM=$COLORTERM" + echo "TERM=$TERM" + echo "HALRUN=$HALRUN" + echo "REALTIME=$REALTIME" fi if $REALTIME status >/dev/null ; then @@ -51,7 +52,7 @@ fi # terminate any other halrun instance: $HALRUN -U >/dev/null 2>&1 -if [ X"$TERM" = Xxterm ] ; then +if [ "$TERM" = "xterm" ] ; then $TERM -geometry 80x40 \ -sb \ -fg black -bg ivory2 \ diff --git a/configs/apps/xhc-hb04/xhc-hb04-layout1.demo b/configs/apps/xhc-hb04/xhc-hb04-layout1.demo index 8aa55a203f0..63841fcd3eb 100755 --- a/configs/apps/xhc-hb04/xhc-hb04-layout1.demo +++ b/configs/apps/xhc-hb04/xhc-hb04-layout1.demo @@ -2,6 +2,6 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } ./xhc-hb04.sh layout1 diff --git a/configs/apps/xhc-hb04/xhc-hb04-layout2.demo b/configs/apps/xhc-hb04/xhc-hb04-layout2.demo index f5c4ef638d8..6371ad5905b 100755 --- a/configs/apps/xhc-hb04/xhc-hb04-layout2.demo +++ b/configs/apps/xhc-hb04/xhc-hb04-layout2.demo @@ -2,6 +2,6 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } ./xhc-hb04.sh layout2 diff --git a/configs/apps/xhc-hb04/xhc-hb04.demo b/configs/apps/xhc-hb04/xhc-hb04.demo index 594b43475c5..e890bb7c76d 100755 --- a/configs/apps/xhc-hb04/xhc-hb04.demo +++ b/configs/apps/xhc-hb04/xhc-hb04.demo @@ -2,7 +2,7 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } # use default layout ./xhc-hb04.sh diff --git a/configs/apps/xhc-hb04/xhc-hb04.sh b/configs/apps/xhc-hb04/xhc-hb04.sh index cadabe41c20..347655a5ea6 100755 --- a/configs/apps/xhc-hb04/xhc-hb04.sh +++ b/configs/apps/xhc-hb04/xhc-hb04.sh @@ -2,14 +2,14 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" +cd "$thisdir" || exit LAYOUT=${1:-""} -[ -x "$(which $COLORTERM)" ] && TERM=$COLORTERM -[ -z $TERM ] && TERM=xterm +[ -x "$(which "$COLORTERM")" ] && TERM="$COLORTERM" +[ -z "$TERM" ] && TERM=xterm # when invoked from Application menu and RIP, may have TERM=dumb -[ x"$TERM" = xdumb ] && TERM=xterm +[ "$TERM" = "dumb" ] && TERM=xterm XHC_HB04=$(which xhc-hb04) HALLIB_DIR=$(linuxcnc_var HALLIB_DIR) @@ -20,7 +20,7 @@ case $LAYOUT in esac dashI="-I $CFG" -if [ ! -z "$debug" ] ; then +if [ -n "$debug" ] ; then echo "COLORTERM=$COLORTERM" echo "TERM=$TERM" echo "XHC_HB04=$XHC_HB04" diff --git a/configs/sim/axis/gladevcp/set-param-from-ini.sh b/configs/sim/axis/gladevcp/set-param-from-ini.sh index d9277f82f82..03604e10f5f 100755 --- a/configs/sim/axis/gladevcp/set-param-from-ini.sh +++ b/configs/sim/axis/gladevcp/set-param-from-ini.sh @@ -1,6 +1,6 @@ #!/bin/bash -cd $(dirname $::argv0) +cd "$(dirname "$0")" || { echo "E: Could not change directory to '$(dirname "$0")'"; exit 1; } gladevcp -u ./meter_scale.py ./meter_scale.ui & diff --git a/scripts/hal_demo b/scripts/hal_demo index d043eb78535..6591d65a2e5 100755 --- a/scripts/hal_demo +++ b/scripts/hal_demo @@ -18,7 +18,7 @@ # # Copyright (c) 2004-2009 All rights reserved. #*******************************************************************/ -if [ ! $1 ] ; then +if [ -z "$1" ] ; then echo "Usage: scripts/hal_demo " echo "Run from the emc2 directory only" # print the list of demos @@ -28,7 +28,7 @@ fi # # the first demo isn't a real demo - it simply lists all the demos # -if [ $1 = list ] ; then +if [ "$1" = "list" ] ; then echo "Available demos are:" echo " list - prints this list" echo " load - loads hal core modules" @@ -44,10 +44,10 @@ fi # # here is the "load" command # -if [ $1 = load ] ; then +if [ "$1" = "load" ] ; then # load the rtos and rtapi if ! scripts/realtime start ; then - exit -1 + exit 1 fi # done echo "RTAPI core loaded" @@ -56,12 +56,12 @@ fi # # here is the "unload" command # -if [ $1 = unload ] ; then +if [ "$1" = "unload" ] ; then # unload any left-over modules bin/halcmd unloadrt all # unload the rtos and rtapi if ! scripts/realtime stop ; then - exit -1 + exit 1 fi # done echo "RTAPI core unloaded" @@ -71,17 +71,19 @@ fi # We're almost ready for the real demos, first we must # make sure the rtapi core is loaded # -HAL_LIB_STR=`/sbin/lsmod | awk '{print $1}' | grep -x hal_lib ` -if [ ! "$HAL_LIB_STR" ] ; then +HAL_LIB_STR=$(/sbin/lsmod | awk '{print $1}' | grep -x hal_lib) +if [ -z "$HAL_LIB_STR" ] ; then echo "All of the demos require the RTAPI and HAL_LIB modules" echo "to be loaded. Use 'hal_demo load' to load them." - exit -1 + exit 1 fi # # The first demo: "parport1" simply tests the parallel port # this one is a step by step, tutorial/intro to HAL concepts # -if [ $1 = parport1 ] ; then +# Don't care about read mangling backslashes, nothing read is used +# shellcheck disable=SC2162 +if [ "$1" = "parport1" ] ; then echo "(Comments that are part of the demo are in parenthesis.)" echo "(This demo echos its commands to the screen so you can" echo " see what each step does. Echoed commands start with '$')" @@ -206,7 +208,9 @@ fi # and halmeter. # this one is also a step by step tutorial # -if [ $1 = siggen ] ; then +# Don't care about read mangling backslashes, nothing read is used +# shellcheck disable=SC2162 +if [ "$1" = "siggen" ] ; then echo "(Comments that are part of the demo are in parenthesis.)" echo "(This demo echos its commands to the screen so you can" echo " see what each step does. Echoed commands start with '$')" @@ -288,7 +292,9 @@ fi # using siggen as a signal source. # this one is also a step by step tutorial # -if [ $1 = scope ] ; then +# Don't care about read mangling backslashes, nothing read is used +# shellcheck disable=SC2162 +if [ "$1" = "scope" ] ; then echo "The first part of this demo is identical to the siggen" echo "demo. Hit enter to get started" read @@ -400,5 +406,5 @@ fi # echo "Sorry, there is no demo called '$1'" scripts/hal_demo -exit -1 +exit 1 diff --git a/scripts/make-docs-pdf-index b/scripts/make-docs-pdf-index index 177be4062b1..8037bc3e093 100755 --- a/scripts/make-docs-pdf-index +++ b/scripts/make-docs-pdf-index @@ -9,19 +9,23 @@ set -e # --show-toplevel` because when building from dsc we don't have a # git repo. TOPLEVEL=${PWD}/.. -cd ${TOPLEVEL}/docs +cd "${TOPLEVEL}"/docs -TITLE="LinuxCNC PDF docs ($(cat ${TOPLEVEL}/VERSION))" +TITLE="LinuxCNC PDF docs ($(cat "${TOPLEVEL}"/VERSION))" rm -f index.html -echo "" >> index.html -echo "${TITLE}" >> index.html -echo "

${TITLE}

" >> index.html +{ + echo "" + echo "${TITLE}" + echo "

${TITLE}

" +} >> index.html -for F in $(ls -1 *.pdf | sort); do +for F in $(ls -1 ./*.pdf | sort); do echo " $F
" >> index.html done -echo "" >> index.html -echo "" >> index.html +{ + echo "" + echo "" +} >> index.html diff --git a/scripts/pyvcp_demo b/scripts/pyvcp_demo index 6c43c299156..1fab35e347a 100755 --- a/scripts/pyvcp_demo +++ b/scripts/pyvcp_demo @@ -22,7 +22,7 @@ # 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. -prog=$(basename $0) +prog=$(basename "$0") function usage () { cat </dev/null status=$? -if [ $status = 0 ] ; then +if [ "$status" = 0 ] ; then msg="$prog: Realtime is already active" echo "$msg" popup "$msg" @@ -74,16 +74,18 @@ case $# in *) usage;; esac -if [ ! -z "$debug" ] ; then - echo debug=$debug - echo REALTIME=$REALTIME - echo XMLFILE=$XMLFILE - echo HALFILE=$HALFILE - echo COMPNAME=$COMPNAME +if [ -n "$debug" ] ; then + echo "debug=$debug" + echo "REALTIME=$REALTIME" + echo "XMLFILE=$XMLFILE" + echo "HALFILE=$HALFILE" + echo "COMPNAME=$COMPNAME" fi -cd $(dirname "$XMLFILE") ;# to allow relative includes -pyvcp -c $COMPNAME $XMLFILE & +# to allow relative includes +cd "$(dirname "$XMLFILE")" || { echo "E: Could not change directory to '$(dirname "$XMLFILE")'"; exit 1; } + +pyvcp -c "$COMPNAME" "$XMLFILE" & pyvcpjob=$! ct=0 # wait for pins to be created before creating signals @@ -91,7 +93,7 @@ while true ; do halcmd show|grep "${COMPNAME}.*ready" >/dev/null 2>&1 status=$? sleep 1 - if [ $status == 0 ] ; then + if [ "$status" = 0 ] ; then #echo "ready after ct=$ct" break fi @@ -99,24 +101,25 @@ while true ; do echo "$0: hal-pyvcp startup failed" exit 1 fi - ct=$(($ct+1)) + ct=$((ct + 1)) done -cd $(dirname "$HALFILE") ;# so HALFILE can source relative files +# so HALFILE can source relative files +cd "$(dirname "$HALFILE")" || { echo "E: Could not change directory to '$(dirname "$HALFILE")'"; exit 1; } halmsg=/tmp/pyvcp_demo_halcmd.err ->|$halmsg -halcmd -f $HALFILE >$halmsg 2>&1 +true >| "$halmsg" +halcmd -f "$HALFILE" > "$halmsg" 2>&1 halstatus=$? -if [ $halstatus != 0 ] ; then +if [ "$halstatus" != 0 ] ; then IFS=$'\n' # split lines newmsg= # put extra blank line between lines of output - for line in $(cat $halmsg) ; do -newmsg="$newmsg + while read -r line; do + newmsg="$newmsg $line " - done + done < "$halmsg" popup "$newmsg" kill $pyvcpjob halrun -U diff --git a/scripts/swish b/scripts/swish index 59037dc5cd6..ac37748f3d3 100755 --- a/scripts/swish +++ b/scripts/swish @@ -11,10 +11,11 @@ fi case "$0" in */*) MYDIR="${0%/*}" ;; - *) MYDIR="`type -path $0`"; MYDIR="${MYDIR%/*}" + *) MYDIR="$(type -path "$0")"; MYDIR="${MYDIR%/*}" esac -SRCDIR=$(cd "$MYDIR/../src"; pwd) +SRCDIR=$(realpath "$MYDIR/../src") +[ -d "$SRCDIR" ] || { echo "E: Cannot find directory '$SRCDIR'."; exit 1; } SWISHINDEX="$SRCDIR/.swishindex" function makerelative () { @@ -64,7 +65,7 @@ EOF exit 1 } -FORCEREBUILD="" +FORCEREBUILD=0 while getopts "hRF:" opt do case "$opt" in @@ -73,9 +74,9 @@ do h|?) usage ;; esac done -shift $(($OPTIND-1)) +shift $((OPTIND - 1)) -if [ "$FORCEREBUILD" -o ! -f "$SWISHINDEX" ] +if [ "$FORCEREBUILD" -eq 1 ] || [ ! -f "$SWISHINDEX" ] then make -C "$SRCDIR" swish || exit $? if [ $# -eq 0 ]; then exit 0; fi @@ -88,12 +89,12 @@ else REGEXP="$1" fi -if ! [ -z "$FILEFILTER" ]; then - swish-e -f $SWISHINDEX -H0 -x '\0' -w "$PAT" \ +if [ -n "$FILEFILTER" ]; then + swish-e -f "$SWISHINDEX" -H0 -x '\0' -w "$PAT" \ | $FILEFILTER | makerelative \ | xargs -0 grep -E -Hnis -e "$REGEXP" else - swish-e -f $SWISHINDEX -H0 -x '\0' -w "$PAT" \ + swish-e -f "$SWISHINDEX" -H0 -x '\0' -w "$PAT" \ | makerelative \ | xargs -0 grep -E -Hnis -e "$REGEXP" fi From eec772f1d40c77402accea0686e6d3dc7dfc66af Mon Sep 17 00:00:00 2001 From: Bertho Stultiens Date: Fri, 31 Jan 2025 12:31:07 +0100 Subject: [PATCH 2/4] Print message before exit on cd fail. --- configs/apps/xhc-hb04/xhc-hb04.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/apps/xhc-hb04/xhc-hb04.sh b/configs/apps/xhc-hb04/xhc-hb04.sh index 347655a5ea6..ca17bb73cb0 100755 --- a/configs/apps/xhc-hb04/xhc-hb04.sh +++ b/configs/apps/xhc-hb04/xhc-hb04.sh @@ -2,7 +2,7 @@ thisfile=$(readlink -f "$0") thisdir=$(dirname "$thisfile") -cd "$thisdir" || exit +cd "$thisdir" || { echo "E: Could not change directory to '$thisdir'"; exit 1; } LAYOUT=${1:-""} From 7439f102f5135623a051c03ed8c0dcd04d2d5716 Mon Sep 17 00:00:00 2001 From: Bertho Stultiens Date: Fri, 31 Jan 2025 12:33:14 +0100 Subject: [PATCH 3/4] Remove superfluous (noclobber) file truncate. File will be overwritten anyway. --- scripts/pyvcp_demo | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/pyvcp_demo b/scripts/pyvcp_demo index 1fab35e347a..febb7295b24 100755 --- a/scripts/pyvcp_demo +++ b/scripts/pyvcp_demo @@ -108,7 +108,6 @@ done cd "$(dirname "$HALFILE")" || { echo "E: Could not change directory to '$(dirname "$HALFILE")'"; exit 1; } halmsg=/tmp/pyvcp_demo_halcmd.err -true >| "$halmsg" halcmd -f "$HALFILE" > "$halmsg" 2>&1 halstatus=$? if [ "$halstatus" != 0 ] ; then From 2d257a1395c05818a1ed881f6f3885894dd4cca0 Mon Sep 17 00:00:00 2001 From: Bertho Stultiens Date: Sun, 2 Feb 2025 15:56:44 +0100 Subject: [PATCH 4/4] Redirect to file even if noclobber is set. --- scripts/pyvcp_demo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pyvcp_demo b/scripts/pyvcp_demo index febb7295b24..5505914b615 100755 --- a/scripts/pyvcp_demo +++ b/scripts/pyvcp_demo @@ -108,7 +108,7 @@ done cd "$(dirname "$HALFILE")" || { echo "E: Could not change directory to '$(dirname "$HALFILE")'"; exit 1; } halmsg=/tmp/pyvcp_demo_halcmd.err -halcmd -f "$HALFILE" > "$halmsg" 2>&1 +halcmd -f "$HALFILE" >| "$halmsg" 2>&1 halstatus=$? if [ "$halstatus" != 0 ] ; then IFS=$'\n' # split lines