From 3ffa1b284b36a27366a0b2537fb6fe669a6344a4 Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Sat, 19 Mar 2022 11:20:44 +0000 Subject: [PATCH] Fix #975, #977: Change scripts from /bin/bash to /bin/sh https://github.com/BestImageViewer/geeqie/pull/975/commits/01d45343f9de35ac6cdf696864066b9b1a5015a0 https://github.com/BestImageViewer/geeqie/pull/977/commits/c84ccd8408a6b88483e6690574390c7b27b49c01 - Change all /bin/bash to /bin/sh - Make POSIX compliant - Standardize mktemp calls - Change some echo calls to printf - Change some @brief headers - Update CODING.md for above changes --- CODING.md | 50 ++ doc/create-doxygen-lua-api.sh | 9 +- doc/create-shortcuts-xml.sh | 14 +- geeqie-install-debian.sh | 596 +++++++++--------- gen_changelog.sh | 2 +- gen_readme.sh | 10 +- plugins/camera-import/geeqie-camera-import | 110 ++-- .../geeqie-camera-import-hook-script | 8 +- plugins/export-jpeg/geeqie-export-jpeg | 36 +- .../geocode-parameters/geocode-parameters.awk | 2 +- plugins/image-crop/geeqie-image-crop | 56 +- plugins/random-image/geeqie-random-image | 49 +- plugins/rotate/geeqie-rotate | 6 +- plugins/symlink/geeqie-symlink | 2 +- .../geeqie-tethered-photography | 16 +- .../geeqie-tethered-photography-hook-script | 4 +- po/gen_translations_stats.sh | 8 +- scripts/check-compiles.sh | 38 +- scripts/doxygen-help.sh | 12 +- scripts/generate-appimage.sh | 14 +- scripts/generate-man-page.sh | 21 +- scripts/keyword_merge.sh | 39 +- scripts/new-release.sh | 22 +- scripts/template-desktop.sh | 12 +- scripts/untranslated-text.sh | 6 +- scripts/web-help.sh | 8 +- version.sh | 18 +- 27 files changed, 610 insertions(+), 558 deletions(-) mode change 100644 => 100755 plugins/image-crop/geeqie-image-crop diff --git a/CODING.md b/CODING.md index 2a4648b1..e33bcdf5 100644 --- a/CODING.md +++ b/CODING.md @@ -4,6 +4,7 @@ [GPL header](#gpl-header) [Git change log](#git-change-log) [Source Code Style](#source-code-style) +[Shell Script Style](#shell-script-style) [External Software Tools](#external-software-tools) [Geeqie Software Tools](#geeqie-software-tools) [Documentation](#documentation) @@ -198,6 +199,25 @@ Use glib types when possible (ie. gint and gchar instead of int and char). Use glib functions when possible (i.e. `g_ascii_isspace()` instead of `isspace()`). Check if used functions are not deprecated. +--- + +## Shell Script Style + +Use `/bin/sh` as the interpreter directive. +Ensure the script is POSIX compliant. +Use `printf` rather than `echo` except for plain text. +There are several versions of `mktemp`. Using the following definition helps portability (note that `template` is not optional): + +```sh +mktemp [-d] [-q] template ... +``` + +and use for example this style: + +```sh +mktemp "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX" +``` + --- ## External Software Tools @@ -264,6 +284,36 @@ Shell scripts may also be validated, e.g. shellcheck --enable=add-default-case,avoid-nullary-conditions,check-unassigned-uppercase,deprecate-which,quote-safe-variables ``` +### shfmt + +Shell scripts may formatted to some extent with [shfmt](https://github.com/mvdan/sh). At the time of writing it does not format `if`, `for` or `while` statements in the style used by Geeqie. +However the following script can be used to achieve that: + +```sh +#!/bin/sh + +shfmt -s -p -ci -sr -fn | awk ' + {if ($0 ~ /; then/) + { + match($0, /^\t*/); + printf('%s\n', substr($0, 0, length($0) - 6)); + printf('%s, substr("\t\t\t\t\t\t\t\t\t\t", 1, RLENGTH)) + print("then") + } + else if ($0 ~ /; do/) + { + match($0, /^\t*/); + printf('%s\n', substr($0, 0, length($0) - 4)); + printf('%s', substr("\t\t\t\t\t\t\t\t\t\t", 1, RLENGTH)) + print("do") + } + else + { + print + } + }' +``` + ### xmllint The .xml Help files may be validated with e.g. `xmllint`. diff --git a/doc/create-doxygen-lua-api.sh b/doc/create-doxygen-lua-api.sh index 0738d728..6730694c 100755 --- a/doc/create-doxygen-lua-api.sh +++ b/doc/create-doxygen-lua-api.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh #********************************************************************** # Copyright (C) 2021 - The Geeqie Team @@ -21,7 +21,7 @@ #********************************************************************** ## @file -## @brief This script will create the Lua API html document, which is part of +## @brief Create the Lua API html document, which is part of ## the Geeqie Help file. ## ## It is run during the generation of the help files. @@ -33,13 +33,14 @@ ## export PROJECT="Geeqie" -export VERSION=$(git tag --list v[1-9]* | tail -1) +VERSION=$(git tag --list v[1-9]* | tail -1) +export VERSION export SRCDIR="$PWD/.." export DOCDIR="$PWD/html/lua-api" export INLINE_SOURCES=NO export STRIP_CODE_COMMENTS=YES -TMPFILE=$(mktemp "${TMPDIR:-/tmp}/geeqie.XXXXXXXX") || exit 1 +TMPFILE=$(mktemp "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX") || exit 1 # Modify the Geeqie doxygen.conf file to produce # only the data needed for the lua API document diff --git a/doc/create-shortcuts-xml.sh b/doc/create-shortcuts-xml.sh index a8ac2ce9..05b60099 100755 --- a/doc/create-shortcuts-xml.sh +++ b/doc/create-shortcuts-xml.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh #********************************************************************** # Copyright (C) 2021 - The Geeqie Team @@ -128,19 +128,19 @@ $0 ~ /^ { "/ { ' keys_xml=$(awk "$awk_window" ./src/dupe.c ) -echo -e "$pre_1_xml" "$duplicates_xml" "$pre_2_xml" "$keys_xml" "$post_xml" > ./doc/docbook/GuideReferenceDuplicatesShortcuts.xml +printf '%b\n' "$pre_1_xml $duplicates_xml $pre_2_xml $keys_xml $post_xml" > ./doc/docbook/GuideReferenceDuplicatesShortcuts.xml keys_xml=$(awk "$awk_window" ./src/search.c ) -echo -e "$pre_1_xml" "$search_xml" "$pre_2_xml" "$keys_xml" "$post_xml" > ./doc/docbook/GuideReferenceSearchShortcuts.xml +printf '%b\n' "$pre_1_xml $search_xml $pre_2_xml $keys_xml $post_xml" > ./doc/docbook/GuideReferenceSearchShortcuts.xml keys_xml=$(awk "$awk_window" ./src/pan-view/pan-view.c ) -echo -e "$pre_1_xml" "$pan_view_xml" "$pre_2_xml" "$keys_xml" "$post_xml" > ./doc/docbook/GuideReferencePanViewShortcuts.xml +printf '%b\n' "$pre_1_xml $pan_view_xml $pre_2_xml $keys_xml $post_xml" > ./doc/docbook/GuideReferencePanViewShortcuts.xml keys_xml=$(awk "$awk_window" ./src/collect-table.c) -echo -e "$pre_1_xml" "$collections_xml" "$pre_2_xml" "$keys_xml" "$post_xml" > ./doc/docbook/GuideReferenceCollectionsShortcuts.xml +printf '%b\n' "$pre_1_xml $collections_xml $pre_2_xml $keys_xml $post_xml" > ./doc/docbook/GuideReferenceCollectionsShortcuts.xml keys_xml=$(awk "$awk_window" ./src/img-view.c) -echo -e "$pre_1_xml" "$image_xml" "$pre_2_xml" "$keys_xml" "$post_xml" > ./doc/docbook/GuideReferenceImageViewShortcuts.xml +printf '%b\n' "$pre_1_xml $image_xml $pre_2_xml $keys_xml $post_xml" > ./doc/docbook/GuideReferenceImageViewShortcuts.xml keys_xml=$(awk "$awk_main_window" ./src/layout_util.c) -echo -e "$pre_1_xml" "$main_window_xml" "$pre_2_xml" "$keys_xml" "$post_main_window_xml" > ./doc/docbook/GuideReferenceMainWindowShortcuts.xml +printf '%b\n' "$pre_1_xml $main_window_xml $pre_2_xml $keys_xml $post_main_window_xml" > ./doc/docbook/GuideReferenceMainWindowShortcuts.xml diff --git a/geeqie-install-debian.sh b/geeqie-install-debian.sh index e729436d..6267613e 100755 --- a/geeqie-install-debian.sh +++ b/geeqie-install-debian.sh @@ -1,15 +1,15 @@ -#!/bin/bash +#!/bin/sh ## @file -## @brief This script will download, compile, and install Geeqie on Debian-based systems. +## @brief Download, compile, and install Geeqie on Debian-based systems. ## -## If run from a folder that already contains the Geeqie sources, the source -## code will be updated from the repository. +## If run from a folder that already contains the Geeqie sources, the source +## code will be updated from the repository. ## Dialogs allow the user to install additional features. ## -version="2022-01-15" -description=$' +version="2022-03-18" +description=' Geeqie is an image viewer. This script will download, compile, and install Geeqie on Debian-based systems. If run from a folder that already contains the Geeqie sources, the source @@ -27,73 +27,67 @@ Command line options are: ' # Essential for compiling -essential_array=( -"git" -"build-essential" -"autoconf" -"libglib2.0-0" -"intltool" -"libtool" -"yelp-tools" -) +essential_array="git +build-essential +autoconf +libglib2.0-0 +intltool +libtool +yelp-tools" # Optional for both GTK2 and GTK3 -optional_array=( -"LCMS (for color management)" -"liblcms2-dev" -"exiv2 (for exif handling)" -"libgexiv2-dev" -"lua (for --remote commands)" -"liblua5.1-0-dev" -"libffmpegthumbnailer (for mpeg thumbnails)" -"libffmpegthumbnailer-dev" -"libtiff (for tiff support)" -"libtiff-dev" -"libjpeg (for jpeg support)" -"libjpeg-dev" -"librsvg2 (for viewing .svg images)" -"librsvg2-common" -"libwmf (for viewing .wmf images)" -"libwmf0.2-7-gtk" -"exiftran (for image rotation)" -"exiftran" -"imagemagick (for image rotation)" -"imagemagick" -"exiv2 command line (for jpeg export)" -"exiv2" -"jpgicc (for jpeg export color correction)" -"liblcms2-utils" -"pandoc (for generating README help file)" -"pandoc" -"gphoto2 (for tethered photography and camera download plugins)" -"gphoto2" -"libimage-exiftool-perl (for jpeg extraction plugin)" -"libimage-exiftool-perl" -"libheif (for HEIF support)" -"libheif-dev" -"libwebp (for WebP images)" -"libwebp-dev" -"libdjvulibre (for DjVu images)" -"libdjvulibre-dev" -"libopenjp2 (for JP2 images)" -"libopenjp2-7-dev" -"libraw (for CR3 images)" -"libraw-dev" -"libomp (required by libraw)" -"libomp-dev" -"libarchive (for compressed files e.g. zip, including timezone)" -"libarchive-dev" -) +optional_array="LCMS (for color management) +liblcms2-dev +exiv2 (for exif handling) +libgexiv2-dev +lua (for --remote commands) +liblua5.1-0-dev +libffmpegthumbnailer (for mpeg thumbnails) +libffmpegthumbnailer-dev +libtiff (for tiff support) +libtiff-dev +libjpeg (for jpeg support) +libjpeg-dev +librsvg2 (for viewing .svg images) +librsvg2-common +libwmf (for viewing .wmf images) +libwmf0.2-7-gtk +exiftran (for image rotation) +exiftran +imagemagick (for image rotation) +imagemagick +exiv2 command line (for jpeg export) +exiv2 +jpgicc (for jpeg export color correction) +liblcms2-utils +pandoc (for generating README help file) +pandoc +gphoto2 (for tethered photography and camera download plugins) +gphoto2 +libimage-exiftool-perl (for jpeg extraction plugin) +libimage-exiftool-perl +libheif (for HEIF support) +libheif-dev +libwebp (for WebP images) +libwebp-dev +libdjvulibre (for DjVu images) +libdjvulibre-dev +libopenjp2 (for JP2 images) +libopenjp2-7-dev +libraw (for CR3 images) +libraw-dev +libomp (required by libraw) +libomp-dev +libarchive (for compressed files e.g. zip, including timezone) +libarchive-dev" # Optional for GTK3 only -optional_gtk3_array=( -"libchamplain gtk (for GPS maps)" -"libchamplain-gtk-0.12-dev" -"libchamplain (for GPS maps)" -"libchamplain-0.12-dev" -"libpoppler (for pdf file preview)" -"libpoppler-glib-dev" -) +optional_gtk3_array="libchamplain gtk (for GPS maps) +libchamplain-gtk-0.12-dev +libchamplain (for GPS maps) +libchamplain-0.12-dev +libpoppler (for pdf file preview) +libpoppler-glib-dev" #################################################################### # Get System Info @@ -101,65 +95,66 @@ optional_gtk3_array=( #################################################################### lowercase() { - echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/" + printf '%b\n' "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/" } systemProfile() { - OS=`lowercase \`uname\`` - KERNEL=`uname -r` - MACH=`uname -m` + OS="$(lowercase "$(uname)")" + KERNEL=$(uname -r) + MACH=$(uname -m) - if [ "${OS}" == "windowsnt" ] + if [ "${OS}" = "windowsnt" ] then OS=windows - elif [ "${OS}" == "darwin" ] + elif [ "${OS}" = "darwin" ] then OS=mac else - OS=`uname` + OS=$(uname) if [ "${OS}" = "SunOS" ] then OS=Solaris - ARCH=`uname -p` - OSSTR="${OS} ${REV}(${ARCH} `uname -v`)" + ARCH=$(uname -p) + OSSTR="${OS} ${REV}(${ARCH} $(uname -v))" elif [ "${OS}" = "AIX" ] then - OSSTR="${OS} `oslevel` (`oslevel -r`)" + # shellcheck disable=SC2034 + OSSTR="${OS} $(oslevel) ($(oslevel -r))" elif [ "${OS}" = "Linux" ] then if [ -f /etc/redhat-release ] then DistroBasedOn='RedHat' - DIST=`cat /etc/redhat-release |sed s/\ release.*//` - PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//` - REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//` + DIST=$(sed s/\ release.*// /etc/redhat-release) + PSUEDONAME=$(sed s/.*\(// /etc/redhat-release | sed s/\)//) + REV=$(sed s/.*release\ // /etc/redhat-release | sed s/\ .*//) elif [ -f /etc/SuSE-release ] then DistroBasedOn='SuSe' - PSUEDONAME=`cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//` - REV=`cat /etc/SuSE-release | tr "\n" ' ' | sed s/.*=\ //` + PSUEDONAME=$(tr "\n" ' ' < /etc/SuSE-release | sed s/VERSION.*//) + REV=$(tr "\n" ' ' < /etc/SuSE-release | sed s/.*=\ //) elif [ -f /etc/mandrake-release ] then DistroBasedOn='Mandrake' - PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//` - REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//` + PSUEDONAME=$(sed s/.*\(// /etc/mandrake-release | sed s/\)//) + REV=$(cat | sed s/.*release\ // /etc/mandrake-release | sed s/\ .*//) elif [ -f /etc/debian_version ] then DistroBasedOn='Debian' if [ -f /etc/lsb-release ] then - DIST=`cat /etc/lsb-release | grep '^DISTRIB_ID' | awk -F= '{ print $2 }'` - PSUEDONAME=`cat /etc/lsb-release | grep '^DISTRIB_CODENAME' | awk -F= '{ print $2 }'` - REV=`cat /etc/lsb-release | grep '^DISTRIB_RELEASE' | awk -F= '{ print $2 }'` + DIST=$(grep '^DISTRIB_ID' /etc/lsb-release | awk -F= '{ print $2 }') + PSUEDONAME=$(grep '^DISTRIB_CODENAME' /etc/lsb-release | awk -F= '{ print $2 }') + REV=$(grep '^DISTRIB_RELEASE' /etc/lsb-release | awk -F= '{ print $2 }') fi fi if [ -f /etc/UnitedLinux-release ] then - DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]" + 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 @@ -173,26 +168,29 @@ systemProfile() install_essential() { - arraylength=${#essential_array[@]} - for (( i=0; i<${arraylength}; i=i+1 )); + i=0 + + for file in $essential_array do - package_query ${essential_array[$i]} - if [ $? != 0 ] + if [ $((i % 2)) -ne 0 ] then - package_install ${essential_array[$i]} + if package_query "$file" + then + package_install "$file" + fi fi + + i=$((i + 1)) done - if [[ $1 == "GTK3" ]] + if [ "$1" = "GTK3" ] then - package_query "libgtk-3-dev" - if [ $? != 0 ] + if package_query "libgtk-3-dev" then package_install libgtk-3-dev fi else - package_query "libgtk2.0-dev" - if [ $? != 0 ] + if package_query "libgtk2.0-dev" then package_install libgtk2.0-dev fi @@ -205,10 +203,10 @@ install_options() then OLDIFS=$IFS IFS='|' - set $options - while [ $# -gt 0 ]; + set "$options" + while [ $# -gt 0 ] do - package_install $1 + package_install "$1" shift done IFS=$OLDIFS @@ -217,19 +215,19 @@ install_options() uninstall() { - current_dir=$(basename $PWD) - if [[ $current_dir == "geeqie" ]] + current_dir="$(basename "$PWD")" + if [ "$current_dir" = "geeqie" ] then + sudo --askpass make uninstall - zenity --title="Uninstall Geeqie" --width=370 --text="WARNING.\nThis will delete folder:\n\n$PWD\n\nand all sub-folders!" --question --ok-label="Cancel" --cancel-label="OK" 2>/dev/null - if [[ $? == 1 ]] + if ! zenity --title="Uninstall Geeqie" --width=370 --text="WARNING.\nThis will delete folder:\n\n$PWD\n\nand all sub-folders!" --question --ok-label="Cancel" --cancel-label="OK" 2> /dev/null then cd .. sudo --askpass rm -rf geeqie fi else - zenity --title="Uninstall Geeqie" --width=370 --text="This is not a geeqie installation folder!\n\n$PWD" --warning 2>/dev/null + zenity --title="Uninstall Geeqie" --width=370 --text="This is not a geeqie installation folder!\n\n$PWD" --warning 2> /dev/null fi exit_install @@ -237,14 +235,16 @@ uninstall() package_query() { - if [[ $DistroBasedOn == "debian" ]] + if [ "$DistroBasedOn" = "debian" ] then - res=$(dpkg-query --show --showformat='${Status}' $1 2>>$install_log) - if [[ "$res" == "install ok installed"* ]] + + # shellcheck disable=SC2086 + res=$(dpkg-query --show --showformat='${Status}' "$1" 2>> $install_log) + if [ "${res}" = "install ok installed" ] then - status=0 - else status=1 + else + status=0 fi fi return $status @@ -252,44 +252,46 @@ package_query() package_install() { - if [[ $DistroBasedOn == "debian" ]] + if [ "$DistroBasedOn" = "debian" ] then - sudo --askpass apt-get --assume-yes install $@ >>$install_log 2>&1 + # shellcheck disable=SC2024 + sudo --askpass apt-get --assume-yes install "$@" >> "$install_log" 2>&1 fi } exit_install() { - rm $install_pass_script >/dev/null 2>&1 - #~ rm $install_log >/dev/null 2>&1 + rm "$install_pass_script" > /dev/null 2>&1 - if [[ -p $zen_pipe ]] + if [ -p "$zen_pipe" ] then - echo "100" > $zen_pipe - echo "#End" > $zen_pipe + printf '%b\n' "100" > "$zen_pipe" + printf '%b\n' "#End" > "$zen_pipe" fi - zenity --title="$title" --width=370 --text=$'Geeqie is not installed\nLog file: '$install_log --info 2>/dev/null + zenity --title="$title" --width=370 --text="Geeqie is not installed\nLog file: $install_log" --info 2> /dev/null - rm $zen_pipe >/dev/null 2>&1 + rm "$zen_pipe" > /dev/null 2>&1 exit 1 } # Entry point +IFS=' +' + # If uninstall has been run, maybe the current directory no longer exists -ls $PWD >/dev/null -if [[ $? != 0 ]] +if [ ! -d "$PWD" ] then - zenity --error --title="Install Geeqie and dependencies" --width=370 --text="Folder $PWD does not exist!" 2>/dev/null + zenity --error --title="Install Geeqie and dependencies" --width=370 --text="Folder $PWD does not exist!" 2> /dev/null exit fi # Check system type systemProfile -if [[ $DistroBasedOn != "debian" ]] +if [ "$DistroBasedOn" != "debian" ] then zenity --error --title="Install Geeqie and dependencies" --width=370 --text="Unknown operating system:\n Operating System: $OS @@ -298,7 +300,7 @@ Psuedoname: $PSUEDONAME Revision: $REV DistroBasedOn: $DistroBasedOn Kernel: $KERNEL -Machine: $MACH" 2>/dev/null +Machine: $MACH" 2> /dev/null exit fi @@ -307,70 +309,68 @@ fi OPTS=$(getopt -o vhc:t:b:ld: --long version,help,commit:,tag:,back:,list,debug: -- "$@") eval set -- "$OPTS" -while true; +while true do case "$1" in - -v | --version ) - echo "$version" - exit - ;; - -h | --help ) - echo "$description" - exit - ;; - -c | --commit ) - COMMIT="$2" - shift - shift - ;; - -t | --tag ) - TAG="$2" - shift; - shift - ;; - -b | --back ) - BACK="$2" - shift; - shift - ;; - -l | --list ) - LIST="$2" - shift; - shift - ;; - -d | --debug ) - DEBUG="$2" - shift; - shift - ;; - * ) break - ;; + -v | --version) + printf '%b\n' "$version" + exit + ;; + -h | --help) + printf '%b\n' "$description" + exit + ;; + -c | --commit) + COMMIT="$2" + shift + shift + ;; + -t | --tag) + TAG="$2" + shift + shift + ;; + -b | --back) + BACK="$2" + shift + shift + ;; + -l | --list) + LIST="$2" + shift + shift + ;; + -d | --debug) + DEBUG="$2" + shift + shift + ;; + *) + break + ;; esac done -if [[ "$LIST" ]] +if [ "$LIST" ] then - echo "Essential libraries:" - arraylength=${#essential_array[@]} - for (( i=0; i<${arraylength}; i=i+1 )); + printf '%b\n' "Essential libraries:" + for file in $essential_array do - echo ${essential_array[$i]} + printf '%b\n' "$file" done - echo " " - echo "Optional libraries:" - arraylength=${#optional_array[@]} - for (( i=0; i<${arraylength}; i=i+1 )); + printf '\n' + printf '%b\n' "Optional libraries:" + for file in $optional_array do - echo ${optional_array[$i]} + printf '%b\n' "$file" done - echo " " - echo "Optional for GTK3:" - arraylength=${#optional_gtk3_array[@]} - for (( i=0; i<${arraylength}; i=i+1 )); + printf '\n' + printf '%b\n' "Optional for GTK3:" + for file in $optional_gtk3_array do - echo ${optional_gtk3_array[$i]} + printf '%b\n' "$file" done exit @@ -379,7 +379,7 @@ fi # If a Geeqie folder already exists here, warn the user if [ -d "geeqie" ] then - zenity --info --title="Install Geeqie and dependencies" --width=370 --text="This script is for use on Ubuntu and other\nDebian-based installations.\nIt will download, compile, and install Geeqie source\ncode and its dependencies.\n\nA sub-folder named \"geeqie\" will be created in the\nfolder this script is run from, and the source code\nwill be downloaded to that sub-folder.\n\nA sub-folder of that name already exists.\nPlease try another folder." 2>/dev/null + zenity --info --title="Install Geeqie and dependencies" --width=370 --text="This script is for use on Ubuntu and other\nDebian-based installations.\nIt will download, compile, and install Geeqie source\ncode and its dependencies.\n\nA sub-folder named \"geeqie\" will be created in the\nfolder this script is run from, and the source code\nwill be downloaded to that sub-folder.\n\nA sub-folder of that name already exists.\nPlease try another folder." 2> /dev/null exit fi @@ -392,7 +392,7 @@ else # If it looks like something else is already installed here, warn the user if [ -d ".git" ] || [ -d "src" ] then - zenity --info --title="Install Geeqie and dependencies" --width=370 --text="This script is for use on Ubuntu and other\nDebian-based installations.\nIt will download, compile, and install Geeqie source\ncode and its dependencies.\n\nIt looks like you are running this script from a folder which already has software installed.\n\nPlease try another folder." 2>/dev/null + zenity --info --title="Install Geeqie and dependencies" --width=370 --text="This script is for use on Ubuntu and other\nDebian-based installations.\nIt will download, compile, and install Geeqie source\ncode and its dependencies.\n\nIt looks like you are running this script from a folder which already has software installed.\n\nPlease try another folder." 2> /dev/null exit else @@ -401,10 +401,10 @@ else fi # Use GTK3 as default -gk2_installed=FALSE +gtk2_installed=FALSE gtk3_installed=TRUE -if [[ $mode == "install" ]] +if [ "$mode" = "install" ] then message="This script is for use on Ubuntu and other\nDebian-based installations.\nIt will download, compile, and install Geeqie source\ncode and its dependencies.\n\nA sub-folder named \"geeqie\" will be created in the\nfolder this script is run from, and the source code\nwill be downloaded to that sub-folder.\n\nIn this dialog you must select whether to compile\nfor GTK2 or GTK3.\nIf you want to use GPS maps or pdf preview,\nyou must choose GTK3.\nThe GTK2 version has a slightly different\nlook-and-feel compared to the GTK3 version,\nbut otherwise has the same features.\nYou may easily switch between the two after\ninstallation.\n\nIn subsequent dialogs you may choose which\noptional features to install." @@ -417,231 +417,239 @@ else install_option=FALSE # When updating, use previous installation as default - if [[ -f config.log ]] + if [ -f config.log ] then - grep gtk-2.0 config.log >/dev/null - if [[ $? != 0 ]] + if grep gtk-2.0 config.log > /dev/null then - gtk2_installed=FALSE - gtk3_installed=TRUE - else gtk2_installed=TRUE gtk3_installed=FALSE + else + gtk2_installed=FALSE + gtk3_installed=TRUE fi fi fi # Ask whether to install GTK2 or GTK3 or uninstall -gtk_version=$(zenity --title="$title" --width=370 --text="$message" --list --radiolist --column "" --column "" "$gtk3_installed" "GTK3 (required for GPS maps and pdf preview)" "$gtk2_installed" "GTK2" FALSE "Uninstall" --cancel-label="Cancel" --ok-label="OK" --hide-header 2>/dev/null) - -if [[ $? == 1 ]] +if ! gtk_version=$(zenity --title="$title" --width=370 --text="$message" --list --radiolist --column "" --column "" "$gtk3_installed" "GTK3 (required for GPS maps and pdf preview)" "$gtk2_installed" "GTK2" FALSE "Uninstall" --cancel-label="Cancel" --ok-label="OK" --hide-header 2> /dev/null) then exit fi # Environment variable SUDO_ASKPASS cannot be "zenity --password", # so create a temporary script containing the command -install_pass_script=$(mktemp --tmpdir geeqie_install_XXXXXX.sh) -echo $'#!/bin/bash -zenity --password --title=\"'$title$'\" --width=370 2>/dev/null -if [[ $? > 0 ]] +install_pass_script=$(mktemp "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX") +printf '%b\n' "#!/bin/sh +if zenity --password --title=\"$title\" --width=370 2>/dev/null then exit 1 -fi -\n' > $install_pass_script -chmod +x $install_pass_script +fi" > "$install_pass_script" +chmod +x "$install_pass_script" export SUDO_ASKPASS=$install_pass_script -if [[ $gtk_version == "Uninstall" ]] +if [ "$gtk_version" = "Uninstall" ] then uninstall exit fi # Put the install log in tmp, to avoid writing to PWD during a new install -rm install.log 2>/dev/null -install_log=$(mktemp --tmpdir geeqie_install_XXXXXX.log) +rm install.log 2> /dev/null +install_log=$(mktemp "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX") -sleep 100 | zenity --title="$title" --text="Checking for installed files" --width=370 --progress --pulsate 2>/dev/null & +sleep 100 | zenity --title="$title" --text="Checking for installed files" --width=370 --progress --pulsate 2> /dev/null & zen_pid=$! # Get the standard options that are not yet installed -arraylength=${#optional_array[@]} -for (( i=0; i<${arraylength}; i=i+2 )); +i=0 +for file in $optional_array do - package_query ${optional_array[$i+1]} - if [ $? != 0 ] + if [ $((i % 2)) -eq 0 ] then - if [ -z "$option_string" ] + package_title="$file" + else + if package_query "$file" then - option_string="$install_option"$'\n'"${optional_array[$i]}"$'\n'"${optional_array[$i+1]}" - else - option_string="$option_string"$'\n'"$install_option"$'\n'"${optional_array[$i]}"$'\n'"${optional_array[$i+1]}" + if [ -z "$option_string" ] + then + option_string="${install_option:+${install_option}}\n${file}\n${file}" + else + option_string="${option_string:+${option_string}}\n$install_option\n${package_title}\n${file}" + fi fi fi + i=$((i + 1)) done # If GTK3 required, get the GTK3 options not yet installed -if [[ "$gtk_version" == "GTK3"* ]] +if [ -z "${gtk_version%%GTK3*}" ] then - arraylength=${#optional_gtk3_array[@]} - for (( i=0; i<${arraylength}; i=i+2 )); + i=0 + for file in $optional_gtk3_array do - package_query ${optional_gtk3_array[$i+1]} - if [ $? != 0 ] + if [ $((i % 2)) -eq 0 ] then - if [ -z "$option_string" ] + package_title="$file" + else + if package_query "$file" then - option_string="$install_option"$'\n'"${optional_gtk3_array[$i]}"$'\n'"${optional_gtk3_array[$i+1]}" - else - option_string="$option_string"$'\n'"$install_option"$'\n'"${optional_gtk3_array[$i]}"$'\n'"${optional_gtk3_array[$i+1]}" + if [ -z "$option_string" ] + then + option_string="${install_option:+${install_option}}\n${file}\n${file}" + else + option_string="${option_string:+${option_string}}\n$install_option\n${package_title}\n${file}" + fi fi fi + i=$((i + 1)) done fi -kill $zen_pid 2>/dev/null +kill $zen_pid 2> /dev/null # Ask the user which options to install if [ -n "$option_string" ] then - options=$(echo "$option_string" | zenity --title="$title" --width=400 --height=500 --list --checklist --text 'Select which library files to install:' --column='Select' --column='Library files' --column='Library' --hide-column=3 --print-column=3 2>/dev/null) - - if [[ $? == 1 ]] + if ! options=$(printf '%b\n' "$option_string" | zenity --title="$title" --width=400 --height=500 --list --checklist --text 'Select which library files to install:' --column='Select' --column='Library files' --column='Library' --hide-column=3 --print-column=3 2> /dev/null) then exit_install fi fi # Start of Zenity progress section -zen_pipe=$(mktemp --dry-run --tmpdir geeqie_install_pipe_XXXXXX) -mkfifo $zen_pipe -(tail -f $zen_pipe 2>/dev/null) | zenity --progress --title="$title" --width=370 --text="Installing options..." --auto-close --auto-kill --percentage=0 2>/dev/null & +zen_pipe=$(mktemp -u "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX") +mkfifo "$zen_pipe" +(tail -f "$zen_pipe" 2> /dev/null) | zenity --progress --title="$title" --width=370 --text="Installing options..." --auto-close --auto-kill --percentage=0 2> /dev/null & -echo "2" > $zen_pipe -echo "#Installing essential libraries..." > $zen_pipe +printf '%b\n' "2" > "$zen_pipe" +printf '%b\n' "#Installing essential libraries..." > "$zen_pipe" -install_essential $gtk_version +install_essential "$gtk_version" -echo "4" > $zen_pipe -echo "#Installing options..." > $zen_pipe +printf '%b\n' "4" > "$zen_pipe" +printf '%b\n' "#Installing options..." > "$zen_pipe" install_options -echo "6" > $zen_pipe -echo "#Installing extra loaders..." > $zen_pipe +printf '%b\n' "6" > "$zen_pipe" +printf '%b\n' "#Installing extra loaders..." > "$zen_pipe" -echo "10" > $zen_pipe -echo "#Getting new sources from server..." > $zen_pipe +printf '%b\n' "10" > "$zen_pipe" +printf '%b\n' "#Getting new sources from server..." > "$zen_pipe" -if [[ $mode == "install" ]] +if [ "$mode" = "install" ] then - ret=$(git clone git://geeqie.org/geeqie.git >>$install_log 2>&1) + if ! git clone git://geeqie.org/geeqie.git >> "$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 + fi else - git checkout master >>$install_log 2>&1 - if [[ $? != 0 ]] + if ! git checkout master >> "$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 + git_error="$(tail -n25 "$install_log" 2>&1)" + zenity --title="$title" --width=370 --height=400 --error --text="Git error:\n\n$git_error" 2> /dev/null + exit_install + fi + if ! git pull >> "$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 fi - ret=$(git pull >>$install_log 2>&1) -fi - -if [[ $? != 0 ]] -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 fi -echo "20" > $zen_pipe -echo "#Cleaning installed version..." > $zen_pipe +printf '%b\n' "20" > "$zen_pipe" +printf '%b\n' "#Cleaning installed version..." > "$zen_pipe" -if [[ $mode == "install" ]] +if [ $mode = "install" ] then - cd geeqie + cd geeqie || exit 1 else - sudo --askpass make uninstall >>$install_log 2>&1 - sudo --askpass make maintainer-clean >>$install_log 2>&1 + # shellcheck disable=SC2024 + sudo --askpass make uninstall >> "$install_log" 2>&1 + # shellcheck disable=SC2024 + sudo --askpass make maintainer-clean >> "$install_log" 2>&1 fi -echo "30" > $zen_pipe -echo "#Checkout required version..." > $zen_pipe +printf '%b\n' "30" > "$zen_pipe" +printf '%b\n' "#Checkout required version..." > "$zen_pipe" -if [[ "$BACK" ]] +if [ "$BACK" ] then - ret=$(git checkout master~"$BACK" >>$install_log 2>&1) - if [[ $? != 0 ]] + if ! git checkout master~"$BACK" >> "$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 + 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 fi -elif [[ "$COMMIT" ]] +elif [ "$COMMIT" ] then - ret=$(git checkout "$COMMIT" >>$install_log 2>&1) - if [[ $? != 0 ]] + + if ! git checkout "$COMMIT" >> "$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 + 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 fi -elif [[ "$TAG" ]] +elif [ "$TAG" ] then - ret=$(git checkout "$TAG" >>$install_log 2>&1) - if [[ $? != 0 ]] + if ! git checkout "$TAG" >> "$install_log" 2>&1 then - echo "error" - 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 + 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 -if [[ "$DEBUG" == "yes" ]] +if [ "$DEBUG" = "yes" ] then debug_opt="" else debug_opt="--disable-debug-log" fi -echo "40" > $zen_pipe -echo "#Creating configuration files..." > $zen_pipe +printf '%b\n' "40" > "$zen_pipe" +printf '%b\n' "#Creating configuration files..." > "$zen_pipe" -if [[ $gtk_version == "GTK3"* ]] +if [ -z "${gtk_version%%GTK3*}" ] then - ./autogen.sh "$debug_opt" >>$install_log 2>&1 + ./autogen.sh "$debug_opt" >> "$install_log" 2>&1 else - ./autogen.sh "$debug_opt" --disable-gtk3 >>$install_log 2>&1 + ./autogen.sh "$debug_opt" --disable-gtk3 >> "$install_log" 2>&1 fi -echo "60" > $zen_pipe -echo "#Compiling..." > $zen_pipe +printf '%b\n' "60" > "$zen_pipe" +printf '%b\n' "#Compiling..." > "$zen_pipe" export CFLAGS=$CFLAGS" -Wno-deprecated-declarations" export CXXFLAGS=$CXXFLAGS" -Wno-deprecated-declarations" -make -j >>$install_log 2>&1 -if [[ $? != 0 ]] +if ! make -j >> "$install_log" 2>&1 then - zenity --title="$title" --width=370 --height=400 --error --text=$'Compile error' 2>/dev/null + zenity --title="$title" --width=370 --height=400 --error --text="Compile error" 2> /dev/null exit_install exit fi -echo "90 " > $zen_pipe -echo "#Installing Geeqie..." > $zen_pipe +printf '%b\n' "90 " > "$zen_pipe" +printf '%b\n' "#Installing Geeqie..." > "$zen_pipe" -sudo --askpass make install >>$install_log 2>&1 +# shellcheck disable=SC2024 +sudo --askpass make install >> "$install_log" 2>&1 -rm $install_pass_script -mv -f $install_log install.log; +rm "$install_pass_script" +mv -f "$install_log" install.log -echo "100 " > $zen_pipe -rm $zen_pipe +printf '%b\n' "100 " > "$zen_pipe" +rm "$zen_pipe" -(for i in $(seq 0 4 100); do echo "$i"; sleep 0.1; done) | zenity --progress --title="$title" --width=370 --text="Geeqie installation complete...\n$zonedetect_message" --auto-close --percentage=0 2>/dev/null +(for i in $(seq 0 4 100) +do + printf '%b\n' "$i" + sleep 0.1 +done) | zenity --progress --title="$title" --width=370 --text="Geeqie installation complete...\n" --auto-close --percentage=0 2> /dev/null exit diff --git a/gen_changelog.sh b/gen_changelog.sh index 2d42d135..e74bd592 100755 --- a/gen_changelog.sh +++ b/gen_changelog.sh @@ -1,7 +1,7 @@ #!/bin/sh ## @file -## @brief Script to update ChangeLog file +## @brief Update ChangeLog file ## - it keeps "pre-svn" history and inserts git log at top, ## - it uses C locale for date format. ## - It has to be run where ChangeLog.gqview is. diff --git a/gen_readme.sh b/gen_readme.sh index 5ebf1722..4ffa1239 100755 --- a/gen_readme.sh +++ b/gen_readme.sh @@ -1,20 +1,20 @@ -#!/bin/bash +#!/bin/sh ## @file ## @brief Convert README.md to README.html ## -## Script to create README.html file, +## Ceate README.html file, ## if [ ! -e "README.md" ] then - echo "ERROR: README.md not found" + printf '%s\n' "ERROR: README.md not found" exit 1 fi -if [ ! -x "$(command -v pandoc)" ] +if ! command -v pandoc > /dev/null 2>&1 then - echo "ERROR: File pandoc not installed" + printf '%s\n' "ERROR: File pandoc not installed" exit 1 fi diff --git a/plugins/camera-import/geeqie-camera-import b/plugins/camera-import/geeqie-camera-import index 2054b677..7dd131ab 100755 --- a/plugins/camera-import/geeqie-camera-import +++ b/plugins/camera-import/geeqie-camera-import @@ -1,38 +1,35 @@ -#!/bin/bash +#!/bin/sh ## @file ## @brief Import all images from camera ## ## Requires gphoto2 ## - -function finish +finish() { if [ -f /tmp/geeqie-camera-import-files ] then rm /tmp/geeqie-camera-import-files fi - if [ -p $zen_pipe ] + if [ -p "$zen_pipe" ] then - rm $zen_pipe + rm "$zen_pipe" fi if [ "$gphoto2_pid" != "" ] then - ps -p $gphoto2_pid > /dev/null - if [ $? -eq 0 ] + if ps -p "$gphoto2_pid" > /dev/null then - kill $gphoto2_pid + kill "$gphoto2_pid" fi fi if [ "$zen_pid" != "" ] then - ps -p $zen_pid > /dev/null - if [ $? -eq 0 ] + if ps -p "$zen_pid" > /dev/null then - kill $zen_pid + kill "$zen_pid" fi fi } @@ -40,7 +37,7 @@ trap finish EXIT if ! [ -x "$(command -v gphoto2)" ] then - zenity --title="Geeqie camera import" --info --width=200 --text="gphoto2 is not installed" 2>/dev/null + zenity --title="Geeqie camera import" --info --width=200 --text="gphoto2 is not installed" 2> /dev/null exit 0 fi @@ -49,34 +46,35 @@ then rm /tmp/geeqie-camera-import.log fi -if [ $(gphoto2 --auto-detect | wc -l) -le 2 ] +if [ "$(gphoto2 --auto-detect | wc -l)" -le 2 ] then - zenity --error --title="Geeqie camera import" --text="No camera detected" --window-icon=/usr/local/share/pixmaps/geeqie.png --width=250 2>/dev/null + zenity --error --title="Geeqie camera import" --text="No camera detected" --window-icon=/usr/local/share/pixmaps/geeqie.png --width=250 2> /dev/null exit 0 fi -list=$(gphoto2 --auto-detect | tail +3) -readarray -t split_list <<<"$list" +IFS=' +' +list=$(gphoto2 --auto-detect | tail -n +3) camera_list="" n=1 -count=$(gphoto2 --auto-detect | tail +3 | wc -l) -if [[ $count -gt 1 ]] +count=$(gphoto2 --auto-detect | tail -n +3 | wc -l) +if [ "$count" -gt 1 ] then - for camera in "${split_list[@]}" + for camera in $list do - if [[ $n -eq $count ]] + if [ "$n" -eq "$count" ] then - camera_list="$camera_list"$'TRUE\n'"$camera"$'\n'"$n" + camera_list="${camera_list:+${camera_list}}TRUE\n$camera\n$n" else - camera_list="$camera_list"$'FALSE\n'"$camera"$'\n'"$n"$'\n' + camera_list="${camera_list:+${camera_list}}FALSE\n$camera\n$n\n" fi - n=$((n+1)) + n=$((n + 1)) done - camera_selected=$(echo "$camera_list" | zenity --width=500 --height=250 --title="Geeqie camera import" --list --text "Select camera" --radiolist --column "Select" --column "Camera" --column "n" --hide-column=3 --print-column=2 2>/dev/null) + camera_selected=$(printf '%b' "$camera_list" | zenity --width=500 --height=250 --title="Geeqie camera import" --list --text "Select camera" --radiolist --column "Select" --column "Camera" --column "n" --print-column=2 2> /dev/null) - if [[ $? == 1 ]] + if [ $? = 1 ] then exit 0 fi @@ -84,58 +82,56 @@ else camera_selected=$(gphoto2 --auto-detect | tail +3) fi -port_type=$(echo $camera_selected |awk -F ':' '{print $1}' | awk '{print $NF}') -camera=$(echo $camera_selected | awk -F $port_type '{print $1}') -port_address=$(echo $camera_selected | awk -F ':' '{print $2}') +port_type=$(printf '%s\n' "$camera_selected" | awk -F ':' '{print $1}' | awk '{print $NF}') +camera=$(printf '%s\n' "$camera_selected" | awk -F "$port_type" '{print $1}') +port_address=$(printf '%s\n' "$camera_selected" | awk -F ':' '{print $2}') port="$port_type:$port_address" script_dir=$(dirname "$0") -zenity --question --title="Geeqie camera import" --text="Camera: $camera\n\nDownloading to folder:\n$PWD" --ok-label="OK" --cancel-label="Cancel" --window-icon=/usr/local/share/pixmaps/geeqie.png --width=350 2>/dev/null - -if [[ $? == 1 ]] +if ! zenity --question --title="Geeqie camera import" --text="Camera: $camera\n\nDownloading to folder:\n$PWD" --ok-label="OK" --cancel-label="Cancel" --window-icon=/usr/local/share/pixmaps/geeqie.png --width=350 2> /dev/null then exit 0 fi -src_files_sorted=$(mktemp --tmpdir geeqie_camera_import_camera_files_sorted_XXXXXX) -dest_files_sorted=$(mktemp --tmpdir geeqie_camera_import_computer_files_sorted_XXXXXX) +src_files_sorted=$(mktemp -d "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX") +dest_files_sorted=$(mktemp -d "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX") ( -gphoto2 --port "$port" --list-files 2>/tmp/geeqie-camera-import.log | awk '/#/ {print $2}' | sort > $src_files_sorted -) | zenity --progress --auto-close --auto-kill --title="Geeqie camera import" --text="Searching for files to download..." --pulsate --window-icon=/usr/local/share/pixmaps/geeqie.png --width=250 + gphoto2 --port "$port" --list-files 2> /tmp/geeqie-camera-import.log | awk '/#/ {print $2}' | sort > "$src_files_sorted" +) | zenity --progress --auto-close --auto-kill --title="Geeqie camera import" --text="Searching for files to download..." --pulsate --window-icon=/usr/local/share/pixmaps/geeqie.png --width=250 error=$(grep -i error /tmp/geeqie-camera-import.log) -if [ ! -z "$error" ] +if [ -n "$error" ] then - cat /tmp/geeqie-camera-import.log | zenity --text-info --title="Geeqie camera import" - --window-icon=error --width=250 2>/dev/null + zenity --text-info --title="Geeqie camera import" - --window-icon=error --width=250 < /tmp/geeqie-camera-import.log 2> /dev/null exit 1 fi -ls -1 | sort > $dest_files_sorted -existing_file_count=$(comm -12 $src_files_sorted $dest_files_sorted | wc -l) +find . -maxdepth 1 -type f | sort > "$dest_files_sorted" +existing_file_count=$(comm -12 "$src_files_sorted" "$dest_files_sorted" | wc -l) -repeated=$(uniq --repeated $src_files_sorted) -if [ ! -z "$repeated" ] +repeated=$(uniq --repeated "$src_files_sorted") +if [ -n "$repeated" ] then repeated="Warning: The following source filenames are not unique.\nSome files may not be downloaded.\nSee the Help file.\n\n$repeated" - zenity --question --text="$repeated" --title="Geeqie camera import" --cancel-label="OK" --ok-label="Cancel" --width=400 --window-icon=/usr/local/share/pixmaps/geeqie.png 2>/dev/null - if [[ $? == 0 ]] + + if zenity --question --text="$repeated" --title="Geeqie camera import" --cancel-label="OK" --ok-label="Cancel" --width=400 --window-icon=/usr/local/share/pixmaps/geeqie.png 2> /dev/null then exit 1 fi fi -total=$(cat $src_files_sorted | wc -l) -files_to_load=$(( $total - $existing_file_count )) +total=$(wc -l < "$src_files_sorted") +files_to_load=$((total - existing_file_count)) -rm $src_files_sorted -rm $dest_files_sorted +rm "$src_files_sorted" +rm "$dest_files_sorted" if [ "$files_to_load" -eq 0 ] then - zenity --info --title="Geeqie camera download" --text="No photos to download" --width=250 --window-icon=usr/local/share/pixmaps/geeqie.png 2>/dev/null + zenity --info --title="Geeqie camera download" --text="No photos to download" --width=250 --window-icon=usr/local/share/pixmaps/geeqie.png 2> /dev/null exit 0 fi @@ -145,29 +141,29 @@ then fi touch /tmp/geeqie-camera-import-files -zen_pipe=$(mktemp --dry-run --tmpdir geeqie_camera_import_pipe_XXXXXX) -mkfifo $zen_pipe +zen_pipe=$(mktemp -u "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX") +mkfifo "$zen_pipe" -gphoto2 --port "$port" --hook-script "$script_dir/"geeqie-camera-import-hook-script --get-all-files --skip-existing 2>/tmp/geeqie-camera-import.log & +gphoto2 --port "$port" --hook-script "$script_dir/"geeqie-camera-import-hook-script --get-all-files --skip-existing 2> /tmp/geeqie-camera-import.log & gphoto2_pid=$! -(tail -f $zen_pipe 2>/dev/null) | zenity --progress --title="Geeqie camera import" --width=370 --text="Downloading: total: $files_to_load existing: $existing_file_count\n" --auto-close --auto-kill --percentage=0 window-icon=/usr/local/share/pixmaps/geeqie.png 2>/dev/null & +(tail -f "$zen_pipe" 2> /dev/null) | zenity --progress --title="Geeqie camera import" --width=370 --text="Downloading: total: $files_to_load existing: $existing_file_count\n" --auto-close --auto-kill --percentage=0 window-icon=/usr/local/share/pixmaps/geeqie.png 2> /dev/null & zen_pid=$! n=0 -while [ -f /tmp/geeqie-camera-import-files ] && [ "$n" -lt 100 ] +while [ -f /tmp/geeqie-camera-import-files ] && [ "$n" -lt 100 ] do - i=$(cat "/tmp/geeqie-camera-import-files" | wc -l) - n=$(( $((i * 100)) / $files_to_load)) - echo "$n" >$zen_pipe + i=$(wc -l < "/tmp/geeqie-camera-import-files") + n=$(($((i * 100)) / files_to_load)) + printf '%s\n' "$n" > "$zen_pipe" latest_file=$(tail -n 1 /tmp/geeqie-camera-import-files) if [ -z "$latest_file" ] then latest_file="Skipping existing files, if any..." fi - echo "#Downloading: total: $files_to_load existing: $existing_file_count\n$latest_file" >$zen_pipe + printf '#Downloading: total: %s existing: %s\n%s' "$files_to_load existing" "$existing_file_count" "$latest_file" > "$zen_pipe" sleep 1 done diff --git a/plugins/camera-import/geeqie-camera-import-hook-script b/plugins/camera-import/geeqie-camera-import-hook-script index 5ddb7766..d89cbd9c 100755 --- a/plugins/camera-import/geeqie-camera-import-hook-script +++ b/plugins/camera-import/geeqie-camera-import-hook-script @@ -1,14 +1,14 @@ -#!/bin/bash +#!/bin/sh ## @file ## @brief Camera import hook script ## -if [ "$ACTION" == "download" ] +if [ "$ACTION" = "download" ] then - echo "$ARGUMENT" >> /tmp/geeqie-camera-import-files + printf '%s\n' "$ARGUMENT" >> /tmp/geeqie-camera-import-files -elif [ "$ACTION" == "stop" ] +elif [ "$ACTION" = "stop" ] then zenity --info --title="Geeqie camera download" --text="Import ended" --width=200 --timeout=5 --window-icon=usr/local/share/pixmaps/geeqie.png 2>/dev/null if [ -f /tmp/geeqie-camera-import-files ] diff --git a/plugins/export-jpeg/geeqie-export-jpeg b/plugins/export-jpeg/geeqie-export-jpeg index 3396592d..088979a1 100755 --- a/plugins/export-jpeg/geeqie-export-jpeg +++ b/plugins/export-jpeg/geeqie-export-jpeg @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh ## @file ## @brief Extract embedded jpegs from a raw file @@ -10,14 +10,6 @@ ## - Set Geeqie focus to the newly generated image ## -count=$(exiv2 -pp "$1" | wc -l) - -if [[ $count -eq 0 ]] -then - zenity --info --width=300 --height=100 --text="Export jpeg from raw file\n\nFile contains no embedded images" --title="Geeqie export jpeg" 2>/dev/null - exit -fi - if ! [ -x "$(command -v exiv2)" ] then zenity --info --width=300 --height=100 --text="Export jpeg from raw file\n\nexiv2 is not installed" --title="Geeqie export jpeg" 2>/dev/null @@ -29,28 +21,36 @@ then zenity --info --width=300 --height=100 --text="Export jpeg from raw file\n\njpgicc is not installed\ncolor corrections will not be made\nYou may install via liblcms2-utils" --title="Geeqie export jpeg" 2>/dev/null fi -list=$(exiv2 -pp "$1") -readarray -t split_list <<<"$list" +count=$(exiv2 -pp "$1" | wc -l) +if [ "$count" -eq 0 ] +then + zenity --info --width=300 --height=100 --text="Export jpeg from raw file\n\nFile contains no embedded images" --title="Geeqie export jpeg" 2>/dev/null + exit 1 +fi + +IFS=' +' +list=$(exiv2 -pp "$1") image_list="" n=1 -for image in "${split_list[@]}" +for image in $list do - if [[ $n -eq $count ]] + if [ "$n" -eq "$count" ] then - image_list="$image_list"$'TRUE\n'"$image"$'\n'"$n" + image_list="${image_list:+${image_list}}TRUE\n$image\n$n" else - image_list="$image_list"$'FALSE\n'"$image"$'\n'"$n"$'\n' + image_list="${image_list:+${image_list}}FALSE\n$image\n$n\n" fi - n=$((n+1)) + n=$((n + 1)) done image_selected=$(echo "$image_list" | zenity --width=500 --height=250 --title="Geeqie export jpeg" --list --text "Select embedded image" --radiolist --column "Select" --column "Image" --column "n" --hide-column=3 --print-column=3 2>/dev/null) -if [[ ! -z "$image_selected" ]] +if [ -n "$image_selected" ] then - tmpdir=$(mktemp --tmpdir --directory geeqie_export_jpeg_XXXXXX) + tmpdir=$(mktemp -d "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX") exiv2 --location "$tmpdir" -ep"$image_selected" "$1" diff --git a/plugins/geocode-parameters/geocode-parameters.awk b/plugins/geocode-parameters/geocode-parameters.awk index 2f2a2621..e1be292c 100644 --- a/plugins/geocode-parameters/geocode-parameters.awk +++ b/plugins/geocode-parameters/geocode-parameters.awk @@ -1,7 +1,7 @@ #!/usr/bin/awk -f # ## @file -## @brief This file is used by the Search option "search on geo-position". +## @brief Used by the Search option "search on geo-position". ## ## It is used to decode the results of internet or other searches ## to extract a geo-position from a text string. diff --git a/plugins/image-crop/geeqie-image-crop b/plugins/image-crop/geeqie-image-crop old mode 100644 new mode 100755 index feb08e9d..0cc9dcbc --- a/plugins/image-crop/geeqie-image-crop +++ b/plugins/image-crop/geeqie-image-crop @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh ## @file ## @brief Crop image @@ -9,14 +9,13 @@ process_raw () { - tmpdir=$(mktemp --tmpdir --directory geeqie_crop_image_XXXXXX) + tmpdir=$(mktemp -d "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX") - list=$(exiv2 -pp "$1") - if [[ ! -z "$list" ]] - then - readarray -t split_list <<<"$list" + array_length=$(exiv2 -pp "$1" | wc -l) - array_length="${#split_list[@]}" + if [ "$array_length" -gt 0 ] + then + # Take last item - should be highest resolution exiv2 --location "$tmpdir" -ep"$array_length" "$1" src_filename=$(ls "$tmpdir/") @@ -25,7 +24,7 @@ process_raw () rotation=$(exiftool -Orientation -n "$1" | cut -d':' -f2 | xargs) convert "$tmpdir/$src_filename" -crop "$2" "$tmpdir/$filename-crop.$extension" - exiftool -Orientation=$rotation -n "$tmpdir/$filename-crop.$extension" + exiftool -Orientation="$rotation" -n "$tmpdir/$filename-crop.$extension" rm "$tmpdir/$src_filename" @@ -40,7 +39,7 @@ process_raw () process_plain () { - tmpdir=$(mktemp --tmpdir --directory geeqie_crop_image_XXXXXX) + tmpdir=$(mktemp -d "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX") src_filename=$(basename -- "$1") filename="${src_filename%.*}" @@ -67,45 +66,40 @@ then if [ -z "$coords" ] then - zenity --error --title="$title" --text="Rectangle coordinates have not been set" --width="$width" --window-icon="$window_icon" 2>/dev/null + zenity --error --title="$title" --text="Rectangle coordinates have not been set" --width="$width" --window-icon="$window_icon" 2> /dev/null exit 0 fi filename=$(basename -- "$1") - extension="${filename##*.}" - - if [ "${extension,,}" = "jpeg" ] + extension=$(printf '%b' "${filename##*.}" | tr '[:upper:]' '[:lower:]') + if [ "${extension}" = "jpeg" ] then - source_file="$1" - process_plain "$1" $coords - elif [ "${extension,,}" = "jpg" ] + process_plain "$1" "$coords" + elif [ "${extension}" = "jpg" ] then - source_file="$1" - process_plain "$1" $coords - elif [ "${extension,,}" = "png" ] + process_plain "$1" "$coords" + elif [ "${extension}" = "png" ] then - source_file="$1" - process_plain "$1" $coords - elif [ "${extension,,}" = "tif" ] + process_plain "$1" "$coords" + elif [ "${extension}" = "tif" ] then - source_file="$1" - process_plain "$1" $coords - elif [ "${extension,,}" = "tiff" ] + process_plain "$1" "$coords" + elif [ "${extension}" = "tiff" ] then - source_file="$1" - process_plain "$1" $coords + process_plain "$1" "$coords" else - process_raw "$1" $coords + process_raw "$1" "$coords" if [ $? = 1 ] then - process_plain "$1" $coords + process_plain "$1" "$coords" fi fi else - zenity --info --title="$title" --width="$width" --height=100 --text="Crop image\n\nexiftool is not installed" --title="$title" --window-icon="$window_icon" 2>/dev/null + zenity --info --title="$title" --width="$width" --height=100 --text="Crop image\n\nexiftool is not installed" --title="$title" --window-icon="$window_icon" 2> /dev/null exit 0 fi else - zenity --info --title="$title" --width="$width" --height=100 --text="Crop image\n\nImageMagick is not installed" --title="$title" --window-icon="$window_icon" 2>/dev/null + zenity --info --title="$title" --width="$width" --height=100 --text="Crop image\n\nImageMagick is not installed" --title="$title" --window-icon="$window_icon" 2> /dev/null exit 0 fi + diff --git a/plugins/random-image/geeqie-random-image b/plugins/random-image/geeqie-random-image index ccfd3119..8f221f29 100755 --- a/plugins/random-image/geeqie-random-image +++ b/plugins/random-image/geeqie-random-image @@ -1,59 +1,64 @@ -#!/bin/bash +#!/bin/sh ## @file ## @brief Select and display a random image from a list of all images ## in Collections and the currently displayed folder ## +IFS=' +' + # get list of images in all collections collection_list=$(geeqie --remote --get-collection-list) -OLDIFS=$IFS -while IFS= read -r line + +for collection_name in $collection_list do - collection=$(geeqie --remote --get-collection:"$line") - list="$list""$collection"$'\n' -done <<< "$collection_list" -IFS=$OLDIFS + collection_file_list=$(geeqie --remote --get-collection:"$collection_name") + for collection_file in $collection_file_list + do + list="${list:+${list}}\n${collection_file}" + done +done # get list of images in current folder file_list=$(geeqie --remote --get-filelist:) -OLDIFS=$IFS -while IFS= read -r line + +for file_name in $file_list do - class_whitespace="${line##*Class:}" + class_whitespace="${file_name##*Class:}" class="${class_whitespace#"${class_whitespace%%[![:space:]]*}"}" - if [ "$class" == "Image" ] + if [ "$class" = "Image" ] then - list="$list""${line%%Class*}"$'\n' + list="$list${file_name%%Class*}\n" fi - if [ "$class" == "RAW Image" ] + if [ "$class" = "RAW Image" ] then - list="$list""${line%%Class*}"$'\n' + list="$list""${file_name%%Class*}\n" fi -done <<< "$file_list" -IFS=$OLDIFS +done # remove blank lines -files_no_blanks=$(echo "$list" | sed -e 's/^[[:blank:]]*$//') +files_no_blanks=$(printf '%b\n' "$list" | sed -e 's/^[[:blank:]]*$//') + # remove leading trailing whitespace -files_no_spaces=$(echo "$files_no_blanks" | sed 's/^[ \t]*//;s/[ \t]*$//') +files_no_spaces=$(printf '%b\n' "$files_no_blanks" | sed 's/^[ \t]*//;s/[ \t]*$//') # remove duplicate lines and select random line -display_image="$(echo "$files_no_spaces" | sort --uniq | shuf -n 1)" +display_image=$( (printf '%b\n' "$files_no_spaces") | sort --uniq | shuf -n 1) # get image currently displayed current_image_collection=$(geeqie --remote --tell) # remove collection name, if it is there current_image_spaces="${current_image_collection%%Collection:*}" # remove leading trailing whitespace -curent_image=$(echo "$current_image_spaces" | sed 's/^[ \t]*//;s/[ \t]*$//') +current_image=$(printf '%b\n' "$current_image_spaces" | sed 's/^[ \t]*//;s/[ \t]*$//') # if the selected random image is currently displayed, try again -if [ "$current_image" == "$display_image" ] +if [ "$current_image" = "$display_image" ] then - display_image="$(echo "$files_no_spaces" | sort --uniq | shuf -n 1)" + display_image=$(printf '%b' "$files_no_spaces" | sort --uniq | shuf -n 1) fi geeqie --remote file:"$display_image" diff --git a/plugins/rotate/geeqie-rotate b/plugins/rotate/geeqie-rotate index fcca7aed..1a6f0da2 100755 --- a/plugins/rotate/geeqie-rotate +++ b/plugins/rotate/geeqie-rotate @@ -82,7 +82,7 @@ rotate_image_file() ;; tif|tiff|png) - mogrify $2 "$3" + mogrify "$2" "$3" [ $? != 0 ] && return 7 return 0; ;; @@ -153,7 +153,7 @@ for file in "$@" ; do if [ -n "$get_sidecars" ] ; then # 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 [ ! -w "$sidecar" ] && exit 5 rotate "$sidecar" @@ -166,7 +166,7 @@ for file in "$@" ; do [ ! -w "$file" ] && exit 5 if [ -n "$rotate_image_file" ] ; then if [ -n "$preserve_mtime" ] ; then - mtime=`mktemp /tmp/geeqie-rotate.XXXXXXXXXX` || exit 3 + mtime=`mktemp "${TMPDIR:-/tmp}/geeqie-rotate.XXXXXXXXXX"` || exit 3 touch --reference="$file" "$mtime" fi diff --git a/plugins/symlink/geeqie-symlink b/plugins/symlink/geeqie-symlink index 9b2ea090..51504e12 100755 --- a/plugins/symlink/geeqie-symlink +++ b/plugins/symlink/geeqie-symlink @@ -1,7 +1,7 @@ #!/bin/sh ## @file -## @brief This is a helper script that symlinks grouped files +## @brief Symlink grouped files ## ## It uses geeqie remote connection to get details about grouped files ## diff --git a/plugins/tethered-photography/geeqie-tethered-photography b/plugins/tethered-photography/geeqie-tethered-photography index 4d04aff1..380c6ff1 100755 --- a/plugins/tethered-photography/geeqie-tethered-photography +++ b/plugins/tethered-photography/geeqie-tethered-photography @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh ## @file ## @brief Simple tethered photography helper @@ -12,7 +12,7 @@ ## gphoto2=filename= ## -n=$(ps -e | grep "geeqie-tethered" | wc -l) +n=$(pgrep "geeqie-tethered" | wc -l) if [ "$n" -ge 3 ] then exit 0 @@ -24,7 +24,7 @@ then exit 0 fi -if [ $(gphoto2 --auto-detect | wc -l) -le 2 ] +if [ "$(gphoto2 --auto-detect | wc -l)" -le 2 ] then zenity --error --title="Geeqie tethered photography" --text="No camera detected" --window-icon=/usr/local/share/pixmaps/geeqie.png --width=250 2>/dev/null exit 0 @@ -34,18 +34,18 @@ notify-send --expire-time=2000 "$(gphoto2 --auto-detect | sed -n '3p')" --icon=g script_dir=$(dirname "$0") -tmpfile=$(mktemp --tmpdir geeqie_tethered_photography_XXXXXX) +tmpfile=$(mktemp "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX") -yes n | gphoto2 --hook-script "$script_dir/"geeqie-tethered-photography-hook-script --capture-tethered >$tmpfile & +yes n | gphoto2 --hook-script "$script_dir/"geeqie-tethered-photography-hook-script --capture-tethered >"$tmpfile" & gphoto2_pid=$! zenity --question --title="Geeqie tethered photography" --ok-label="Stop" --cancel-label="Show log data" --text="Tethered photography is running.\n\n\nDownloading to folder:\n""$PWD\n\n\nExisting files will not be overwritten,\nbut the download will not take place.\n\n(Use gphoto2 --filename default option\nfor auto-rename on download)" --width=300 --window-icon=/usr/local/share/pixmaps/geeqie.png 2>/dev/null -if [ $? == 1 ] +if [ $? = 1 ] 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 + 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 -rm $tmpfile +rm "$tmpfile" diff --git a/plugins/tethered-photography/geeqie-tethered-photography-hook-script b/plugins/tethered-photography/geeqie-tethered-photography-hook-script index 0f8dc488..6b83e1c2 100755 --- a/plugins/tethered-photography/geeqie-tethered-photography-hook-script +++ b/plugins/tethered-photography/geeqie-tethered-photography-hook-script @@ -1,10 +1,10 @@ -#!/bin/bash +#!/bin/sh ## @file ## @brief Tethered photography hook script ## -if [ "$ACTION" == "download" ] +if [ "$ACTION" = "download" ] then notify-send --expire-time=4000 "$ARGUMENT" --icon=geeqie geeqie --remote File:"$PWD/$ARGUMENT" diff --git a/po/gen_translations_stats.sh b/po/gen_translations_stats.sh index e1c90d6e..1888f493 100755 --- a/po/gen_translations_stats.sh +++ b/po/gen_translations_stats.sh @@ -1,14 +1,14 @@ -#!/bin/bash +#!/bin/sh ## @file -## @brief This script prints translations statistics for .po files +## @brief Print translations statistics for .po files ## existing in the current directory ## export LC_ALL=C echo "Translations statistics" -echo "Date: "$(date -R) +echo "Date: $(date -R)" echo echo "Note: completion % in the chart below may not be quite correct" @@ -19,7 +19,7 @@ echo (echo "Language Comp(%) Trans Fuzzy Untrans Total"; \ for i in *.po; do - msgfmt --statistics -o /dev/null $i 2>&1 \ + msgfmt --statistics -o /dev/null "$i" 2>&1 \ | perl -ne ' my ($tr_done, $tr_fuzz, $tr_un) = (0, 0, 0); $tr_done = $1 if /(\d+) translated messages?/; diff --git a/scripts/check-compiles.sh b/scripts/check-compiles.sh index 03c0e39b..734c5402 100755 --- a/scripts/check-compiles.sh +++ b/scripts/check-compiles.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh #/* # * Copyright (C) 2021 The Geeqie Team @@ -27,44 +27,48 @@ compile() { - # Cannot have --enable-debug-flags with --disable-gtk3 + compiler="$1" - declare -A variant - variant[0]="$disable_list --disable-gtk3" - variant[1]="--disable-gtk3" - variant[2]="--enable-debug-flags $disable_list" - variant[3]="--enable-debug-flags" - variant[4]="$disable_list" - variant[5]="" + # Cannot have --enable-debug-flags with --disable-gtk3 + set -- "$disable_list --disable-gtk3" "--disable-gtk3" "$disable_list --enable-debug-flags" "--enable-debug-flags" "$disable_list" "" - for ((i = 0; i <= 5; i++)) + i=1 + while [ $i -le 6 ] do - if [[ "${variant[$i]}" =~ "gtk3" ]]; then + variant="" + eval variant="\$${i}" + + if [ "$variant" != "${variant%gtk3*}" ] + then gtk="GTK2" else gtk="GTK3" fi - if [[ "${variant[$i]}" =~ "disable-threads" ]]; then + if [ "$variant" != "${variant%disable-threads*}" ] + then disabled="all disabled" else disabled="none disabled" fi - if [[ "${variant[$i]}" =~ "--enable-debug-flags" ]]; then + if [ "$variant" != "${variant%--enable-debug-flags*}" ] + then debug_flags="enable-debug-flags" else debug_flags="" fi - echo -e " \e[32m $1 $gtk $debug_flags $disabled " + printf '\e[32m%s\n' "$compiler $gtk $debug_flags $disabled" sudo make maintainer-clean > /dev/null 2>&1 - ./autogen.sh "${variant[$i]}" > /dev/null 2>&1 + ./autogen.sh "$variant" > /dev/null 2>&1 make -j > /dev/null + + i=$((i+1)) done } -disable_list=" "$(awk --field-separator '[][]' '/AC_HELP_STRING\(\[--disable-/ {if ($2 != "gtk3") print $2}' configure.ac | tr '\n' ' ') +disable_list=" "$(awk -F '[][]' '/AC_HELP_STRING\(\[--disable-/ {if ($2 != "gtk3") print $2}' configure.ac | tr '\n' ' ') -echo "Disabled list: :$disable_list" +printf '%s\n' "Disabled list: :$disable_list" export CFLAGS="-Wno-deprecated-declarations" diff --git a/scripts/doxygen-help.sh b/scripts/doxygen-help.sh index e1c3ec55..75b00ca3 100755 --- a/scripts/doxygen-help.sh +++ b/scripts/doxygen-help.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh #********************************************************************** # Copyright (C) 2021 - The Geeqie Team @@ -51,13 +51,13 @@ ## Then run 'doxygen doxygen.conf' ## -if [[ -z "${DOCDIR}" ]] +if [ -z "${DOCDIR}" ] then - echo "Environment variable DOCDIR not set" + printf '%s\n' "Environment variable DOCDIR not set" zenity --title="Geeqie" --width=200 --warning --text="Environment variable DOCDIR not set" -elif [[ -z "${PROJECT}" ]] +elif [ -z "${PROJECT}" ] then - echo "Environment variable PROJECT not set" + printf '%s\n' "Environment variable PROJECT not set" zenity --title="Geeqie" --width=200 --warning --text="Environment variable PROJECT not set" else url_found=$(awk -v search_param="$1" -v docdir="$DOCDIR" ' @@ -96,7 +96,7 @@ else } ' "$DOCDIR"/"$PROJECT".tag) - if [[ -z $url_found ]] + if [ -z "$url_found" ] then exit 1 else diff --git a/scripts/generate-appimage.sh b/scripts/generate-appimage.sh index f5df698c..e8ff83de 100755 --- a/scripts/generate-appimage.sh +++ b/scripts/generate-appimage.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /bin/sh #********************************************************************** # Copyright (C) 2021 - The Geeqie Team # @@ -20,27 +20,27 @@ #********************************************************************** ## @file -## @brief This script will generate a Geeqie AppImage. +## @brief Generate a Geeqie AppImage. ## ## It must be run from the base Geeqie folder. ## The single parameter is the directory where the AppDir ## will be created. ## -if [[ ! -f geeqie.spec.in ]] || [[ ! -d .git ]] +if [ ! -f geeqie.spec.in ] || [ ! -d .git ] then - echo "This is not a Geeqie folder" + printf '%s\n' "This is not a Geeqie folder" exit 1 fi if ! target_dir=$(realpath "$1"); then - echo "No target dir specified" + printf '%s\n' "No target dir specified" exit 1 fi rm -rf "$target_dir"/AppDir -mkdir "$target_dir"/AppDir || { echo "Cannot make $target_dir/AppDir"; exit 1; } +mkdir "$target_dir"/AppDir || { printf '%s\n' "Cannot make $target_dir/AppDir"; exit 1; } sudo rm -rf doc/html @@ -52,7 +52,7 @@ make install DESTDIR="$target_dir"/AppDir VERSION=$(git tag | tail -1) export VERSION -cd "$target_dir" || { echo "Cannot cd to $target_dir"; exit 1; } +cd "$target_dir" || { printf '%s\n' "Cannot cd to $target_dir"; exit 1; } linuxdeploy-x86_64.AppImage \ --appdir ./AppDir --output appimage \ diff --git a/scripts/generate-man-page.sh b/scripts/generate-man-page.sh index 26efeff2..7794eb11 100755 --- a/scripts/generate-man-page.sh +++ b/scripts/generate-man-page.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh ## @file ## @brief Create the man page from the output of the "geeqie--help" command @@ -9,24 +9,22 @@ ## The programs help2man and doclifter are required - both are available as .deb packages. ## -command -v help2man > /dev/null -if [ $? -eq 1 ] +if ! command -v help2man > /dev/null then - echo "help2man not installed" - exit + printf '%s\n' "help2man not installed" + exit 1 fi -command -v doclifter > /dev/null -if [ $? -eq 1 ] +if ! command -v doclifter > /dev/null then - echo "doclifter not installed" - exit + printf '%s\n' "doclifter not installed" + exit 1 fi -options_file=$(mktemp) +options_file=$(mktemp "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX") year=$(date +"%Y") -echo "[NAME] +printf '%s\n' "[NAME] Geeqie - GTK based multiformat image viewer [DESCRIPTION] @@ -46,7 +44,6 @@ Copyright (C) 1999-2004 by John Ellis. Copyright (C) 2004-$year by The Geeqie Te own risk! This software released under the GNU General Public License. Please read the COPYING file for more information." > "$options_file" - help2man --no-info --include="$options_file" src/geeqie > geeqie.1 doclifter geeqie.1 diff --git a/scripts/keyword_merge.sh b/scripts/keyword_merge.sh index 7df21259..c533331c 100755 --- a/scripts/keyword_merge.sh +++ b/scripts/keyword_merge.sh @@ -1,8 +1,7 @@ -#!/bin/bash +#!/bin/sh ## @file -## @brief This is a simple script to merge the keyword tree of one Geeqie -## configuration file into another. +## @brief Merge the keyword tree of one Geeqie configuration file into another. ## ## The keyword trees are simply concatenated. When Geeqie loads ## the resulting configuration file, any duplicates are discarded. @@ -15,18 +14,18 @@ merge_file() flag=0 while read -r line_merge do - if [[ flag -eq 0 ]] + if [ $flag -eq 0 ] then - if [[ $line_merge =~ "" ]] + if [ "$line_merge" != "${line_merge%*}" ] then flag=1 fi else - if [[ $line_merge =~ "" ]] + if [ "$line_merge" != "${line_merge%*}" ] then flag=0 else - echo "$line_merge" >> "$2" + printf '%s\n' "$line_merge" >> "$2" fi fi done < "$1" @@ -34,51 +33,51 @@ done < "$1" np=$# -zenity --info --text="This script will merge the keywords from one Geeqie\nconfiguration file into another.\n\n\The command format is:\nmerge.sh {config. file to merge into} {config. file to merge from}\n\nIf you do not supply parameters, you are prompted.\n\nYou are given the option to backup the main config. file before it is overwritten with the merged data.\n\nEnsure that Geeqie is not running." --title="Geeqie merge keywords" --width=400 --height=200 -if [[ $? -eq 1 ]] +zenity --info --text="This script will merge the keywords from one Geeqie\nconfiguration file into another.\n\n\The command format is:\nkeyword_merge.sh {config. file to merge into} {config. file to merge from}\n\nIf you do not supply parameters, you are prompted.\n\nYou are given the option to backup the main config. file before it is overwritten with the merged data.\n\nEnsure that Geeqie is not running." --title="Geeqie merge keywords" --width=400 --height=200 +if [ $? -eq 1 ] then exit 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 ]] + if [ $? -eq 1 ] then exit fi config_merge=$(zenity --file-selection --file-filter="geeqierc.xml" --file-filter="*.xml" --file-filter="*"-- title="Select configuration file to merge from") - if [[ $? -eq 1 ]] + if [ $? -eq 1 ] 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 ]] + if [ $? -eq 1 ] then exit fi fi -tmp_file=$(mktemp) +tmp_file=$(mktemp "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX") while read -r line_main do - if [[ $line_main =~ "" ]] + if [ "$line_main" != "${line_merge%*}" ] then merge_file "$config_merge" "$tmp_file" fi - echo "$line_main" >> "$tmp_file" + printf '%s\n' "$line_main" >> "$tmp_file" done < "$config_main" -zenity --question --text="Backup configuration file before overwriting?" -if [[ $? -eq 0 ]] + +if zenity --question --text="Backup configuration file before overwriting?" then cp "$config_main" "$config_main.$(date +%Y%m%d%H%M%S)" fi diff --git a/scripts/new-release.sh b/scripts/new-release.sh index 5f68843a..1df9cf5f 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 @@ -19,7 +19,7 @@ if [ ! -d .git ] then - echo "Directory .git does not exist" + printf '%s\n' "Directory .git does not exist" exit 1 fi @@ -35,7 +35,7 @@ push= while getopts "v:s:p:hr" option; do case $option in h) - echo -e "-v release major.minor e.g 1.9\n-s start hash e.g. 728172681 (optional)\n-p release patch version e.g. 2 for 1.6.2\n-r push to repo.\n-h help" + printf '%s\n%s\n%s\n%s\n%s\n' "-v release major.minor e.g 1.9" "-s start hash e.g. 728172681 (optional)" "-p release patch version e.g. 2 for 1.6.2" "-r push to repo." "-h help" exit 0 ;; v) version="$OPTARG" ;; @@ -48,13 +48,13 @@ done if [ "$start" ] && [ "$patch" ] then - echo "Cannot have start-hash and patch number together" + printf '%s\n' "Cannot have start-hash and patch number together" exit 1 fi -if [ "$(echo "$version" | awk -F"." '{print NF-1}')" -ne 1 ] +if [ "$(printf '%s\n' "$version" | awk -F"." '{print NF-1}')" -ne 1 ] then - echo "Version major.minor $version is not valid" + printf '%s\n' "Version major.minor $version is not valid" exit 1 fi @@ -62,7 +62,7 @@ if [ "$start" ] then if ! git branch master --contains "$start" > /dev/null 2>&1 then - echo "Start hash is not in master branch" + printf '%s\n' "Start hash is not in master branch" exit 1 fi fi @@ -71,19 +71,19 @@ if [ "$patch" ] then if ! git rev-parse "v$version" > /dev/null 2>&1 then - echo "Version $version does not exist" + printf '%s\n' "Version $version does not exist" exit 1 fi - if [[ ! $patch =~ ^-?[0-9]+$ ]] + if ! [ "$patch" -ge 0 ] 2>/dev/null then - echo "Patch $patch is not an integer" + printf '%s\n' "Patch $patch is not an integer" exit 1 fi else if git rev-parse "v$version" > /dev/null 2>&1 then - echo "Version $version already exists" + printf '%s\n' "Version $version already exists" exit 1 fi fi diff --git a/scripts/template-desktop.sh b/scripts/template-desktop.sh index 25940f29..273cef83 100755 --- a/scripts/template-desktop.sh +++ b/scripts/template-desktop.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#!/bin/sh ## @file @@ -7,7 +7,7 @@ ## This needs to be run only when the menus have changed. ## -tmp_file=$(mktemp) +tmp_file=$(mktemp "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX") path=$(dirname "$(realpath "$0")") srcpath=$(dirname "$path")/src/layout_util.c templatepath=$(dirname "$path")/plugins/template.desktop.in @@ -78,12 +78,10 @@ function get_menus() (template_flag == 0) {print} ' "$templatepath" > "$tmp_file" -cat $tmp_file -echo $PWD +cat "$tmp_file" +printf '%s\n' "$PWD" -diff --unified=0 "./plugins/template.desktop.in" "$tmp_file" | zenity --title="Plugin template update" --text-info --width=700 --height=400 - -if [ "$?" == 0 ] +if diff --unified=0 "./plugins/template.desktop.in" "$tmp_file" | zenity --title="Plugin template update" --text-info --width=700 --height=400 then mv "$tmp_file" "$templatepath" else diff --git a/scripts/untranslated-text.sh b/scripts/untranslated-text.sh index cb13cfca..37388186 100755 --- a/scripts/untranslated-text.sh +++ b/scripts/untranslated-text.sh @@ -1,7 +1,7 @@ -#!/bin/bash +#!/bin/sh ## @file -## @brief A simple script to locate strings not marked for translation +## @brief Locate strings not marked for translation ## ## Checks all .c files under ./src ## @@ -13,6 +13,6 @@ for file in src/*.c src/view_file/*.c do for search_text in "label" "menu_item_add" "tooltip" "_button" "_text" do - cat -n "$file" | grep --extended-regexp --ignore-case "$search_text.*\(\"" | grep --invert-match "_(" | grep --invert-match "(\"\")" && echo -e "$file \n" + cat -n "$file" | grep --extended-regexp --ignore-case "$search_text.*\(\"" | grep --invert-match "_(" | grep --invert-match "(\"\")" && printf '%s\n\n' "$file" done done diff --git a/scripts/web-help.sh b/scripts/web-help.sh index 4a9fb1e0..00292325 100755 --- a/scripts/web-help.sh +++ b/scripts/web-help.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh ## @file ## @brief Update the Geeqie webpage Help files @@ -25,18 +25,18 @@ if [ ! -d ".git" ] || [ ! -d "src" ] || [ ! -f "geeqie.1" ] then - echo "This is not a Geeqie project folder" + printf '%s\n' "This is not a Geeqie project folder" exit 1 fi if [ ! -d "../geeqie.github.io/.git" ] || [ ! -d "../geeqie.github.io/help" ] then - echo "The Geeqie webpage project folder geeqie.github.io was not found" + printf '%s\n' "The Geeqie webpage project folder geeqie.github.io was not found" exit 1 fi rm -rf doc/html -tmpdir=$(mktemp --tmpdir --directory) +tmpdir=$(mktemp -d "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX") make -j install DESTDIR="$tmpdir" rm -r "$tmpdir" diff --git a/version.sh b/version.sh index fb527419..2fe3fde2 100755 --- a/version.sh +++ b/version.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh ## @file ## @brief Generate the Geeqie version number @@ -22,27 +22,27 @@ if [ -d .git ] then branch=$(git rev-parse --abbrev-ref HEAD) - if [ "$branch" == "master" ] + if [ "$branch" = "master" ] then - IFS=$'.' -# shellcheck disable=SC2046 + IFS='.' + # shellcheck disable=SC2046 set -- $(git tag --list v[1-9]* | tail -n 1 | tr -d 'v') major_version=$1 minor_version=$2 # patch_version=$3 # not used on master branch - echo "$major_version" && echo "." && echo "$minor_version" && echo "+git" && git log --max-count=1 --date=format:"%Y%m%d" --format="%ad" && echo "-" && git rev-parse --quiet --verify --short HEAD + printf '%s' "$major_version" && printf '%s' "." && printf '%s' "$minor_version" && printf '%s' "+git" && git log --max-count=1 --date=format:"%Y%m%d" --format="%ad" && printf '%s' "-" && git rev-parse --quiet --verify --short HEAD else version=$(head -1 NEWS) -# shellcheck disable=SC2086 + # shellcheck disable=SC2086 set -- $version - echo "$2" + printf '%s' "$2" fi else version=$(head -1 NEWS) -# shellcheck disable=SC2086 + # shellcheck disable=SC2086 set -- $version - echo "$2" + printf '%s' "$2" fi -- 2.20.1