#!/bin/bash VERS='1.0.0-07152023' source /opt/idssys/defaults/colors.inc source /opt/idssys/defaults/default.inc source /opt/idssys/emulator-sync/settings.conf ESFOLDER=/opt/idssys/emulator-sync SYNC_FOLDER="${ESFOLDER}/._sync_nextcloud" [ ! -d ${SYNC_FOLDER} ] && mkdir ${SYNC_FOLDER} SENDNOTICE(){ [ "${PUSHOVER_APP_TOKEN}" != "" ] && PUSH_TO_MOBILE "${2} $(date)" "${1}" ${3} & [ "${EMAIL_NOTICE}" != "" ] && echo -e "${1}\n\n$(date)" | mail -s "${2}" ${EMAIL_NOTICE} } RUNSYNC(){ [ -f ${ESFOLDER}/nc-sync.running ] && [ $(expr $(date +%s) - $(stat -L --format %Y ${ESFOLDER}/nc-sync.running)) -gt 21600 ] && /bin/rm -f ${ESFOLDER}/nc-sync.running if [ ! -f ${ESFOLDER}/nc-sync.running ]; then touch ${ESFOLDER}/nc-sync.running if [ ! -f ${NC_PATH}/mounted ]; then /usr/bin/mount -a sleep 5s fi if [ -f ${NC_PATH}/mounted ] || [ "${1}" == "skipmount" ]; then echo -en "${idsCL[LightCyan]}Sync Started : ${idsCL[Default]}" [ -f ${ESFOLDER}/mount.failure ] && /bin/rm -f ${ESFOLDER}/mount.failure if [ -f ${SYNC_FOLDER}/failures.txt ]; then echo -e "${idsCL[Red]}Failed${idsCL[Default]}" if [ -f ${SYNC_FOLDER}/failures2.txt ]; then echo "Nextcloud sync failure, ${SYNC_FOLDER}/failures.txt exists." SENDNOTICE "Nextcloud Sync Failure" "${SYNC_FOLDER}/failures.txt Exists\n\n$(date)" 1 /bin/rm -f ${ESFOLDER}/nc-sync.running exit 1 else /bin/mv ${SYNC_FOLDER}/failures.txt ${SYNC_FOLDER}/failures2.txt fi fi if [ ! -f ${SYNC_FOLDER}/failures.txt ]; then ${ESFOLDER}/nextcloud-sync-cron/nextcloud-sync-cron.sh --verbose --logdir ${SYNC_FOLDER} ${ESFOLDER}/nextcloud-client.conf echo -e "${idsCL[Green]}Done${idsCL[Default]}" if [ -f ${SYNC_FOLDER}/failures2.txt ] && [ ! -f ${SYNC_FOLDER}/failures.txt ]; then echo "$(date): Fixed" >> ${NC_PATH}/sync.log SENDNOTICE "Nextcloud Sync Fixed" "Sync is running again" /bin/rm -f ${SYNC_FOLDER}/failures* fi /bin/rm -f ${ESFOLDER}/nc-sync.running fi else if [ -f ${ESFOLDER}/mount.failure ]; then SENDNOTICE "Nextcloud Sync Unmounted" "The folder ${NC_PATH} Cannot be mounted" 1 /bin/rm -f ${ESFOLDER}/nc-sync.running exit 1 else /usr/bin/mount -a touch ${ESFOLDER}/mount.failure /bin/rm -f ${ESFOLDER}/nc-sync.running exit 1 fi fi else echo "There is a sync in process" exit 0 fi } echo echo -e "${idsCL[LightGreen]} Emulator-Nextcloud-Sync ${idsCL[Default]} ${idsCL[DarkGray]}(ver-${VERS})${idsCL[Default]}" DIVIDER . lightGreen echo case ${1} in sync) RUNSYNC ${2};; esac exit 1