diff --git a/piwirefresh.sh b/piwirefresh.sh index 7e0de8d..6790f13 100755 --- a/piwirefresh.sh +++ b/piwirefresh.sh @@ -1,41 +1,47 @@ #!/bin/bash -mountedCheckFile="/home/network/Qbilder/photos/.mounted" -catId=0 -subCatId=1 +# Get script working directory +# (when called from a different directory) +WDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )" + +if [ ! -s "$WDIR/config.sh" ] ; then + echo "No configuration found" + exit 1; +fi +. "$WDIR/config.sh" STARTTIME=$(date +%s) # -s : file exists and has a size greater than zero -if [ ! -s "$mountedCheckFile" ] ; then - echo "[refresh] Network not available (exists: $mountedCheckFile)" +if [ ! -s "$piwiMountedCheckFile" ] ; then + echo "[refresh] Network not available (exists: $piwiMountedCheckFile)" exit 1; fi # check if the file is really readable and contains text -mounted=$(cat "$mountedCheckFile" 2>>/dev/null) +mounted=$(cat "$piwiMountedCheckFile" 2>>/dev/null) if [ -z $mounted ] ; then - echo "[refresh] Network not available (content: $montedCheckFile)" + echo "[refresh] Network not available (content: $piwiMountedCheckFile)" exit 1; fi if [ "$1" != "" ] && [ "$2" != "" ] then - catId=$1 - subCatId=$2 + piwiRefreshCatId=$1 + piwiRefreshSubCatId=$2 fi perl -w /root/script/piwigo_refresh.pl \ - --base_url=https://change.me/gallery \ - --site=2 \ - --user="-change me-" \ - --password="-change me-" \ - --directory="/var/www/piwigo/network" \ + --base_url="${piwiRefreshUrl}" \ + --site=${piwiRefreshSiteId} \ + --user="${piwiRefreshUser}" \ + --password="${piwiRefreshPass}" \ + --directory="${piwiRefreshSite}" \ --caddie=0 \ - --privacy_level=4 \ - --cat=${catId} \ - --subcat=${subCatId} + --privacy_level=${piwiRefreshPrivacy} \ + --cat=${piwiRefreshCatId} \ + --subcat=${piwiRefreshSubCatId} ENDTIME=$(date +%s) echo "Refresh took: $((($ENDTIME - $STARTTIME)/60)) minutes" diff --git a/piwisync.sh b/piwisync.sh index e5693c1..d957c48 100755 --- a/piwisync.sh +++ b/piwisync.sh @@ -1,24 +1,35 @@ #!/bin/bash -myyear=$(date "+%Y") +# Get script working directory +# (when called from a different directory) +WDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )" +if [ ! -s "$WDIR/config.sh" ] ; then + echo "No configuration found" + exit 1; +fi +. "$WDIR/config.sh" + +myyear=$(date "+%Y") if [ "$1" != "" ] then myyear=$1 - #echo Error subdir parameter missing - #exit 1; fi subDir="$myyear/" -piwigoThumbRoot="/var/www/piwigo/_data/i/network/network/${subDir}" -networkPhotoRoot="/home/network/Qbilder/photos/${subDir}" +thumbRoot="${piwiThumbRoot}/${subDir}" +photoRoot="${piwiPhotoRoot}/${subDir}" -if [ ! -e ${networkPhotoRoot} ] -then - echo "${networkPhotoRoot} not found" +if [ ! -e ${thumbRoot} ] ; then + echo "Thumbnail root ${thumbRoot} not found" exit 1; fi -/root/script/piwigo_thumbgen.sh "${networkPhotoRoot}" "${piwigoThumbRoot}" +if [ ! -e ${photoRoot} ] ; then + echo "Photo root ${photoRoot} not found" + exit 1; +fi -/root/script/piwirefresh.sh +$WDIR/piwigo_thumbgen.sh "${photoRoot}" "${thumbRoot}" + +$WDIR/piwirefresh.sh diff --git a/piwisyncremote.sh b/piwisyncremote.sh index 826d1f9..01efcd2 100755 --- a/piwisyncremote.sh +++ b/piwisyncremote.sh @@ -7,51 +7,55 @@ # TODO Adjust password in the line where sshfs is mounted # TODO Adjust following directories to fit your needs -remotePhotoRoot="/var/www/piwigo/_data/i/network/network" -networkPhotoRoot="/home/network/Bilder/photos/" -localTemp="/tmp/piwiTemp/" -piwigoThumbRoot="/tmp/piwiMnt/" -sshfsAccess="user@host" +# Get script working directory +# (when called from a different directory) +WDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )" + +if [ ! -s "$WDIR/config.sh" ] ; then + echo "No configuration found" + exit 1; +fi +. "$WDIR/config.sh" if [ "$1" == "" ] then echo "Subfolder must be provided!" - echo "Source: $networkPhotoRoot" - echo "Remote: ${remotePhotoRoot}[subfolder]" + echo "Source: $piwiPhotoRootRemote" + echo "Remote: ${piwiThumbRootRemote}[subfolder]" exit 1; fi subDir="$1/" -if [ ! -e ${networkPhotoRoot}${subDir} ] +if [ ! -e ${piwiPhotoRootRemote}${subDir} ] then - echo "${networkPhotoRoot}${subDir} not found" + echo "${piwiPhotoRootRemote}${subDir} not found" exit 1; fi -mkdir -p "${localTemp}" "${piwigoThumbRoot}" +mkdir -p "${piwiLocalTemp}" "${piwiLocalThumbRoot}" -./piwigo_thumbgen.sh "${networkPhotoRoot}${subDir}" "${localTemp}${subDir}" +$WDIR/piwigo_thumbgen.sh "${piwiPhotoRootRemote}${subDir}" "${piwiLocalTemp}${subDir}" -if [[ -z $(mount | grep ${piwigoThumbRoot}) ]] +if [[ -z $(mount | grep ${piwiLocalThumbRoot}) ]] then - echo "mounting $piwigoThumbRoot..." - sshfs ${sshfsAccess}:${remotePhotoRoot} ${piwigoThumbRoot} -o password_stdin <<< "-change me-" + echo -n "mounting $piwiLocalThumbRoot ..." + sshfs ${piwiRemoteUser}@${piwiRemoteHost}:${piwiThumbRootRemote} ${piwiLocalThumbRoot} -o password_stdin <<< "${piwiRemotePass}" && echo "ok" fi -if [[ ! -z $(mount | grep ${piwigoThumbRoot}) ]] +if [[ ! -z $(mount | grep ${piwiLocalThumbRoot}) ]] then echo "copying thumbnails to webserver..." - rsync --ignore-existing -r "${localTemp}${subDir}" "${piwigoThumbRoot}${subDir}" + rsync --ignore-existing -r "${piwiLocalTemp}${subDir}" "${piwiLocalThumbRoot}${subDir}" fi -echo "chown -R www-data: ${remotePhotoRoot}/${subDir} (on your webserver)" +echo "chown -R www-data: ${piwiThumbRootRemote}/${subDir} (on your webserver)" echo "Symlink network drive on webserver (e.g. /var/www/piwigo/network/network/${subDir})" read -n 1 -s -r -p "Press any key to continue" echo -e -n "\nUpdating gallery..." -./piwirefresh.sh && echo "Ok" +$WDIR/piwirefresh.sh && echo "Ok" -echo "Don't forget to sudo umount ${piwigoThumbRoot}" +echo "Don't forget to sudo umount ${piwiLocalThumbRoot}" exit 0;