From d5b0f3b2ef5070095a38d2905a999181e4c42b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edouard=20Choini=C3=A8re?= <27212526+echoix@users.noreply.github.com> Date: Sun, 17 Nov 2024 03:28:08 +0000 Subject: [PATCH] macosx: Address shellcheck warnings and format with shfmt `shfmt -w -s -i 4 -ci -bn -sr .` --- macosx/app/build_gui_user_menu.sh | 86 ++++++++++--------- macosx/app/build_html_user_index.sh | 123 +++++++++++++--------------- macosx/app/python_wrapper | 26 +++--- 3 files changed, 113 insertions(+), 122 deletions(-) diff --git a/macosx/app/build_gui_user_menu.sh b/macosx/app/build_gui_user_menu.sh index e4bc6e7f250..713c5bcc457 100755 --- a/macosx/app/build_gui_user_menu.sh +++ b/macosx/app/build_gui_user_menu.sh @@ -11,7 +11,7 @@ # addon commands can't have spaces in them or sh for loop messes up. # may be my limited knowledge of sh scripting and there could be a way. -GRASS_MMVER=`cut -d . -f 1-2 "$GISBASE/etc/VERSIONNUMBER"` +GRASS_MMVER=$(cut -d . -f 1-2 "$GISBASE/etc/VERSIONNUMBER") BINDIR="$GISBASE_USER/Modules/bin" SCRIPTDIR="$GISBASE_USER/Modules/scripts" BINDIRG="$GISBASE_SYSTEM/Modules/bin" @@ -25,58 +25,56 @@ mkdir -p "$MENUDIR" echo "# generated by grass startup" > "$MENUDIR/xtnmenu.dat" # global addons: -if [ -d "$BINDIRG" ] ; then - cd "$BINDIRG" - CMDLISTG=`ls -1 2> /dev/null` +if [ -d "$BINDIRG" ]; then + cd "$BINDIRG" || exit + CMDLISTG=$(ls -1 2> /dev/null) else - CMDLISTG="" + CMDLISTG="" fi -if [ -d "$SCRIPTDIRG" ] ; then - cd "$SCRIPTDIRG" - CMDLISTG="$CMDLISTG"$'\n'"`ls -1 2> /dev/null`" +if [ -d "$SCRIPTDIRG" ]; then + cd "$SCRIPTDIRG" || exit + CMDLISTG="$CMDLISTG"$'\n'"$(ls -1 2> /dev/null)" fi -CMDLISTG=`echo "$CMDLISTG" | sort -u` +CMDLISTG=$(echo "$CMDLISTG" | sort -u) CMDGFOUND="" -if [ "$CMDLISTG" != "" ] ; then - for i in $CMDLISTG - do - if [ -f "$BINDIRG/$i" ] ; then - ftype="`file $BINDIRG/$i`" - else - ftype="`file $SCRIPTDIRG/$i`" - fi - if [ "`echo $ftype | grep 'Mach-O'`" ] || [ "`grep '#% *Module' $BINDIRG/$i 2> /dev/null`" ] || [ "`grep '#% *Module' $SCRIPTDIRG/$i 2> /dev/null`" ] ; then - echo "main:$i:$i:$i" >> "$MENUDIR/xtnmenu.dat" - CMDGFOUND="1" - fi - done +if [ "$CMDLISTG" != "" ]; then + for i in $CMDLISTG; do + if [ -f "$BINDIRG/$i" ]; then + ftype="$(file "$BINDIRG/$i")" + else + ftype="$(file "$SCRIPTDIRG/$i")" + fi + if [ "$(echo "$ftype" | grep 'Mach-O')" ] || [ "$(grep '#% *Module' "$BINDIRG/$i" 2> /dev/null)" ] || [ "$(grep '#% *Module' "$SCRIPTDIRG/$i" 2> /dev/null)" ]; then + echo "main:$i:$i:$i" >> "$MENUDIR/xtnmenu.dat" + CMDGFOUND="1" + fi + done fi # user addons: CMDFIRST="1" -cd "$BINDIR" -CMDLIST=`ls -1 2> /dev/null` -if [ -d "$SCRIPTDIR" ] ; then - cd "$SCRIPTDIR" - CMDLIST="$CMDLIST"$'\n'"`ls -1 2> /dev/null`" +cd "$BINDIR" || exit +CMDLIST=$(ls -1 2> /dev/null) +if [ -d "$SCRIPTDIR" ]; then + cd "$SCRIPTDIR" || exit + CMDLIST="$CMDLIST"$'\n'"$(ls -1 2> /dev/null)" fi -CMDLIST=`echo "$CMDLIST" | sort -u` +CMDLIST=$(echo "$CMDLIST" | sort -u) -if [ "$CMDLIST" != "" ] ; then - for i in $CMDLIST - do - if [ -f "$BINDIR/$i" ] ; then - ftype="`file $BINDIR/$i`" - else - ftype="`file $SCRIPTDIR/$i`" - fi - if [ "`echo $ftype | grep 'Mach-O'`" ] || [ "`grep '#% *Module' $BINDIR/$i 2> /dev/null`" ] || [ "`grep '#% *Module' $SCRIPTDIR/$i 2> /dev/null`" ] ; then - if [ "$CMDFIRST" ] && [ "$CMDGFOUND" ] ; then - echo "separator" >> "$MENUDIR/xtnmenu.dat" - CMDFIRST="" - fi - echo "main:$i:$i:$i" >> "$MENUDIR/xtnmenu.dat" - fi - done +if [ "$CMDLIST" != "" ]; then + for i in $CMDLIST; do + if [ -f "$BINDIR/$i" ]; then + ftype="$(file "$BINDIR/$i")" + else + ftype="$(file "$SCRIPTDIR/$i")" + fi + if [ "$(echo "$ftype" | grep 'Mach-O')" ] || [ "$(grep '#% *Module' "$BINDIR/$i" 2> /dev/null)" ] || [ "$(grep '#% *Module' "$SCRIPTDIR/$i" 2> /dev/null)" ]; then + if [ "$CMDFIRST" ] && [ "$CMDGFOUND" ]; then + echo "separator" >> "$MENUDIR/xtnmenu.dat" + CMDFIRST="" + fi + echo "main:$i:$i:$i" >> "$MENUDIR/xtnmenu.dat" + fi + done fi diff --git a/macosx/app/build_html_user_index.sh b/macosx/app/build_html_user_index.sh index 0dd7271f0b0..7ec3aa53bca 100755 --- a/macosx/app/build_html_user_index.sh +++ b/macosx/app/build_html_user_index.sh @@ -17,35 +17,34 @@ ############# nothing to configure below ############ # $1 is current path to GRASS.app/Contents/MacOS, defaults to /Applications -if [ "$1" != "" ] ; then - GISBASE=$1 +if [ "$1" != "" ]; then + GISBASE=$1 else - GISBASE="/Applications/GRASS-$GRASS_MMVER.app/Contents/MacOS" + GISBASE="/Applications/GRASS-$GRASS_MMVER.app/Contents/MacOS" fi -GRASS_MMVER=`cut -d . -f 1-2 "$GISBASE/etc/VERSIONNUMBER"` -GRASSVERSION=`cat "$GISBASE/etc/VERSIONNUMBER"` +GRASS_MMVER=$(cut -d . -f 1-2 "$GISBASE/etc/VERSIONNUMBER") +GRASSVERSION=$(cat "$GISBASE/etc/VERSIONNUMBER") HTMLDIR="$GISBASE_USER/Modules/docs/html" HTMLDIRG="$GISBASE_SYSTEM/Modules/docs/html" -write_html_header() -{ -# $1: filename -# $2: page title -# $3: is it main index +write_html_header() { + # $1: filename + # $2: page title + # $3: is it main index -echo " + echo " $2 - " > $1 -if [ "$3" ] ; then - echo " + " > "$1" + if [ "$3" ]; then + echo " - " >> $1 -fi -echo " + " >> "$1" + fi + echo " @@ -66,17 +65,16 @@ consulting companies.

