diff options
author | Nils K <git@nkn-it.de> | 2021-03-15 22:27:52 +0100 |
---|---|---|
committer | Nils K <git@nkn-it.de> | 2021-03-15 22:27:52 +0100 |
commit | 7785c6127cfbc520f482cf89257d532d772f6a7e (patch) | |
tree | 0a5f83a43c85d458580b5d6cd2908d6f82cf1b21 | |
parent | 89060f5e95a2bba7057f1b223d34489f1cd0cf01 (diff) |
better var names
-rwxr-xr-x | gallery.sh | 206 |
1 files changed, 103 insertions, 103 deletions
@@ -8,46 +8,46 @@ #### Configuration Section ######################################################################################### -height_small=187 -height_large=768 -quality=85 -thumbdir="__thumbs" -htmlfile="index.html" -title="Gallery" -footer='Created with <a href="https://github.com/Cyclenerd/gallery_shell">gallery.sh</a>' +MY_HEIGHT_SMALL=187 +MY_HEIGHT_LARGE=768 +MY_QUALITY=85 +MY_THUMBDIR="__thumbs" +MY_INDEX_HTML_FILE="index.html" +MY_TITLE="Gallery" +MY_FOOTER='Created with <a href="https://github.com/Cyclenerd/gallery_shell">gallery.sh</a>' # Use convert from ImageMagick -convert="convert" +MY_CONVERT_COMMAND="convert" # Use JHead for EXIF Information -exif="jhead" +MY_EXIF_COMMAND="jhead" -# Bootstrap (currently v3.4.1) -stylesheet="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css" +# Bootstrap 4 +MY_CSS="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css" # Debugging output # true=enable, false=disable -debug=true +MY_DEBUG=true ######################################################################################### #### End Configuration Section ######################################################################################### -me=$(basename "$0") -datetime=$(date -u "+%Y-%m-%d %H:%M:%S") -datetime+=" UTC" +MY_SCRIPT_NAME=$(basename "$0") +MY_DATETIME=$(date -u "+%Y-%m-%d %H:%M:%S") +MY_DATETIME+=" UTC" function usage { - returnCode="$1" - echo -e "Usage: $me [-t <title>] [-d <thumbdir>] [-h]: - [-t <title>]\\t sets the title (default: $title) - [-d <thumbdir>]\\t sets the thumbdir (default: $thumbdir) + MY_RETURN_CODE="$1" + echo -e "Usage: $MY_SCRIPT_NAME [-t <title>] [-d <thumbdir>] [-h]: + [-t <title>]\\t sets the title (default: $MY_TITLE) + [-d <thumbdir>]\\t sets the thumbdir (default: $MY_THUMBDIR) [-h]\\t\\t displays help (this message)" - exit "$returnCode" + exit "$MY_RETURN_CODE" } function debugOutput(){ - if [[ "$debug" == true ]]; then + if [[ "$MY_DEBUG" == true ]]; then echo "$1" # if debug variable is true, echo whatever's passed to the function fi } @@ -56,21 +56,21 @@ function getFileSize(){ # Be aware that BSD stat doesn't support --version and -c if stat --version &>/dev/null; then # GNU - myfilesize=$(stat -c %s "$1" | awk '{$1/=1000000;printf "%.2fMB\n",$1}') + MY_FILE_SIZE=$(stat -c %s "$1" | awk '{$1/=1000000;printf "%.2fMB\n",$1}') else # BSD - myfilesize=$(stat -f %z "$1" | awk '{$1/=1000000;printf "%.2fMB\n",$1}') + MY_FILE_SIZE=$(stat -f %z "$1" | awk '{$1/=1000000;printf "%.2fMB\n",$1}') fi - echo "$myfilesize" + echo "$MY_FILE_SIZE" } while getopts ":t:d:h" opt; do case $opt in t) - title="$OPTARG" + MY_TITLE="$OPTARG" ;; d) - thumbdir="$OPTARG" + MY_THUMBDIR="$OPTARG" ;; h) usage 0 @@ -82,39 +82,39 @@ while getopts ":t:d:h" opt; do esac done -debugOutput "- $me : $datetime" +debugOutput "- $MY_SCRIPT_NAME : $MY_DATETIME" ### Check Commands -command -v $convert >/dev/null 2>&1 || { echo >&2 "!!! $convert it's not installed. Aborting."; exit 1; } -command -v $exif >/dev/null 2>&1 || { echo >&2 "!!! $exif it's not installed. Aborting."; exit 1; } +command -v $MY_CONVERT_COMMAND >/dev/null 2>&1 || { echo >&2 "!!! $MY_CONVERT_COMMAND it's not installed. Aborting."; exit 1; } +command -v $MY_EXIF_COMMAND >/dev/null 2>&1 || { echo >&2 "!!! $MY_EXIF_COMMAND it's not installed. Aborting."; exit 1; } ### Create Folders -[[ -d "$thumbdir" ]] || mkdir "$thumbdir" || exit 2 +[[ -d "$MY_THUMBDIR" ]] || mkdir "$MY_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 +MY_HEIGHTS[0]=$MY_HEIGHT_SMALL +MY_HEIGHTS[1]=$MY_HEIGHT_LARGE +for MY_RES in ${MY_HEIGHTS[*]}; do + [[ -d "$MY_THUMBDIR/$MY_RES" ]] || mkdir -p "$MY_THUMBDIR/$MY_RES" || exit 3 done #### Create Startpage -debugOutput "$htmlfile" -cat > "$htmlfile" << EOF +debugOutput "$MY_INDEX_HTML_FILE" +cat > "$MY_INDEX_HTML_FILE" << EOF <!DOCTYPE HTML> <html lang="en"> <head> <meta charset="utf-8"> - <title>$title</title> + <title>$MY_TITLE</title> <meta name="viewport" content="width=device-width"> <meta name="robots" content="noindex, nofollow"> - <link rel="stylesheet" href="$stylesheet"> + <link rel="stylesheet" href="$MY_CSS"> </head> <body> <header> <div class="navbar navbar-dark bg-dark shadow-sm"> <div class="container"> <a href="#" class="navbar-brand"> - <strong>$title</strong> + <strong>$MY_TITLE</strong> </a> </div> </div> @@ -125,56 +125,56 @@ EOF ### Photos (JPG) if [[ $(find . -maxdepth 1 -type f -iname \*.jpg | wc -l) -gt 0 ]]; then -echo '<div class="row row-cols-sm-1 row-cols-md-2 row-cols-lg-3 row-cols-xl-4 py-5">' >> "$htmlfile" +echo '<div class="row row-cols-sm-1 row-cols-md-2 row-cols-lg-3 row-cols-xl-4 py-5">' >> "$MY_INDEX_HTML_FILE" ## Generate Images -numfiles=0 -for filename in *.[jJ][pP][gG]; do - filelist[$numfiles]=$filename - (( numfiles++ )) - for res in ${heights[*]}; do - if [[ ! -s $thumbdir/$res/$filename ]]; then - debugOutput "$thumbdir/$res/$filename" - $convert -auto-orient -strip -quality $quality -resize x$res "$filename" "$thumbdir/$res/$filename" +MY_NUM_FILES=0 +for MY_FILENAME in *.[jJ][pP][gG]; do + MY_FILELIST[$MY_NUM_FILES]=$MY_FILENAME + (( MY_NUM_FILES++ )) + for MY_RES in ${MY_HEIGHTS[*]}; do + if [[ ! -s $MY_THUMBDIR/$MY_RES/$MY_FILENAME ]]; then + debugOutput "$MY_THUMBDIR/$MY_RES/$MY_FILENAME" + $MY_CONVERT_COMMAND -auto-orient -strip -quality $MY_QUALITY -resize x$MY_RES "$MY_FILENAME" "$MY_THUMBDIR/$MY_RES/$MY_FILENAME" fi done - cat >> "$htmlfile" << EOF + cat >> "$MY_INDEX_HTML_FILE" << EOF <div class="col"> <p> - <a href="$thumbdir/$filename.html"><img src="$thumbdir/$height_small/$filename" alt="Thumbnail: $filename" class="rounded mx-auto d-block"></a> + <a href="$MY_THUMBDIR/$MY_FILENAME.html"><img src="$MY_THUMBDIR/$MY_HEIGHT_SMALL/$MY_FILENAME" alt="Thumbnail: $MY_FILENAME" class="rounded mx-auto d-block"></a> </p> </div> EOF done -echo '</div>' >> "$htmlfile" +echo '</div>' >> "$MY_INDEX_HTML_FILE" ## Generate the HTML Files for Images in thumbdir -file=0 -while [[ $file -lt $numfiles ]]; do - filename=${filelist[$file]} - prev="" - next="" - [[ $file -ne 0 ]] && prev=${filelist[$((file - 1))]} - [[ $file -ne $((numfiles - 1)) ]] && next=${filelist[$((file + 1))]} - imagehtmlfile="$thumbdir/$filename.html" - exifinfo=$($exif "$filename") - filesize=$(getFileSize "$filename") - debugOutput "$imagehtmlfile" - cat > "$imagehtmlfile" << EOF +MY_FILE=0 +while [[ $MY_FILE -lt $MY_NUM_FILES ]]; do + MY_FILENAME=${MY_FILELIST[$MY_FILE]} + MY_PREV="" + MY_NEXT="" + [[ $MY_FILE -ne 0 ]] && MY_PREV=${MY_FILELIST[$((MY_FILE - 1))]} + [[ $MY_FILE -ne $((MY_NUM_FILES - 1)) ]] && MY_NEXT=${MY_FILELIST[$((MY_FILE + 1))]} + MY_IMAGE_HTML_FILE="$MY_THUMBDIR/$MY_FILENAME.html" + MY_EXIF_INFO=$($MY_EXIF_COMMAND "$MY_FILENAME") + MY_FILESIZE=$(getFileSize "$MY_FILENAME") + debugOutput "$MY_IMAGE_HTML_FILE" + cat > "$MY_IMAGE_HTML_FILE" << EOF <!DOCTYPE HTML> <html lang="en"> <head> <meta charset="utf-8"> -<title>$filename</title> +<title>$MY_FILENAME</title> <meta name="viewport" content="width=device-width"> <meta name="robots" content="noindex, nofollow"> -<link rel="stylesheet" href="$stylesheet"> +<link rel="stylesheet" href="$MY_CSS"> </head> <body> <header> <div class="navbar navbar-dark bg-dark shadow-sm"> <div class="container"> <a href="../index.html" class="navbar-brand"> - <strong>$title</strong> + <strong>$MY_TITLE</strong> </a> </div> </div> @@ -183,44 +183,44 @@ while [[ $file -lt $numfiles ]]; do EOF # Pager - echo '<div class="row py-3"><div class="col text-left">' >> "$imagehtmlfile" - if [[ $prev ]]; then - echo '<a href="'"$prev"'.html" accesskey="p" title="⌨️ PC: [Alt]+[Shift]+[P] / MAC: [Control]+[Option]+[P]" class="btn btn-secondary " role="button">« Previous</a>' >> "$imagehtmlfile" + echo '<div class="row py-3"><div class="col text-left">' >> "$MY_IMAGE_HTML_FILE" + if [[ $MY_PREV ]]; then + echo '<a href="'"$MY_PREV"'.html" accesskey="p" title="⌨️ PC: [Alt]+[Shift]+[P] / MAC: [Control]+[Option]+[P]" class="btn btn-secondary " role="button">« Previous</a>' >> "$MY_IMAGE_HTML_FILE" else - echo '<a href="#" class="btn btn-secondary disabled" role="button" aria-disabled="true">« Previous</a>' >> "$imagehtmlfile" + echo '<a href="#" class="btn btn-secondary disabled" role="button" aria-disabled="true">« Previous</a>' >> "$MY_IMAGE_HTML_FILE" fi - cat >> "$imagehtmlfile" << EOF + cat >> "$MY_IMAGE_HTML_FILE" << EOF </div> -<div class="col d-none d-md-block text-center"><h3>$filename</h3></div> +<div class="col d-none d-md-block text-center"><h3>$MY_FILENAME</h3></div> <div class="col text-right"> EOF - if [[ $next ]]; then - echo '<a href="'"$next"'.html" accesskey="n" title="⌨️ PC: [Alt]+[Shift]+[N] / MAC: [Control]+[Option]+[N]" class="btn btn-secondary ">Next »</a>' >> "$imagehtmlfile" + if [[ $MY_NEXT ]]; then + echo '<a href="'"$MY_NEXT"'.html" accesskey="n" title="⌨️ PC: [Alt]+[Shift]+[N] / MAC: [Control]+[Option]+[N]" class="btn btn-secondary ">Next »</a>' >> "$MY_IMAGE_HTML_FILE" else - echo '<a href="#" class="btn btn-secondary disabled" role="button" aria-disabled="true">Next »</a>' >> "$imagehtmlfile" + echo '<a href="#" class="btn btn-secondary disabled" role="button" aria-disabled="true">Next »</a>' >> "$MY_IMAGE_HTML_FILE" fi - echo '</div></div>' >> "$imagehtmlfile" + echo '</div></div>' >> "$MY_IMAGE_HTML_FILE" - cat >> "$imagehtmlfile" << EOF + cat >> "$MY_IMAGE_HTML_FILE" << EOF <div class="row"> <div class="col"> - <p><img src="$height_large/$filename" class="img-fluid" alt="Image: $filename"></p> + <p><img src="$MY_HEIGHT_LARGE/$MY_FILENAME" class="img-fluid" alt="Image: $MY_FILENAME"></p> </div> </div> <div class="row"> <div class="col"> - <p><a class="btn btn-primary" href="../$filename">Download Original ($filesize)</a></p> + <p><a class="btn btn-primary" href="../$MY_FILENAME">Download Original ($MY_FILESIZE)</a></p> </div> </div> EOF # EXIF - if [[ $exifinfo ]]; then - cat >> "$imagehtmlfile" << EOF + if [[ $MY_EXIF_INFO ]]; then + cat >> "$MY_IMAGE_HTML_FILE" << EOF <div class="row"> <div class="col"> <pre> -$exifinfo +$MY_EXIF_INFO </pre> </div> </div> @@ -228,25 +228,25 @@ EOF fi # Footer - cat >> "$imagehtmlfile" << EOF + cat >> "$MY_IMAGE_HTML_FILE" << EOF </main> <!-- // main container --> <br> <footer class="footer mt-auto py-3 bg-light"> <div class="container"> - <span class="text-muted">$footer - $datetime</span> + <span class="text-muted">$MY_FOOTER - $MY_DATETIME</span> </div> </footer> </body> </html> EOF - (( file++ )) + (( MY_FILE++ )) done fi ### Movies (MOV or MP4) if [[ $(find . -maxdepth 1 -type f -iname \*.mov -o -iname '*.mp4' | wc -l) -gt 0 ]]; then - cat >> "$htmlfile" << EOF + cat >> "$MY_INDEX_HTML_FILE" << EOF <div class="row"> <div class="col"> <div class="page-header"><h2>Movies</h2></div> @@ -256,27 +256,27 @@ if [[ $(find . -maxdepth 1 -type f -iname \*.mov -o -iname '*.mp4' | wc -l) -gt <div class="col"> EOF if [[ $(find . -maxdepth 1 -type f -iname \*.mov | wc -l) -gt 0 ]]; then - for filename in *.[mM][oO][vV]; do - filesize=$(getFileSize "$filename") - cat >> "$htmlfile" << EOF -<a href="$filename" class="btn btn-primary" role="button">$filename ($filesize)</a> + for MY_FILENAME in *.[mM][oO][vV]; do + MY_FILESIZE=$(getFileSize "$MY_FILENAME") + cat >> "$MY_INDEX_HTML_FILE" << EOF +<a href="$MY_FILENAME" class="btn btn-primary" role="button">$MY_FILENAME ($MY_FILESIZE)</a> EOF done fi if [[ $(find . -maxdepth 1 -type f -iname \*.mp4 | wc -l) -gt 0 ]]; then - for filename in *.[mM][pP]4; do - filesize=$(getFileSize "$filename") - cat >> "$htmlfile" << EOF -<a href="$filename" class="btn btn-primary" role="button">$filename ($filesize)</a> + for MY_FILENAME in *.[mM][pP]4; do + MY_FILESIZE=$(getFileSize "$MY_FILENAME") + cat >> "$MY_INDEX_HTML_FILE" << EOF +<a href="$MY_FILENAME" class="btn btn-primary" role="button">$MY_FILENAME ($MY_FILESIZE)</a> EOF done fi - echo '</div></div>' >> "$htmlfile" + echo '</div></div>' >> "$MY_INDEX_HTML_FILE" fi ### Downloads (ZIP) if [[ $(find . -maxdepth 1 -type f -iname \*.zip | wc -l) -gt 0 ]]; then - cat >> "$htmlfile" << EOF + cat >> "$MY_INDEX_HTML_FILE" << EOF <div class="row"> <div class="col"> <div class="page-header"><h2>Downloads</h2></div> @@ -285,22 +285,22 @@ if [[ $(find . -maxdepth 1 -type f -iname \*.zip | wc -l) -gt 0 ]]; then <div class="row"> <div class="col"> EOF - for filename in *.[zZ][iI][pP]; do - filesize=$(getFileSize "$filename") - cat >> "$htmlfile" << EOF -<a href="$filename" class="btn btn-primary" role="button">$filename ($filesize)</a> + for MY_FILENAME in *.[zZ][iI][pP]; do + MY_FILESIZE=$(getFileSize "$MY_FILENAME") + cat >> "$MY_INDEX_HTML_FILE" << EOF +<a href="$MY_FILENAME" class="btn btn-primary" role="button">$MY_FILENAME ($MY_FILESIZE)</a> EOF done - echo '</div></div>' >> "$htmlfile" + echo '</div></div>' >> "$MY_INDEX_HTML_FILE" fi ### Footer -cat >> "$htmlfile" << EOF +cat >> "$MY_INDEX_HTML_FILE" << EOF </main> <!-- // main container --> <br> <footer class="footer mt-auto py-3 bg-light"> <div class="container"> - <span class="text-muted">$footer - $datetime</span> + <span class="text-muted">$MY_FOOTER - $MY_DATETIME</span> </div> </footer> </body> |