From 072e1d8f133546ddb2cf5fa42eab900f4277c63a Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Wed, 8 Jan 2020 21:57:52 +0100 Subject: [PATCH] Add missing subdirectory if parent directory exists Mostly when a new year begins --- piwisync.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/piwisync.sh b/piwisync.sh index d957c48..5693ac1 100755 --- a/piwisync.sh +++ b/piwisync.sh @@ -19,14 +19,22 @@ fi subDir="$myyear/" thumbRoot="${piwiThumbRoot}/${subDir}" photoRoot="${piwiPhotoRoot}/${subDir}" +local yearRegex='[0-9]{4}' if [ ! -e ${thumbRoot} ] ; then - echo "Thumbnail root ${thumbRoot} not found" - exit 1; + 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" + exit 1; + fi fi if [ ! -e ${photoRoot} ] ; then - echo "Photo root ${photoRoot} not found" + echo " [E] Photo root ${photoRoot} not found" exit 1; fi