Geographic Resources Analysis Support System (GRASS), an open source (GNU GPL'ed), image processing and geographic information system (GIS).

-" >> $1 +" >> "$1" } -write_html_footer() -{ -# $1: filename -echo "
" >> $1 -echo "

Help Index | Full Index | Addon Index
" >> $1 -echo "© 2003-2008 GRASS Development Team

" >> $1 -echo "" >> $1 -echo "" >> $1 +write_html_footer() { + # $1: filename + echo '
' >> "$1" + echo "

Help Index | Full Index | Addon Index
" >> "$1" + echo '© 2003-2008 GRASS Development Team

' >> "$1" + echo "" >> "$1" + echo "" >> "$1" } FULLINDEX=addon_index.html @@ -91,24 +89,24 @@ cp -f "$GISBASE/docs/html/grass_logo.png" "$HTMLDIR/" cp -f "$GISBASE/docs/html/grass_icon.png" "$HTMLDIR/" #process all global HTML pages: -if [ -d "$HTMLDIRG" ] ; then -cd "$HTMLDIRG" +if [ -d "$HTMLDIRG" ]; then + cd "$HTMLDIRG" || exit -#get list of available GRASS modules: -CMDLISTG=`ls -1 *.*.html 2> /dev/null | grep -v index.html | cut -d'.' -f1 | sort -u` + #get list of available GRASS modules: + CMDLISTG=$(ls -1 *.*.html 2> /dev/null | grep -v index.html | cut -d'.' -f1 | sort -u) else -CMDLISTG="" + CMDLISTG="" fi #process all user HTML pages: -cd "$HTMLDIR" +cd "$HTMLDIR" || exit # don't really need to delete these, as removed global modules won't get indexed, # though old symlinks will accumulate. I'm just worried about wildcard deletes. #rm -f global_*.html #get list of available GRASS modules: -CMDLIST=`ls -1 *.*.html 2> /dev/null | grep -v index.html | cut -d'.' -f1 | sort -u` +CMDLIST=$(ls -1 -- *.*.html 2> /dev/null | grep -v index.html | cut -d'.' -f1 | sort -u) #write main index: #echo "Generating HTML manual pages index (help system)..." @@ -125,42 +123,38 @@ echo "" >> $FULLINDEX # global commands: echo "

Global addon command index:

" >> $FULLINDEX echo "" >> $FULLINDEX -if [ "$CMDLISTG" = "" ] ; then - echo "" >> $FULLINDEX +if [ "$CMDLISTG" = "" ]; then + echo '' >> $FULLINDEX else - for i in $CMDLISTG - do - cd "$HTMLDIRG" - CMDLISTI="`ls -1 $i.*.html`" - cd "$HTMLDIR" - for i in $CMDLISTI - do - BASENAME=`basename $i .html` - SHORTDESC="`cat "$HTMLDIRG/$i" | awk '/NAME/,/SYNOPSIS/' | grep '' | cut -d'-' -f2- | sed 's+^ ++g' | grep -vi 'SYNOPSIS' | head -n 1`" -# echo "" >> $FULLINDEX - # make them local to user to simplify page links - echo "" >> $FULLINDEX - ln -sf "$HTMLDIRG/$i" global_$i + for i in $CMDLISTG; do + cd "$HTMLDIRG" || exit + CMDLISTI="$(ls -1 -- "$i".*.html)" + cd "$HTMLDIR" || exit + for i in $CMDLISTI; do + BASENAME=$(basename "$i" .html) + SHORTDESC="$(cat "$HTMLDIRG/$i" | awk '/NAME/,/SYNOPSIS/' | grep '' | cut -d'-' -f2- | sed 's+^ ++g' | grep -vi 'SYNOPSIS' | head -n 1)" + # echo "" >> $FULLINDEX + # make them local to user to simplify page links + echo "" >> $FULLINDEX + ln -sf "$HTMLDIRG/$i" global_"$i" + done done - done fi echo "
[There are no global addon help pages.]
[There are no global addon help pages.]
$BASENAME $SHORTDESC
$BASENAME $SHORTDESC
$BASENAME $SHORTDESC
$BASENAME $SHORTDESC
" >> $FULLINDEX # user commands: echo "

User addon command index:

" >> $FULLINDEX echo "" >> $FULLINDEX -if [ "$CMDLIST" = "" ] ; then - echo "" >> $FULLINDEX +if [ "$CMDLIST" = "" ]; then + echo '' >> $FULLINDEX else - for i in $CMDLIST - do - for i in `ls -1 $i.*.html` - do - BASENAME=`basename $i .html` - SHORTDESC="`cat $i | awk '/NAME/,/SYNOPSIS/' | grep '' | cut -d'-' -f2- | sed 's+^ ++g' | grep -vi 'SYNOPSIS' | head -n 1`" - echo "" >> $FULLINDEX + for i in $CMDLIST; do + for i in $(ls -1 -- "$i".*.html); do + BASENAME=$(basename "$i" .html) + SHORTDESC="$(cat "$i" | awk '/NAME/,/SYNOPSIS/' | grep '' | cut -d'-' -f2- | sed 's+^ ++g' | grep -vi 'SYNOPSIS' | head -n 1)" + echo "" >> $FULLINDEX + done done - done fi echo "
[There are no user addon help pages.]
[There are no user addon help pages.]
$BASENAME $SHORTDESC
$BASENAME $SHORTDESC
" >> $FULLINDEX @@ -169,9 +163,8 @@ write_html_footer $FULLINDEX # user redirects to app dir for main index files -for i in index full_index display database general imagery misc postscript raster raster3D vector -do -echo " +for i in index full_index display database general imagery misc postscript raster raster3D vector; do + echo " @@ -185,6 +178,6 @@ done # add Help Viewer links in user docs folder -mkdir -p $HOME/Library/Documentation/Help/ -ln -sfh ../../GRASS/$GRASS_MMVER/Modules/docs/html $HOME/Library/Documentation/Help/GRASS-$GRASS_MMVER-addon -ln -sfh $GISBASE/docs/html $HOME/Library/Documentation/Help/GRASS-$GRASS_MMVER +mkdir -p "$HOME/Library/Documentation/Help/" +ln -sfh "../../GRASS/$GRASS_MMVER/Modules/docs/html" "$HOME/Library/Documentation/Help/GRASS-$GRASS_MMVER-addon" +ln -sfh "$GISBASE/docs/html" "$HOME/Library/Documentation/Help/GRASS-$GRASS_MMVER" diff --git a/macosx/app/python_wrapper b/macosx/app/python_wrapper index 66655417f3a..f9b05d1f437 100755 --- a/macosx/app/python_wrapper +++ b/macosx/app/python_wrapper @@ -21,25 +21,25 @@ # and reliable method is probably to not depend on Apple's customizations and # execute pythonw directly, 32bit if necessary. -if [ -z "$GISBASE" ] ; then +if [ -z "$GISBASE" ]; then echo "You must be in GRASS GIS to run this program." >&2 exit 1 fi -SYSARCH=`uname -p` -SYSVER=`uname -r | cut -d . -f 1` +SYSARCH=$(uname -p) +SYSVER=$(uname -r | cut -d . -f 1) -if [ ! "$GRASS_PYTHONWX" ] ; then - GRASS_PYTHONWX="pythonw" +if [ ! "$GRASS_PYTHONWX" ]; then + GRASS_PYTHONWX="pythonw" fi # can't run python 64bit if wx not 64bit, assume OSX 10.5+ possible 64bit -if [ $(($SYSVER)) -gt 5 ] && [ "$GRASS_WX64BIT" = "0" ] ; then - case $SYSARCH in - powerpc) pyarch="-ppc" ;; - i386) pyarch="-i386" ;; - *) pyarch="" ;; - esac - exec /usr/bin/arch $pyarch "$GRASS_PYTHONWX" "$@" +if [ $((SYSVER)) -gt 5 ] && [ "$GRASS_WX64BIT" = "0" ]; then + case $SYSARCH in + powerpc) pyarch="-ppc" ;; + i386) pyarch="-i386" ;; + *) pyarch="" ;; + esac + exec /usr/bin/arch $pyarch "$GRASS_PYTHONWX" "$@" else - exec "$GRASS_PYTHONWX" "$@" + exec "$GRASS_PYTHONWX" "$@" fi