From f877b9f4c31cbb2c335c6b37411d75653bb66cb8 Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Sat, 10 Jun 2023 12:14:13 +0100 Subject: [PATCH] Run shellcheck on script files Run using: for file in $(find . -not \( -path ./subprojects -prune \) -name "*.sh") do realfile=$(realpath "$file") shellcheck --norc --format=diff --shell sh --enable=add-default-case,avoid-nullary-conditions,check-unassigned-uppercase,deprecate-which,quote-safe-variables "$realfile"| patch "$realfile" done exit Plus manual edits. --- geeqie-install-debian.sh | 22 ++++----- gen_changelog.sh | 3 +- .../geeqie-camera-import-hook-script | 1 + plugins/image-crop/geeqie-image-crop | 2 +- plugins/rotate/geeqie-rotate | 49 +++++++++++-------- plugins/symlink/geeqie-symlink | 4 +- .../geeqie-tethered-photography | 2 +- .../geeqie-tethered-photography-hook-script | 1 + po/regen_potfiles.sh | 10 ++-- scripts/generate-linuxdeploy-for-arm.sh | 8 +-- scripts/keyword_merge.sh | 8 +-- scripts/new-release.sh | 10 +--- version.sh | 2 +- 13 files changed, 62 insertions(+), 60 deletions(-) diff --git a/geeqie-install-debian.sh b/geeqie-install-debian.sh index 5e9c589d..eaf00c9b 100755 --- a/geeqie-install-debian.sh +++ b/geeqie-install-debian.sh @@ -156,8 +156,8 @@ systemProfile() then DIST="${DIST}[$(tr "\n" ' ' < /etc/UnitedLinux-release | sed s/VERSION.*//)]" fi - OS=$(lowercase $OS) - DistroBasedOn=$(lowercase $DistroBasedOn) + OS=$(lowercase "$OS") + DistroBasedOn=$(lowercase "$DistroBasedOn") readonly OS readonly DIST readonly DistroBasedOn @@ -244,7 +244,7 @@ package_query() status=0 fi fi - return $status + return "$status" } package_install() @@ -343,7 +343,7 @@ do esac done -if [ "$LIST" ] +if [ -n "$LIST" ] then printf '%b\n' "Essential libraries:" for file in $essential_array @@ -417,12 +417,11 @@ then exit 1 fi" > "$install_pass_script" chmod +x "$install_pass_script" -export SUDO_ASKPASS=$install_pass_script +export SUDO_ASKPASS="$install_pass_script" if [ "$gtk_version" = "Uninstall" ] then uninstall - exit fi # Put the install log in tmp, to avoid writing to PWD during a new install @@ -453,7 +452,7 @@ do i=$((i + 1)) done -kill $zen_pid 2> /dev/null +kill "$zen_pid" 2> /dev/null # Ask the user which options to install if [ -n "$option_string" ] @@ -511,7 +510,7 @@ fi printf '%b\n' "20" > "$zen_pipe" printf '%b\n' "#Cleaning installed version..." > "$zen_pipe" -if [ $mode = "install" ] +if [ "$mode" = "install" ] then cd geeqie || exit 1 else @@ -521,7 +520,7 @@ fi printf '%b\n' "30" > "$zen_pipe" printf '%b\n' "#Checkout required version..." > "$zen_pipe" -if [ "$BACK" ] +if [ -n "$BACK" ] then if ! git checkout master~"$BACK" >> "$install_log" 2>&1 then @@ -529,7 +528,7 @@ then zenity --title="$title" --width=370 --height=400 --error --text="Git error:\n\n$git_error" 2> /dev/null exit_install fi -elif [ "$COMMIT" ] +elif [ -n "$COMMIT" ] then if ! git checkout "$COMMIT" >> "$install_log" 2>&1 @@ -538,14 +537,13 @@ then zenity --title="$title" --width=370 --height=400 --error --text="Git error:\n\n$git_error" 2> /dev/null exit_install fi -elif [ "$TAG" ] +elif [ -n "$TAG" ] then if ! git checkout "$TAG" >> "$install_log" 2>&1 then git_error=$(tail -n5 "$install_log" 2>&1) zenity --title="$title" --width=370 --height=400 --error --text="Git error:\n\n$git_error" 2> /dev/null exit_install - exit fi fi diff --git a/gen_changelog.sh b/gen_changelog.sh index 3b8bb372..b47a1a2d 100755 --- a/gen_changelog.sh +++ b/gen_changelog.sh @@ -11,7 +11,7 @@ builddir="$2" -cd "$1" +cd "$1" || exit [ ! -e "ChangeLog.gqview" ] && exit 1 [ ! -x "$(command -v git)" ] && exit 1 @@ -40,6 +40,7 @@ mv -f "$builddir/ChangeLog.$$.new.html" "$builddir/ChangeLog.html" # Meson: distribute in tarballs. The first variable is more reliable, but requires Meson 0.58. # Fallback to the older one if necessary +# shellcheck disable=SC2154 for distdir in "$MESON_PROJECT_DIST_ROOT" "$MESON_DIST_ROOT"; do if [ -n "$distdir" ]; then cp -f "$builddir/ChangeLog.html" "$distdir/ChangeLog.html" diff --git a/plugins/camera-import/geeqie-camera-import-hook-script b/plugins/camera-import/geeqie-camera-import-hook-script index d89cbd9c..964d69b2 100755 --- a/plugins/camera-import/geeqie-camera-import-hook-script +++ b/plugins/camera-import/geeqie-camera-import-hook-script @@ -4,6 +4,7 @@ ## @brief Camera import hook script ## +# shellcheck disable=2154 if [ "$ACTION" = "download" ] then printf '%s\n' "$ARGUMENT" >> /tmp/geeqie-camera-import-files diff --git a/plugins/image-crop/geeqie-image-crop b/plugins/image-crop/geeqie-image-crop index 0cc9dcbc..23711ddb 100755 --- a/plugins/image-crop/geeqie-image-crop +++ b/plugins/image-crop/geeqie-image-crop @@ -34,7 +34,7 @@ process_raw () res=1 fi - return $res + return "$res" } process_plain () diff --git a/plugins/rotate/geeqie-rotate b/plugins/rotate/geeqie-rotate index 1a6f0da2..dca9df61 100755 --- a/plugins/rotate/geeqie-rotate +++ b/plugins/rotate/geeqie-rotate @@ -10,12 +10,13 @@ GQ_METADATA_DIR="$HOME/.local/share/geeqie/metadata" rotate() { - ext=`echo "${1##*.}" |tr "[:upper:]" "[:lower:]"` - [ "x$ext" = "x" ] && return 1 #no extension + ext=$(echo "${1##*.}" |tr "[:upper:]" "[:lower:]") + [ "$ext" = "" ] && return 1 #no extension gq_metadata="$GQ_METADATA_DIR/$1.gq.xmp" if [ -f "$gq_metadata" ] ; then - gq_orientation=`exiv2 -PXkv "$gq_metadata"|grep Xmp.tiff.Orientation|sed -e "s|Xmp.tiff.Orientation *||"` + gq_orientation=$(exiv2 -PXkv "$gq_metadata"|grep Xmp.tiff.Orientation|sed -e "s|Xmp.tiff.Orientation *||") +# shellcheck disable=2181 [ $? != 0 ] && exit 1 else gq_orientation= @@ -25,16 +26,19 @@ rotate() jpg|jpeg) if [ -n "$gq_orientation" ] ; then exiv2 -M "set Exif.Image.Orientation $gq_orientation" "$1" +# shellcheck disable=2181 [ $? != 0 ] && exit 1 fi if exiftran -aip "$1" ; then # exiftran ignores xmp, set it manually exiv2 -M "set Xmp.tiff.Orientation 1" "$1" +# shellcheck disable=2181 [ $? != 0 ] && exit 1 #http://dev.exiv2.org/issues/639 if [ -n "$gq_orientation" ] ; then exiv2 -M "set Xmp.tiff.Orientation 1" \ -M "set Exif.Image.Orientation 1" "$gq_metadata" +# shellcheck disable=2181 [ $? != 0 ] && exit 1 fi return 0 @@ -46,16 +50,19 @@ rotate() tif|tiff|png) if [ -n "$gq_orientation" ] ; then exiv2 -M "set Exif.Image.Orientation $gq_orientation" "$1" +# shellcheck disable=2181 [ $? != 0 ] && exit 1 fi if mogrify -auto-orient "$1" ; then # mogrify ignores xmp, set it manually exiv2 -M "set Xmp.tiff.Orientation 1" "$1" +# shellcheck disable=2181 [ $? != 0 ] && exit 1 #http://dev.exiv2.org/issues/639 if [ -n "$gq_orientation" ] ; then exiv2 -M "set Xmp.tiff.Orientation 1" \ -M "set Exif.Image.Orientation 1" "$gq_metadata" +# shellcheck disable=2181 [ $? != 0 ] && exit 1 fi return 0 @@ -71,18 +78,20 @@ rotate() rotate_image_file() { - ext=`echo "${3##*.}" |tr "[:upper:]" "[:lower:]"` - [ "x$ext" = "x" ] && return 1 #no extension + ext=$(echo "${3##*.}" |tr "[:upper:]" "[:lower:]") + [ "$ext" = "" ] && return 1 #no extension case "$ext" in jpg|jpeg) exiftran -i "$1" "$3" +# shellcheck disable=2181 [ $? != 0 ] && return 6 return 0; ;; tif|tiff|png) mogrify "$2" "$3" +# shellcheck disable=2181 [ $? != 0 ] && return 7 return 0; ;; @@ -94,14 +103,14 @@ rotate_image_file() } get_sidecars= -if [ "x$1" = "x-g" ] ; then +if [ "$1" = "-g" ] ; then get_sidecars=yes shift fi rotate_image_file= rotation= -if [ "x$1" = "x-r" ] ; then +if [ "$1" = "-r" ] ; then rotate_image_file=yes shift rotation="$1" @@ -109,40 +118,40 @@ if [ "x$1" = "x-r" ] ; then fi preserve_mtime= -if [ "x$1" = "x-t" ] ; then +if [ "$1" = "-t" ] ; then preserve_mtime=yes shift fi if [ -n "$rotation" ] ; then - if [ "x$rotation" = "x0" ] ; then + if [ "$rotation" = "0" ] ; then exit 0 fi - if [ "x$rotation" = "x2" ] ; then + if [ "$rotation" = "2" ] ; then mogrify_param="-flop" exiftran_param="-F" fi - if [ "x$rotation" = "x3" ] ; then + if [ "$rotation" = "3" ] ; then mogrify_param="-rotate 180" exiftran_param="-1" fi - if [ "x$rotation" = "x4" ] ; then + if [ "$rotation" = "4" ] ; then mogrify_param="-flip" exiftran_param="-f" fi - if [ "x$rotation" = "x5" ] ; then + if [ "$rotation" = "5" ] ; then mogrify_param="-transpose" exiftran_param="-t" fi - if [ "x$rotation" = "x6" ] ; then + if [ "$rotation" = "6" ] ; then mogrify_param="-rotate 90" exiftran_param="-9" fi - if [ "x$rotation" = "x7" ] ; then + if [ "$rotation" = "7" ] ; then mogrify_param="-transverse" exiftran_param="-T" fi - if [ "x$rotation" = "x8" ] ; then + if [ "$rotation" = "8" ] ; then mogrify_param="-rotate -90" exiftran_param="-2" fi @@ -161,12 +170,12 @@ for file in "$@" ; do done # Bourne shell runs DO loops in a sub-shell ret=$? - [ $ret != 0 ] && exit $ret + [ "$ret" != 0 ] && exit "$ret" else [ ! -w "$file" ] && exit 5 if [ -n "$rotate_image_file" ] ; then if [ -n "$preserve_mtime" ] ; then - mtime=`mktemp "${TMPDIR:-/tmp}/geeqie-rotate.XXXXXXXXXX"` || exit 3 + mtime=$(mktemp "${TMPDIR:-/tmp}/geeqie-rotate.XXXXXXXXXX") || exit 3 touch --reference="$file" "$mtime" fi @@ -177,11 +186,11 @@ for file in "$@" ; do touch --reference="$mtime" "$file" rm "$mtime" fi - [ $ret != 0 ] && exit $ret + [ "$ret" != 0 ] && exit "$ret" else rotate "$file" ret=$? - [ $ret != 0 ] && exit $ret + [ "$ret" != 0 ] && exit "$ret" fi fi done diff --git a/plugins/symlink/geeqie-symlink b/plugins/symlink/geeqie-symlink index 51504e12..9da7f24c 100755 --- a/plugins/symlink/geeqie-symlink +++ b/plugins/symlink/geeqie-symlink @@ -10,10 +10,10 @@ for file in "$@" ; do # we got only one file for each group, typically the main one # get the sidecars: - geeqie -r --get-sidecars:"$file" |while read sidecar ; do + geeqie -r --get-sidecars:"$file" |while read -r sidecar ; do # the main file is included in the sidecar file list, no special handling is required # get destination path for each sidecar file: - geeqie -r --get-destination:"$sidecar" | if read destination ; then + geeqie -r --get-destination:"$sidecar" | if read -r destination ; then ln -s "$sidecar" "$destination" fi done diff --git a/plugins/tethered-photography/geeqie-tethered-photography b/plugins/tethered-photography/geeqie-tethered-photography index 380c6ff1..1d47341c 100755 --- a/plugins/tethered-photography/geeqie-tethered-photography +++ b/plugins/tethered-photography/geeqie-tethered-photography @@ -47,5 +47,5 @@ then zenity --text-info --title="Geeqie tethered photography" --window-icon=/usr/local/share/pixmaps/geeqie.png --ok-label="Stop" --cancel-label="Abort" <"$tmpfile" 2>/dev/null fi -kill $gphoto2_pid +kill "$gphoto2_pid" rm "$tmpfile" diff --git a/plugins/tethered-photography/geeqie-tethered-photography-hook-script b/plugins/tethered-photography/geeqie-tethered-photography-hook-script index 6b83e1c2..394b27bb 100755 --- a/plugins/tethered-photography/geeqie-tethered-photography-hook-script +++ b/plugins/tethered-photography/geeqie-tethered-photography-hook-script @@ -4,6 +4,7 @@ ## @brief Tethered photography hook script ## +# shellcheck disable=SC2154 if [ "$ACTION" = "download" ] then notify-send --expire-time=4000 "$ARGUMENT" --icon=geeqie diff --git a/po/regen_potfiles.sh b/po/regen_potfiles.sh index 540bd417..278499db 100755 --- a/po/regen_potfiles.sh +++ b/po/regen_potfiles.sh @@ -9,8 +9,8 @@ # TODO(xsdg): Re-write this in a simpler way and test that it works: (cd ..; find ... | sort > $TMP) TMP=POTFILES.$$ -((find ../src/ -type f \( -name '*.c' -o -name '*.cc' \) ; find ../ -type f -name '*.desktop.in' ; find ../ -type f -name '*.appdata.xml.in') | while read f; do - (echo $f | sed 's#^../##') -done) | sort > $TMP -diff -u POTFILES $TMP -rm -f $TMP +( (find ../src/ -type f \( -name '*.c' -o -name '*.cc' \) ; find ../ -type f -name '*.desktop.in' ; find ../ -type f -name '*.appdata.xml.in') | while read -r f; do + (echo "$f" | sed 's#^../##') +done) | sort > "$TMP" +diff -u POTFILES "$TMP" +rm -f "$TMP" diff --git a/scripts/generate-linuxdeploy-for-arm.sh b/scripts/generate-linuxdeploy-for-arm.sh index a857197e..bccf8401 100644 --- a/scripts/generate-linuxdeploy-for-arm.sh +++ b/scripts/generate-linuxdeploy-for-arm.sh @@ -41,13 +41,13 @@ sudo apt install libgirepository1.0-dev rm -rf /tmp/linuxdeploy-* -cd "$HOME" +cd "$HOME" || exit if [ ! -d bin ] then mkdir bin fi -cd "$HOME"/bin +cd "$HOME"/bin || exit if [ ! -f appimagetool-aarch64.AppImage ] then @@ -67,7 +67,7 @@ then mv linuxdeploy linuxdeploy-download fi -cd linuxdeploy-download +cd linuxdeploy-download || exit # Use arm architecture sed -i 's/"x86_64"/"aarch64"/g' ./ci/build.sh @@ -104,7 +104,7 @@ then git clone --recursive https://github.com/linuxdeploy/linuxdeploy-plugin-appimage.git fi -cd linuxdeploy-plugin-appimage +cd linuxdeploy-plugin-appimage || exit # Always use /tmp sed -i 's/TEMP_BASE=\/dev\/shm/TEMP_BASE=\/tmp/' ./ci/build-appimage.sh diff --git a/scripts/keyword_merge.sh b/scripts/keyword_merge.sh index c533331c..0a869dd8 100755 --- a/scripts/keyword_merge.sh +++ b/scripts/keyword_merge.sh @@ -14,7 +14,7 @@ merge_file() flag=0 while read -r line_merge do - if [ $flag -eq 0 ] + if [ "$flag" -eq 0 ] then if [ "$line_merge" != "${line_merge%*}" ] then @@ -40,11 +40,11 @@ then fi -if [ $np -ge 3 ] +if [ "$np" -ge 3 ] then zenity --error --text "Too many parameters" exit -elif [ $np -eq 0 ] +elif [ "$np" -eq 0 ] then config_main=$(zenity --file-selection --file-filter="geeqierc.xml" --file-filter="*.xml" --file-filter="*" --title="Select main configuration file") if [ $? -eq 1 ] @@ -56,7 +56,7 @@ then then exit fi -elif [ $np -eq 1 ] +elif [ "$np" -eq 1 ] then config_merge=$(zenity --file-selection --file-filter="geeqierc.xml" --file-filter="*.xml" --file-filter="*" --title="Select configuration file to merge from") if [ $? -eq 1 ] diff --git a/scripts/new-release.sh b/scripts/new-release.sh index ef48f418..0faee503 100755 --- a/scripts/new-release.sh +++ b/scripts/new-release.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh ## @file ## @brief Create a new release @@ -17,14 +17,6 @@ ## It is expected that the first line of NEWS is in the form "Geeqie \ ## -error_handler () -{ - echo "Error on line: $1" - exit 1 -} -trap 'error_handler ${LINENO}' ERR - - version= start= patch= diff --git a/version.sh b/version.sh index f6e1c5a3..772aada5 100755 --- a/version.sh +++ b/version.sh @@ -32,7 +32,7 @@ then minor_version=$2 # patch_version=$3 # not used on master branch - printf '%s%s%s%s%s%s%s' "$major_version" "." "$minor_version" "+git" $(git log --max-count=1 --date=format:"%Y%m%d" --format="%ad") "-" $(git rev-parse --quiet --verify --short HEAD) + printf '%s%s%s%s%s%s%s' "$major_version" "." "$minor_version" "+git" "$(git log --max-count=1 --date=format:"%Y%m%d" --format="%ad")" "-" "$(git rev-parse --quiet --verify --short HEAD)" else version=$(head -1 NEWS) # shellcheck disable=SC2086 -- 2.20.1