Make more configurable for different paths for external programs
authorBrett Parker <arch@sommitrealweird.co.uk>
Tue, 25 Jan 2005 22:37:04 +0000 (22:37 +0000)
committerBrett Parker <arch@sommitrealweird.co.uk>
Tue, 25 Jan 2005 22:37:04 +0000 (22:37 +0000)
* Make the find command be built once and used several times
* add XARGSCOMMAND and a sensible default
* add ECHOCOMMAND and a sensible default
* sort the images in (general) numeric order before writing the HTML page

git-archimport-id: arch@sommitrealweird.co.uk--2005-desktop/bpgallery--mainline--0.9.2--patch-1

bpgallery.sh

index 63a27e8ea7be86caa1ea07fe1da5b765a279e41d..d95049eedff19d546feddab4da5799c086603e52 100755 (executable)
@@ -17,6 +17,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+set -f
+
 VERSION="0.9.2"
 
 if [[ -z $TITLE ]]; then 
@@ -27,10 +29,34 @@ if [[ -z $CONVERTTOOL ]]; then
        CONVERTTOOL="/usr/bin/convert"
 fi
 
+if [[ -z $FINDCOMMAND ]]; then
+       FINDCOMMAND=/usr/bin/find
+fi
+
+if [[ -z $XARGSCOMMAND ]]; then
+       XARGSCOMMAND=/usr/bin/xargs
+fi
+
+if [[ -z $ECHOCOMMAND ]]; then
+       ECHOCOMMAND=/bin/echo
+fi
+
 if [[ -z $WIDTH ]]; then
        WIDTH=100
 fi
 
+if [[ -z $IMAGEEXTENSIONS ]]; then
+       IMAGEEXTENSIONS="jpg gif png";
+fi
+
+FINDIMAGESOPTIONS=""
+
+for imageext in $IMAGEEXTENSIONS; do
+       FINDIMAGESOPTIONS=$FINDIMAGESOPTIONS' -o -type f -maxdepth 1 -iname '*.$imageext' -print0'
+done
+
+FINDIMAGESOPTIONS=${FINDIMAGESOPTIONS## -o }
+
 usage() {
        cat <<END
 Usage:
@@ -74,7 +100,7 @@ fi
 
 cd "$1"
 
-if ( ! find . -name '*.jpg' -o -name '*.png' -o -name '*.gif' > /dev/null 2>/dev/null ); then
+if ( ! $FINDCOMMAND . $FINDIMAGESOPTIONS > /dev/null 2>/dev/null ); then
        echo "$1 does not contain any images. Quitting."
        exit 4
 fi
@@ -86,7 +112,7 @@ else
        exit 3
 fi
 
-find . -type f -name \*.jpg -print0 -or -type f -name \*.gif -print0 -or -type f -name \*.png -print0 -maxdepth 1 | xargs -0 --replace $CONVERTTOOL -resize $WIDTH "{}" "icons/{}"
+$FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 --replace $CONVERTTOOL -resize $WIDTH '{}' 'icons/{}'
 
 cat <<END > index.html
 <?xml version="1.0"?>
@@ -100,7 +126,7 @@ cat <<END > index.html
 END
 
 
-find . -type f -name \*.jpg -maxdepth 1 -print -or -type f -name \*.gif -maxdepth 1 -print -or -type f -name \*.png -maxdepth 1 -print | sed -e 's#^./\(.*\)$#<div class="thumbnail"><a href="\1"><img src="icons/\1" /></a></div>#' >> index.html
+$FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 --replace $ECHOCOMMAND {} |sort -g | sed -e 's#^./\(.*\)$#<div class="thumbnail"><a href="\1"><img src="icons/\1" /></a></div>#' >> index.html
 
 cat <<END >> index.html
 </body>
@@ -109,30 +135,17 @@ END
 
 
 cd icons
-if ( ls *.jpg > /dev/null 2>/dev/null ); then
-       TEMPMAX=$(identify *.jpg | sed -r 's#^.*?[0-9]+x([0-9]+)\+.*$#\1#' | sort -g -r | head -n 1)
-       if [[ $TEMPMAX -gt $MAXHEIGHT ]]; then
-               MAXHEIGHT=$TEMPMAX
-       fi
-fi
 
-if ( ls *.gif > /dev/null 2>/dev/null ); then
-       TEMPMAX=$(identify *.gif | sed -r 's#^.*?[0-9]+x([0-9]+)\+.*$#\1#' | sort -g -r | head -n 1)
-               
-       if [[ $TEMPMAX -gt $MAXHEIGHT ]]; then
-               MAXHEIGHT=$TEMPMAX
+for imageext in $IMAGEEXTENSIONS; do
+       if ( ls "*.$imageext" > /dev/null 2>/dev/null ); then
+               TEMPMAX=$(identify *.jpg | grep "Geometry:" | sed -r 's#^.*Geometry:.*?[0-9]+x([0-9]+)\+.*$#\1#' | sort -g -r | head -n 1)
+               if [[ $TEMPMAX -gt $MAXHEIGHT ]]; then
+                       MAXHEIGHT=$TEMPMAX
+               fi
        fi
-fi
-
-if ( ls *.png > /dev/null 2>/dev/null ); then
-       TEMPMAX=$(identify *.png | sed -r 's#^.*?[0-9]+x([0-9]+)\+.*$#\1#' | sort -g -r | head -n 1)
-       if [[ $TEMPMAX -gt $MAXHEIGHT ]]; then
-               MAXHEIGHT=$TEMPMAX
-       fi
-fi
+done
 
 cd ..
-       
 
 
 cat <<END > style.css