Additionally generate thumbnails for last year on the first of Janary

This commit is contained in:
2020-01-10 11:23:02 +01:00
parent fdc532a966
commit 3605349e0f
2 changed files with 42 additions and 26 deletions

View File

@@ -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"

View File

@@ -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 <SUBDIR>
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