From fab72851e5f42ae48104df1ddf938051f43767c1 Mon Sep 17 00:00:00 2001
From: Nils
Date: Mon, 7 Nov 2016 17:28:18 +0100
Subject: ShellCheck optimization
http://www.shellcheck.net/
---
gallery.sh | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/gallery.sh b/gallery.sh
index 48efc0e..aef305c 100755
--- a/gallery.sh
+++ b/gallery.sh
@@ -11,8 +11,8 @@
height_small=187
height_large=768
quality=85
-thumbdir=__thumbs
-htmlfile=index.html
+thumbdir="__thumbs"
+htmlfile="index.html"
title="Gallery"
footer='Created with gallery.sh'
@@ -59,13 +59,12 @@ function debugOutput(){
function getFileSize(){
# Be aware that BSD stat doesn't support --version and -c
- stat --version &>/dev/null
- if [[ "${?}" -eq "0" ]]; then
+ if stat --version &>/dev/null; then
# GNU
- local myfilesize=$(stat -c %s "$1" | awk '{$1/=1000000;printf "%.2fMB\n",$1}')
+ myfilesize=$(stat -c %s "$1" | awk '{$1/=1000000;printf "%.2fMB\n",$1}')
else
# BSD
- local myfilesize=$(stat -f %z "$1" | awk '{$1/=1000000;printf "%.2fMB\n",$1}')
+ myfilesize=$(stat -f %z "$1" | awk '{$1/=1000000;printf "%.2fMB\n",$1}')
fi
echo "$myfilesize"
}
@@ -95,12 +94,12 @@ command -v $convert >/dev/null 2>&1 || { echo >&2 "!!! $convert it's not install
command -v $exif >/dev/null 2>&1 || { echo >&2 "!!! $exif it's not installed. Aborting."; exit 1; }
### Create Folders
-[[ -d $thumbdir ]] || mkdir $thumbdir || exit 2
+[[ -d "$thumbdir" ]] || mkdir "$thumbdir" || exit 2
heights[0]=$height_small
heights[1]=$height_large
for res in ${heights[*]}; do
- [[ -d $thumbdir/$res ]] || mkdir -p $thumbdir/$res || exit 3
+ [[ -d "$thumbdir/$res" ]] || mkdir -p "$thumbdir/$res" || exit 3
done
#### Create Startpage
@@ -147,7 +146,7 @@ for filename in *.[jJ][pP][gG]; do
EOF
-[[ $(( $numfiles % 4 )) -eq 0 ]] && echo '' >> "$htmlfile"
+[[ $((numfiles % 4)) -eq 0 ]] && echo '' >> "$htmlfile"
done
echo '' >> "$htmlfile"
@@ -155,10 +154,11 @@ echo '' >> "$htmlfile"
file=0
while [[ $file -lt $numfiles ]]; do
filename=${filelist[$file]}
- prev= next=
+ prev=""
+ next=""
[[ $file -ne 0 ]] && prev=${filelist[$((file - 1))]}
[[ $file -ne $((numfiles - 1)) ]] && next=${filelist[$((file + 1))]}
- imagehtmlfile=$thumbdir/$filename.html
+ imagehtmlfile="$thumbdir/$filename.html"
exifinfo=$($exif "$filename")
filesize=$(getFileSize "$filename")
debugOutput "$imagehtmlfile"
@@ -183,8 +183,8 @@ EOF
# Pager
echo '' >> "$imagehtmlfile"
cat >> "$imagehtmlfile" << EOF
--
cgit v1.2.3