diff options
| author | Paul Buetow <paul@buetow.org> | 2022-02-19 10:59:23 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2022-02-19 10:59:23 +0000 |
| commit | e2e7f1477f16c97c676501ca9b98907135bb8155 (patch) | |
| tree | 6556c19593b2920f18dbf4118a1fe849e86fabf4 | |
| parent | 75c62b3abb4f84c2dc967b9f9289df10cb6af227 (diff) | |
more on shellcheck
| -rw-r--r-- | Makefile | 33 | ||||
| -rw-r--r-- | share/templates/default/header-first-add.tmpl | 2 | ||||
| -rw-r--r-- | share/templates/default/prev.tmpl | 2 | ||||
| -rwxr-xr-x | src/photoalbum.sh | 45 |
4 files changed, 44 insertions, 38 deletions
@@ -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 -<p align='right'> +<p align='center'> 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 <<END <a href='${prev}.html'>Previous ${MAXPREVIEWS} pictures of current Album</a> -<p align='right'> +<p align='center'> 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" |
