From 75b67f975bd6fb94cc736443926379f825bf8a2b Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 1 May 2021 08:34:18 +0100 Subject: fix URIs --- README.pod | 2 +- docs/photoalbum.1 | 2 +- docs/photoalbum.pod | 2 +- docs/photoalbum.txt | 2 +- share/templates/default/footer.tmpl | 2 +- src/photoalbum.sh | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.pod b/README.pod index 829b6b9..9c55dd7 100644 --- a/README.pod +++ b/README.pod @@ -53,6 +53,6 @@ See package description or project website. =head1 AUTHOR -Paul Buetow - +Paul Buetow - =cut diff --git a/docs/photoalbum.1 b/docs/photoalbum.1 index e9878ae..c0d7344 100644 --- a/docs/photoalbum.1 +++ b/docs/photoalbum.1 @@ -181,4 +181,4 @@ Go to the templates directory and edit them as wished. See package description or project website. .SH "AUTHOR" .IX Header "AUTHOR" -Paul Buetow \- +Paul Buetow \- diff --git a/docs/photoalbum.pod b/docs/photoalbum.pod index 829b6b9..9c55dd7 100644 --- a/docs/photoalbum.pod +++ b/docs/photoalbum.pod @@ -53,6 +53,6 @@ See package description or project website. =head1 AUTHOR -Paul Buetow - +Paul Buetow - =cut diff --git a/docs/photoalbum.txt b/docs/photoalbum.txt index c0a7a51..56d7806 100644 --- a/docs/photoalbum.txt +++ b/docs/photoalbum.txt @@ -41,5 +41,5 @@ LICENSE See package description or project website. AUTHOR - Paul Buetow - + Paul Buetow - diff --git a/share/templates/default/footer.tmpl b/share/templates/default/footer.tmpl index a6b5c78..18af2b5 100644 --- a/share/templates/default/footer.tmpl +++ b/share/templates/default/footer.tmpl @@ -10,7 +10,7 @@ END fi cat < END diff --git a/src/photoalbum.sh b/src/photoalbum.sh index 82c086a..b18a446 100755 --- a/src/photoalbum.sh +++ b/src/photoalbum.sh @@ -1,7 +1,7 @@ #!/bin/bash # photoalbum (c) 2011 - 2014 by Paul C. Buetow -# http://photoalbum.buetow.org +# http://github.com/snonux/photoalbum declare -r VERSION='PHOTOALBUMVERSION' declare -r DEFAULTRC=/etc/default/photoalbum -- cgit v1.2.3 From c54942df3c23088466fa9a612de4dbeafb77630b Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 5 Feb 2022 14:19:56 +0000 Subject: use default by default --- Makefile | 1 + docs/photoalbum.1 | 4 ++-- src/photoalbum.sh | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index ad5131e..45d804b 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ NAME=photoalbum +#DESTDIR=/ all: version documentation build build: test ! -d ./bin && mkdir ./bin || exit 0 diff --git a/docs/photoalbum.1 b/docs/photoalbum.1 index c0d7344..146d2d4 100644 --- a/docs/photoalbum.1 +++ b/docs/photoalbum.1 @@ -1,4 +1,4 @@ -.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) +.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== @@ -133,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "PHOTOALBUM 1" -.TH PHOTOALBUM 1 "2021-01-24" "photoalbum 0.4.5" "User Commands" +.TH PHOTOALBUM 1 "2022-02-05" "photoalbum 0.4.5" "User Commands" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l diff --git a/src/photoalbum.sh b/src/photoalbum.sh index b18a446..a044278 100755 --- a/src/photoalbum.sh +++ b/src/photoalbum.sh @@ -16,7 +16,7 @@ USAGE } function makemake { - [ ! -f ./photoalbumrc ] && cp /etc/default/photoalbum ./photoalbumrc + [ ! -f ./photoalbumrc ] && cp $DEFAULTRC ./photoalbumrc cat < ./Makefile all: photoalbum generate photoalbumrc -- cgit v1.2.3 From f91a910a81a49cd09f66b9549cba38e2132dd654 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 5 Feb 2022 14:30:13 +0000 Subject: GEOMETRY is optional --- src/photoalbum.default.conf | 7 ++++--- src/photoalbum.sh | 8 ++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/photoalbum.default.conf b/src/photoalbum.default.conf index 160a8ed..07026f3 100644 --- a/src/photoalbum.default.conf +++ b/src/photoalbum.default.conf @@ -1,9 +1,11 @@ # The title of the photoalbum TITLE='A simple Photoalbum' -# Diverse default values +# Thumbnail geometry THUMBGEOMETRY=250 -GEOMETRY=800 +# Normal geometry (when viewing photo). Uncomment, to keep original size. +GEOMETRY=1200 +# Max previews per page. MAXPREVIEWS=100 # Diverse directories, need to be full paths, not relative! @@ -22,4 +24,3 @@ TAR_OPTS='-c' # Some debugging options #set -e #set -x - diff --git a/src/photoalbum.sh b/src/photoalbum.sh index a044278..5d8c8b2 100755 --- a/src/photoalbum.sh +++ b/src/photoalbum.sh @@ -59,8 +59,12 @@ function scalephotos { if [ ! -f "${destphoto_nospace}" ]; then echo "Scaling ${photo} to ${destphoto_nospace}" - convert -auto-orient \ - -geometry ${GEOMETRY} "${photo}" "${destphoto_nospace}" + if [ ! -z "${GEOMETRY}" ]; then + convert -auto-orient \ + -geometry ${GEOMETRY} "${photo}" "${destphoto_nospace}" + else + convert -auto-orient "${photo}" "${destphoto_nospace}" + fi fi done } -- cgit v1.2.3 From 280500bd9d018a9c1984214984c94fb36163afce Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 14 Feb 2022 22:41:08 +0000 Subject: fix URL --- src/photoalbum.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/photoalbum.sh b/src/photoalbum.sh index 5d8c8b2..410d7cb 100755 --- a/src/photoalbum.sh +++ b/src/photoalbum.sh @@ -1,7 +1,7 @@ #!/bin/bash # photoalbum (c) 2011 - 2014 by Paul C. Buetow -# http://github.com/snonux/photoalbum +# https://codeberg.org/foozone/photoalbum declare -r VERSION='PHOTOALBUMVERSION' declare -r DEFAULTRC=/etc/default/photoalbum -- cgit v1.2.3 From 78771e1f4f0f7c2a503a486ba88570c1ac2e2ba8 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 14 Feb 2022 22:47:01 +0000 Subject: add idea --- IDEA.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 IDEA.md diff --git a/IDEA.md b/IDEA.md new file mode 100644 index 0000000..aa32565 --- /dev/null +++ b/IDEA.md @@ -0,0 +1 @@ +I could use https://masonry.desandro.com/ to line up the photos niceley. But also keep a HTML-only version available. -- cgit v1.2.3 From 75c62b3abb4f84c2dc967b9f9289df10cb6af227 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 14 Feb 2022 23:04:18 +0000 Subject: refactor a bit - closer to ShellCheck safety but not quite there yet --- src/photoalbum.sh | 175 ++++++++++++++++++++++++++---------------------------- 1 file changed, 85 insertions(+), 90 deletions(-) diff --git a/src/photoalbum.sh b/src/photoalbum.sh index 410d7cb..eb1e06a 100755 --- a/src/photoalbum.sh +++ b/src/photoalbum.sh @@ -1,45 +1,45 @@ #!/bin/bash -# photoalbum (c) 2011 - 2014 by Paul C. Buetow +# photoalbum (c) 2011 - 2014, 2022 by Paul Buetow # https://codeberg.org/foozone/photoalbum declare -r VERSION='PHOTOALBUMVERSION' -declare -r DEFAULTRC=/etc/default/photoalbum +declare -r DEFAULTRC='/etc/default/photoalbum' declare -r ARG1="${1}" ; shift declare RC_FILE="${1}" ; shift -function usage { +usage () { cat - <&2 Usage: $0 clean|generate|version|makemake|recursive:DIR [rcfile] USAGE } -function makemake { - [ ! -f ./photoalbumrc ] && cp $DEFAULTRC ./photoalbumrc +makemake () { + [ ! -f ./photoalbumrc ] && cp "$DEFAULTRC" ./photoalbumrc cat < ./Makefile all: photoalbum generate photoalbumrc clean: photoalbum clean photoalbumrc MAKEFILE - echo You may now customize ./photoalbumrc and run make + 'echo You may now customize ./photoalbumrc and run make' } -function tarball { +tarball () { # Cleanup tarball from prev run if any find "${DIST_DIR}" -maxdepth 1 -type f -name \*.tar -delete - declare -r base=$(basename "${INCOMING_DIR}") + declare -r base="$(basename "${INCOMING_DIR}")" echo "Creating tarball ${DIST_DIR}/${tarball_name} from ${INCOMING_DIR}" - cd $(dirname "${INCOMING_DIR}") + cd "$(dirname "${INCOMING_DIR}")" tar $TAR_OPTS -f "${DIST_DIR}/${tarball_name}" "${base}" cd - &>/dev/null } -function template { - declare -r template=${1} ; shift - declare -r html=${1} ; shift +template () { + declare -r template="${1}" ; shift + declare -r html="${1}" ; shift declare -r dist_html="${DIST_DIR}/${html_dir}" # Creating ${dist_html}/${html}.html from ${template}.tmpl @@ -47,14 +47,14 @@ function template { source "${TEMPLATE_DIR}/${template}.tmpl" >> "${dist_html}/${html}" } -function scalephotos { +scalephotos () { cd "${INCOMING_DIR}" && find ./ -type f $FIND_ARGS | sort | while read photo; do - declare photo=$(sed 's#^\./##' <<< "${photo}") + declare photo="$(sed 's#^\./##' <<< "${photo}")" declare destphoto="${DIST_DIR}/photos/${photo}" - declare destphoto_nospace=${destphoto// /_} + declare destphoto_nospace="${destphoto// /_}" - declare dirname=$(dirname "${destphoto}") + declare dirname="$(dirname "${destphoto}")" [ ! -d "${dirname}" ] && mkdir -p "${dirname}" if [ ! -f "${destphoto_nospace}" ]; then @@ -69,7 +69,7 @@ function scalephotos { done } -function albumhtml { +albumhtml () { declare photos_dir="${1}" ; shift declare html_dir="${1}" ; shift declare thumbs_dir="${1}" ; shift @@ -78,10 +78,10 @@ function albumhtml { declare -i num=1 declare -i i=0 - declare name=page-${num} + declare name="page-${num}" - template header ${name}.html - template header-first-add ${name}.html + template header "${name}.html" + template header-first-add "${name}.html" cd "${DIST_DIR}/${photos_dir}" && find ./ -type f | sort | sed 's;^\./;;' | while read photo; do @@ -91,26 +91,26 @@ function albumhtml { i=1 : $(( num++ )) - declare next=page-${num} - template next ${name}.html - template footer ${name}.html + declare next="page-${num}" + template next "${name}.html" + template footer "${name}.html" - declare prev=${name} - declare name=${next} - template header ${name}.html - template prev ${name}.html + declare prev="${name}" + declare name="${next}" + template header "${name}.html" + template prev "${name}.html" fi # Preview page - template preview ${name}.html + template preview "${name}.html" # View page - template header ${num}-${i}.html - template view ${num}-${i}.html - template footer ${num}-${i}.html + template header "${num}-${i}.html" + template view "${num}-${i}.html" + template footer "${num}-${i}.html" if [ ! -f "${DIST_DIR}/${thumbs_dir}/${photo}" ]; then - dirname=$(dirname "${DIST_DIR}/${thumbs_dir}/${photo}") + dirname="$(dirname "${DIST_DIR}/${thumbs_dir}/${photo}")" [ ! -d "${dirname}" ] && mkdir -p "${dirname}" echo "Creating thumb ${DIST_DIR}/${thumbs_dir}/${photo}"; @@ -120,76 +120,73 @@ function albumhtml { done template footer \ - $(cd "${DIST_DIR}/${html_dir}";ls -t page-*.html | head -n 1) + "$(cd "${DIST_DIR}/${html_dir}";ls -t page-*.html | head -n 1)" cd "${DIST_DIR}/${html_dir}" && ls *.html | grep -v page- | cut -d'-' -f1 | uniq | while read prefix; do - declare page=$(ls -t ${prefix}-*.html | - head -n 1 | sed 's#\(.*\)-.*.html#\1#') + declare page="$(ls -t ${prefix}-*.html | head -n 1 | sed 's#\(.*\)-.*.html#\1#')" + declare lastview="$(ls -t ${prefix}-*.html | head -n 1 | sed 's/.*-\(.*\).html/\1/')" - declare lastview=$(ls -t ${prefix}-*.html | - head -n 1 | sed 's/.*-\(.*\).html/\1/') + declare prevredirect="${page}-0" + declare nextredirect="${page}-$((lastview+1))" - declare prevredirect=${page}-0 - declare nextredirect=${page}-$((lastview+1)) - - declare redirect_page=$(( page-1 ))-${MAXPREVIEWS} - template redirect ${prevredirect}.html + declare redirect_page="$(( page-1 ))-${MAXPREVIEWS}" + template redirect "${prevredirect}.html" if [ ${lastview} -eq ${MAXPREVIEWS} ]; then - declare redirect_page=$(( page+1 ))-1 + declare redirect_page="$(( page+1 ))-1" else - declare redirect_page=${page}-${lastview} - template redirect 0-${MAXPREVIEWS}.html - redirect_page=1-1 + declare redirect_page="${page}-${lastview}" + template redirect "0-${MAXPREVIEWS}.html" + redirect_page='1-1' fi - template redirect ${nextredirect}.html + template redirect "${nextredirect}.html" done # Create per album index/redirect page - declare redirect_page=page-1 - template redirect index.html + declare redirect_page='page-1' + template 'redirect' 'index.html' } -function albumindexhtml { +albumindexhtml () { declare -a dirs=( "${1}" ) - declare is_subalbum=no - declare html_dir=html - declare backhref=.. + declare is_subalbum='no' + declare html_dir='html' + declare backhref='..' - template header index.html - template header-first-add index.html + template 'header' 'index.html' + template 'header-first-add' 'index.html' for dir in ${dirs[*]}; do - declare basename=$(basename "$dir") - declare album=$basename + declare basename="$(basename "$dir")" + declare album="$basename" declare thumbs_dir="${DIST_DIR}/thumbs/${basename}" - declare pictures=$(ls "${thumbs_dir}" | wc -l) - declare random_num=$(( 1 + $RANDOM % $pictures )) - declare pages=$(( $pictures / $MAXPREVIEWS + 1 )) + declare pictures="$(ls "${thumbs_dir}" | wc -l)" + declare random_num="$(( 1 + $RANDOM % $pictures ))" + declare pages="$(( $pictures / $MAXPREVIEWS + 1 ))" declare random_thumb="./thumbs/${basename}"/$(find \ "${thumbs_dir}" -type f -printf "%f\n" | head -n ${random_num} | tail -n 1) - [ ${pages} -gt 1 ] && declare s=s || declare s='' + [ ${pages} -gt 1 ] && declare s='s' || declare s='' declare description="${pictures} pictures / ${pages} page${s}" - template index-preview index.html + template 'index-preview' 'index.html' done - template footer index.html + template 'footer' 'index.html' } -function generate { +generate () { if [ ! -d "${INCOMING_DIR}" ]; then echo "ERROR: You have to create ${INCOMING_DIR} first" >&2 exit 1 fi if [ "${TARBALL_INCLUDE}" = yes ]; then - declare -r base=$(basename "${INCOMING_DIR}") - declare -r now=$(date +'%Y-%m-%d-%H%M%S') + declare -r base="$(basename "${INCOMING_DIR}")" + declare -r now="$(date +'%Y-%m-%d-%H%M%S')" declare -r tarball_name="${base}-${now}${TARBALL_SUFFIX}" fi @@ -197,20 +194,18 @@ function generate { scalephotos find "${DIST_DIR}" -type f -name \*.html -delete - declare -a dirs=( $(find "${DIST_DIR}/photos" \ - -mindepth 1 -maxdepth 1 -type d | sort) ) + declare -a dirs=( $(find "${DIST_DIR}/photos" -mindepth 1 -maxdepth 1 -type d | sort) ) # Figure out wether we want sub-albums or not if [[ "${SUB_ALBUMS}" != yes || ${#dirs[*]} -eq 0 ]]; then - declare is_subalbum=no - albumhtml photos html thumbs .. + declare is_subalbum='no' + albumhtml 'photos' 'html' 'thumbs' '..' else - declare is_subalbum=yes + declare is_subalbum='yes' for dir in ${dirs[*]}; do - declare basename=$(basename "${dir}") - albumhtml \ - "photos/${basename}" "html/${basename}" "thumbs/${basename}" ../.. + declare basename="$(basename "${dir}")" + albumhtml "photos/${basename}" "html/${basename}" "thumbs/${basename}" '../..' done # Create an album selection screen @@ -218,34 +213,34 @@ function generate { fi # Create top level index/redirect page - declare html_dir=./ - declare redirect_page=./html/index - template redirect index.html + declare html_dir='./' + declare redirect_page='./html/index' + template 'redirect' 'index.html' - if [ "${TARBALL_INCLUDE}" = yes ]; then + if [ "${TARBALL_INCLUDE}" = 'yes' ]; then tarball fi } -function recursive { - local dir=$(cut -d: -f2 <<< $ARG1) +recursive () { + local dir="$(cut -d: -f2 <<< $ARG1)" - if [ ! -d $dir ]; then + if [ ! -d "$dir" ]; then echo "Directory $dir does not exist!" exit 1 fi find $dir -type d | grep -v '\.HTML' | while read d; do - test ! -d $d.HTML && mkdir $d.HTML - rc_file=$d.HTML/photoalbumrc - cd $d.HTML && cp $RC_FILE $rc_file && chmod 644 $rc_file - echo "INCOMING_DIR=$d" >> $rc_file - echo "DIST_DIR=$d.HTML" >> $rc_file - echo "ORIGINAL_BASEPATH=../../$(basename $d)" >> $rc_file - echo 'FIND_ARGS="-maxdepth 1"' >> $rc_file - photoalbum generate $rc_file + test ! -d "$d.HTML" && mkdir "$d.HTML " + rc_file="$d.HTML/photoalbumrc" + cd "$d.HTML" && cp "$RC_FILE" "$rc_file" && chmod 644 "$rc_file" + echo "INCOMING_DIR=$d" >> "$rc_file" + echo "DIST_DIR=$d.HTML" >> "$rc_file" + echo "ORIGINAL_BASEPATH=../../$(basename $d)" >> "$rc_file" + echo 'FIND_ARGS="-maxdepth 1"' >> "$rc_file" + photoalbum generate "$rc_file" cd - &>/dev/null - test -d $d.HTML && test ! -d $d.HTML/thumbs && rm -Rf $d.HTML + test -d "$d.HTML" && test ! -d "$d.HTML/thumbs" && rm -Rf "$d.HTML" done } -- cgit v1.2.3 From e2e7f1477f16c97c676501ca9b98907135bb8155 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 19 Feb 2022 10:59:23 +0000 Subject: more on shellcheck --- Makefile | 33 ++++++++++---------- share/templates/default/header-first-add.tmpl | 2 +- share/templates/default/prev.tmpl | 2 +- src/photoalbum.sh | 45 ++++++++++++++++----------- 4 files changed, 44 insertions(+), 38 deletions(-) diff --git a/Makefile b/Makefile index 45d804b..8c10c7f 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ NAME=photoalbum #DESTDIR=/ -all: version documentation build +all: version build +version: + cut -d' ' -f2 changelog | head -n 1 | sed 's/(//;s/)//' > .version build: test ! -d ./bin && mkdir ./bin || exit 0 sed "s/PHOTOALBUMVERSION/$$(cat .version)/" src/$(NAME).sh > ./bin/$(NAME) @@ -19,20 +21,17 @@ deinstall: clean: test -d ./bin && rm -Rf ./bin || exit 0 test -d ./debian/photoalbum && rm -Rf ./debian/photoalbum || exit 0 -version: - cut -d' ' -f2 changelog | head -n 1 | sed 's/(//;s/)//' > .version # Builds the documentation into a manpage -documentation: - pod2man --release="$(NAME) $$(cat .version)" \ - --center="User Commands" ./docs/$(NAME).pod > ./docs/$(NAME).1 - pod2text ./docs/$(NAME).pod > ./docs/$(NAME).txt - # For github page - cp ./docs/$(NAME).pod README.pod -release: all - bash -c "git tag $$(cat .version)" - git push --tags - git commit -a -m 'New release' - git push origin master -clean-top: - rm ../$(NAME)_*.tar.gz - rm ../$(NAME)_*.changes +shellcheck: + # SC1090: ShellCheck can't follow non-constant source. Use a directive to specify location. + # SC2012: Use find instead of ls to better handle non-alphanumeric filenames. + # SC2155: Declare and assign separately to avoid masking return values. + # SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails. + # SC2207: Prefer mapfile or read -a to split command output (or quote to avoid splitting). + shellcheck \ + --exclude SC1090 \ + --exclude SC2012 \ + --exclude SC2155 \ + --exclude SC2164 \ + --exclude SC2207 \ + ./src/photoalbum.sh diff --git a/share/templates/default/header-first-add.tmpl b/share/templates/default/header-first-add.tmpl index c6eed3a..436c4e9 100644 --- a/share/templates/default/header-first-add.tmpl +++ b/share/templates/default/header-first-add.tmpl @@ -1,3 +1,3 @@ cat < +

