diff options
| author | Paul Buetow <paul@buetow.org> | 2022-02-19 11:01:48 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2022-02-19 11:01:48 +0000 |
| commit | 6feae6c65217e8b82c33d3fd4c15be09293ebf9f (patch) | |
| tree | 666d35cd48ce3598634f536889e5665b5e26c25d | |
| parent | 1c460f748c9695d03d34c37a0abf5f91e7a9c7a2 (diff) | |
| parent | e2e7f1477f16c97c676501ca9b98907135bb8155 (diff) | |
merged
| -rw-r--r-- | IDEA.md | 1 | ||||
| -rw-r--r-- | Makefile | 34 | ||||
| -rw-r--r-- | README.pod | 58 | ||||
| -rw-r--r-- | docs/photoalbum.1 | 6 | ||||
| -rw-r--r-- | docs/photoalbum.pod | 2 | ||||
| -rw-r--r-- | docs/photoalbum.txt | 2 | ||||
| -rw-r--r-- | share/templates/default/footer.tmpl | 2 | ||||
| -rw-r--r-- | share/templates/default/header-first-add.tmpl | 2 | ||||
| -rw-r--r-- | share/templates/default/prev.tmpl | 2 | ||||
| -rw-r--r-- | src/photoalbum.default.conf | 9 | ||||
| -rwxr-xr-x | src/photoalbum.sh | 174 |
11 files changed, 179 insertions, 113 deletions
@@ -0,0 +1 @@ +I could use https://masonry.desandro.com/ to line up the photos niceley. But also keep a HTML-only version available. @@ -1,5 +1,8 @@ NAME=photoalbum -all: version documentation build +#DESTDIR=/ +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) @@ -18,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/README.pod b/README.pod new file mode 100644 index 0000000..9c55dd7 --- /dev/null +++ b/README.pod @@ -0,0 +1,58 @@ +=head1 NAME + +photoalbum - photoalbum is a minimal bash script for linux to generate static web photo albums. + +=head1 SYNOPSIS + +photoalbum clean|generate|version|recursive:DIR [rcfile] +photoalbum makemake + +=over + +=item clean + +Cleans up the working space + +=item version + +Prints out the version + +=item generate + +Generates the static photoalbum + +=item makemake + +Creates a Makefile and photoalbumrc in the current working directory. + +=back + +=head2 RCFILE + +=head2 TUTORIAL + +* See if /etc/default/photoalbum fits your needs. If not, copy /etc/default/photoalbum to ~/.photoalbumrc in order to customize it. + +* Copy all images wanted to the incoming folder (see config file) + +* Run 'photoalbum generate' + +* Distribute the ./dist directory + +* Clean the mess up with 'photoalbum clean' + +It is possible to specify a custom rcfile path too. + +=head3 HTML TEMPLATES + +Go to the templates directory and edit them as wished. + +=head1 LICENSE + +See package description or project website. + +=head1 AUTHOR + +Paul Buetow - <http://buetow.org> + +=cut diff --git a/docs/photoalbum.1 b/docs/photoalbum.1 index e9878ae..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 @@ -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 \- <http://photoalbum.buetow.org> +Paul Buetow \- <http://buetow.org> 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 - <http://photoalbum.buetow.org> +Paul Buetow - <http://buetow.org> =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 - <http://photoalbum.buetow.org> + Paul Buetow - <http://buetow.org> 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 -Page generated at $(date) using Bash and ImageMagick at $(uname); <photoalbum@mx.buetow.org> +Page generated at $(date) using Bash and ImageMagick at $(uname); <photoalbum@dev.buetow.org> </body> </html> END 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.default.conf b/src/photoalbum.default.conf index 8f4e488..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 -THUMBGEOMETRY=100 -GEOMETRY=1600 +# Thumbnail geometry +THUMBGEOMETRY=250 +# 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 2295201..74e89b9 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 +# photoalbum (c) 2011 - 2014, 2022 by Paul Buetow +# https://codeberg.org/foozone/photoalbum readonly VERSION='PHOTOALBUMVERSION' readonly DEFAULTRC=/etc/default/photoalbum @@ -16,14 +16,14 @@ USAGE } makemake () { - [ ! -f ./photoalbumrc ] && cp /etc/default/photoalbum ./photoalbumrc + [ ! -f ./photoalbumrc ] && cp "$DEFAULTRC" ./photoalbumrc cat <<MAKEFILE > ./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' } tarball () { @@ -32,7 +32,7 @@ tarball () { readonly 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 } @@ -50,17 +50,21 @@ template() { 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 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 } @@ -69,15 +73,15 @@ 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 - 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 @@ -87,26 +91,26 @@ 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}"; @@ -116,65 +120,65 @@ 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 | + 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 + if [ "$lastview" -eq "$MAXPREVIEWS" ]; then + 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 + export redirect_page + 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' } 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")" + # 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 pictures="$(ls "${thumbs_dir}" | wc -l)" + 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}" - template index-preview index.html + declare s='' + [ ${pages} -gt 1 ] && s='s' + export description="${pictures} pictures / ${pages} page${s}" + template 'index-preview' 'index.html' done - template footer index.html + template 'footer' 'index.html' } generate () { @@ -193,20 +197,18 @@ 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 .. + 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}" ../.. + declare basename="$(basename "${dir}")" + albumhtml "photos/${basename}" "html/${basename}" "thumbs/${basename}" '../..' done # Create an album selection screen @@ -214,34 +216,38 @@ 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 } recursive () { - local dir=$(cut -d: -f2 <<< $ARG1) + 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 + 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"; + 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 + test -d "$d.HTML" && test ! -d "$d.HTML/thumbs" && rm -Rf "$d.HTML" done } |
