Files
emulator-sync/emulator-sync-scripts.sh

84 lines
2.3 KiB
Bash
Executable File

#!/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=${ESFOLDER}
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}
}
[ -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
[ -f ${ESFOLDER}/mount.failure ] && /bin/rm -f ${ESFOLDER}/mount.failure
if [ -f ${SYNC_FOLDER}/failures.txt ]; then
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
echo "Sync Started"
${ESFOLDER}/nextcloud-sync-cron/nextcloud-sync-cron.sh --verbose ${ESFOLDER}/nextcloud-client.conf
echo "Sync Finished"
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
exit 0
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) NEWCERT ${2};;
esac
exit 1