END diff --git a/share/templates/default/prev.tmpl b/share/templates/default/prev.tmpl index 62d5a35..770cf68 100644 --- a/share/templates/default/prev.tmpl +++ b/share/templates/default/prev.tmpl @@ -1,4 +1,4 @@ cat <Previous ${MAXPREVIEWS} pictures of current Album -

+

END diff --git a/src/photoalbum.sh b/src/photoalbum.sh index eb1e06a..500bb2f 100755 --- a/src/photoalbum.sh +++ b/src/photoalbum.sh @@ -73,7 +73,7 @@ albumhtml () { declare photos_dir="${1}" ; shift declare html_dir="${1}" ; shift declare thumbs_dir="${1}" ; shift - declare backhref="${1}" ; shift + export backhref="${1}" ; shift declare -i num=1 declare -i i=0 @@ -122,10 +122,10 @@ albumhtml () { template footer \ "$(cd "${DIST_DIR}/${html_dir}";ls -t page-*.html | head -n 1)" - cd "${DIST_DIR}/${html_dir}" && ls *.html | grep -v page- | cut -d'-' -f1 | uniq | + cd "${DIST_DIR}/${html_dir}" && ls ./*.html | grep -v page- | cut -d'-' -f1 | uniq | while read prefix; do - declare page="$(ls -t ${prefix}-*.html | head -n 1 | sed 's#\(.*\)-.*.html#\1#')" - declare lastview="$(ls -t ${prefix}-*.html | head -n 1 | sed 's/.*-\(.*\).html/\1/')" + declare page="$(ls -t "${prefix}"-*.html | head -n 1 | sed 's#\(.*\)-.*.html#\1#')" + declare lastview="$(ls -t "${prefix}"-*.html | head -n 1 | sed 's/.*-\(.*\).html/\1/')" declare prevredirect="${page}-0" declare nextredirect="${page}-$((lastview+1))" @@ -133,7 +133,7 @@ albumhtml () { declare redirect_page="$(( page-1 ))-${MAXPREVIEWS}" template redirect "${prevredirect}.html" - if [ ${lastview} -eq ${MAXPREVIEWS} ]; then + if [ "$lastview" -eq "$MAXPREVIEWS" ]; then declare redirect_page="$(( page+1 ))-1" else @@ -141,6 +141,7 @@ albumhtml () { template redirect "0-${MAXPREVIEWS}.html" redirect_page='1-1' fi + export redirect_page template redirect "${nextredirect}.html" done @@ -160,18 +161,20 @@ albumindexhtml () { for dir in ${dirs[*]}; do declare basename="$(basename "$dir")" - declare album="$basename" + # TODO: All exported vars in UPPERCASE + export album="$basename" declare thumbs_dir="${DIST_DIR}/thumbs/${basename}" declare pictures="$(ls "${thumbs_dir}" | wc -l)" - declare random_num="$(( 1 + $RANDOM % $pictures ))" - declare pages="$(( $pictures / $MAXPREVIEWS + 1 ))" + declare random_num="$(( 1 + RANDOM % pictures ))" + declare pages="$(( pictures / MAXPREVIEWS + 1 ))" - declare random_thumb="./thumbs/${basename}"/$(find \ + export random_thumb="./thumbs/${basename}"/$(find \ "${thumbs_dir}" -type f -printf "%f\n" | head -n ${random_num} | tail -n 1) - [ ${pages} -gt 1 ] && declare s='s' || declare s='' - declare description="${pictures} pictures / ${pages} page${s}" + declare s='' + [ ${pages} -gt 1 ] && s='s' + export description="${pictures} pictures / ${pages} page${s}" template 'index-preview' 'index.html' done @@ -198,11 +201,11 @@ generate () { # Figure out wether we want sub-albums or not if [[ "${SUB_ALBUMS}" != yes || ${#dirs[*]} -eq 0 ]]; then - declare is_subalbum='no' + export is_subalbum='no' albumhtml 'photos' 'html' 'thumbs' '..' else - declare is_subalbum='yes' + export is_subalbum='yes' for dir in ${dirs[*]}; do declare basename="$(basename "${dir}")" albumhtml "photos/${basename}" "html/${basename}" "thumbs/${basename}" '../..' @@ -223,21 +226,25 @@ generate () { } recursive () { - local dir="$(cut -d: -f2 <<< $ARG1)" + local dir="$(cut -d: -f2 <<< "$ARG1")" if [ ! -d "$dir" ]; then echo "Directory $dir does not exist!" exit 1 fi - find $dir -type d | grep -v '\.HTML' | while read d; do + find "$dir" -type d | grep -v '\.HTML' | while read -r d; do test ! -d "$d.HTML" && mkdir "$d.HTML " rc_file="$d.HTML/photoalbumrc" cd "$d.HTML" && cp "$RC_FILE" "$rc_file" && chmod 644 "$rc_file" - echo "INCOMING_DIR=$d" >> "$rc_file" - echo "DIST_DIR=$d.HTML" >> "$rc_file" - echo "ORIGINAL_BASEPATH=../../$(basename $d)" >> "$rc_file" - echo 'FIND_ARGS="-maxdepth 1"' >> "$rc_file" + + { + echo "INCOMING_DIR=$d"; + echo "DIST_DIR=$d.HTML"; + echo "ORIGINAL_BASEPATH=../../$(basename "$d")"; + echo 'FIND_ARGS="-maxdepth 1"'; + } >> "$rc_file" + photoalbum generate "$rc_file" cd - &>/dev/null test -d "$d.HTML" && test ! -d "$d.HTML/thumbs" && rm -Rf "$d.HTML" -- cgit v1.2.3