From 3605349e0f61e41131507c2b341deb8525d5ebf9 Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Fri, 10 Jan 2020 11:23:02 +0100 Subject: [PATCH] Additionally generate thumbnails for last year on the first of Janary --- piwigo_thumbgen.sh | 4 +-- piwisync.sh | 64 +++++++++++++++++++++++++++++----------------- 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/piwigo_thumbgen.sh b/piwigo_thumbgen.sh index 716308f..9c07253 100755 --- a/piwigo_thumbgen.sh +++ b/piwigo_thumbgen.sh @@ -6,8 +6,8 @@ shopt -s globstar #echo "Starting Piwigo thumbnail generation" #Remember a trailing '/' -sourceDir="$1" -destDir="$2" +sourceDir="$1/" +destDir="$2/" echo "Source: $sourceDir" echo "Dest: $destDir" diff --git a/piwisync.sh b/piwisync.sh index 626cdeb..392bf06 100755 --- a/piwisync.sh +++ b/piwisync.sh @@ -5,39 +5,55 @@ WDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )" if [ ! -s "$WDIR/config.sh" ] ; then - echo "No configuration found" + echo " [E] No configuration found" exit 1; fi . "$WDIR/config.sh" -myyear=$(date "+%Y") -if [ "$1" != "" ] -then - myyear=$1 +myYear=$(date "+%Y") +myMonth=$(date "+%m") +myDay=$(date "+%d") +lastYear=$(($(date +%Y)-1)) + +if [ ! -z $1 ] ; then + myYear="$1" fi -subDir="$myyear/" -thumbRoot="${piwiThumbRoot}/${subDir}" -photoRoot="${piwiPhotoRoot}/${subDir}" -yearRegex='[0-9]{4}' - -if [ ! -e ${thumbRoot} ] ; then - if [ -w ${piwiThumbRoot} ] && [[ "$subDir" =~ $yearRegex ]] ; then - # Thumb root of piwigo available just subdir missing - echo " [I] Adding missing year subdirectory $(basename $subDir) to $piwiThumbRoot" - echo " Happy new year $(basename $subDir) I guess ;)" - mkdir -p "$thumbRoot" - else - echo " [E] Thumbnail root ${thumbRoot} not found" +# genThumbs +genThumbs() { + if [ -z $1 ] ; then + echo " [W] No photo subdirectory provided" + return 1; + fi + + local thumbRoot="${piwiThumbRoot}/$1" + local photoRoot="${piwiPhotoRoot}/$1" + + if [ ! -e ${photoRoot} ] ; then + echo " [E] Photo root ${photoRoot} not found" exit 1; fi -fi -if [ ! -e ${photoRoot} ] ; then - echo " [E] Photo root ${photoRoot} not found" - exit 1; -fi + if [ ! -e ${thumbRoot} ] ; then + if [ -w ${piwiThumbRoot} ] ; then + # Thumb root of piwigo available just subdir missing + echo " [I] Adding missing subdirectory $(basename $1) to $piwiThumbRoot" + mkdir -p "$thumbRoot" + else + echo " [E] Thumbnail root ${thumbRoot} not found" + exit 1; + fi + fi -$WDIR/piwigo_thumbgen.sh "${photoRoot}" "${thumbRoot}" + $WDIR/piwigo_thumbgen.sh "${photoRoot}" "${thumbRoot}" +} + +# On the first day of the year generate last year's thumbnails for the last time +if [ $myMonth -eq 1 ] && [ $myDay -eq 1 ] ; then + echo " [I] Generate $lastYear thumbnails for the last time" + echo " Happy new year $(date +%Y), I guess ;)" + genThumbs "$lastYear" +fi +genThumbs "$myYear" $WDIR/piwirefresh.sh