From c94c7a1b41c7caea3699e66f99053df2d509bb05 Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Mon, 30 Sep 2024 18:06:07 -0500 Subject: [PATCH] update --- defaults.inc | 2 +- mm-scripts.sh | 124 ++++++++++++++++++++++++++------------------------ 2 files changed, 65 insertions(+), 61 deletions(-) diff --git a/defaults.inc b/defaults.inc index b14fc43..6ef9c27 100755 --- a/defaults.inc +++ b/defaults.inc @@ -1,6 +1,6 @@ #!/usr/bin/env bash -VERS='3.9.85-09302024' +VERS='3.9.86-09302024' MMFOLDER="/opt/idssys/mediamanager" TMPFOLDER="${MMFOLDER}/.tmp" diff --git a/mm-scripts.sh b/mm-scripts.sh index d24a9ca..2e43881 100755 --- a/mm-scripts.sh +++ b/mm-scripts.sh @@ -334,71 +334,75 @@ MMSTART(){ exit 1 fi - msg="Verifying Plex Media is Mounted" - c=0; spc=''; spc1=$((${cw_spc}-${#msg})) - until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done - echo -en "${idsCL[LightCyan]}${msg}${spc} ${idsCL[White]}: ${idsCL[Default]}" - [ "${1}" == "start" ] && [ "${2}" != "vpn" ] && rm -f ${TMPFOLDER}/mm.noservices - ### CHECK FOR PLEX MOUNT - if [ ! -f ${PLEX_MOUNT}/mounted ] && [ "${2}" != "vpn" ] && [ ! -f ${TMPFOLDER}/mm.noservices ]; then - echo "$(date) - Plex Media Not Mounted, will try and mount" >> ${MM_LOGFILE} - umount ${PLEX_MOUNT} >/dev/null 2>&1 - sleep 2s - mount -a >/dev/null 2>&1 - sleep 2s + if [ ${SERVICESCHECK} != "" ]; then + msg="Verifying Plex Media is Mounted" + c=0; spc=''; spc1=$((${cw_spc}-${#msg})) + until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done + echo -en "${idsCL[LightCyan]}${msg}${spc} ${idsCL[White]}: ${idsCL[Default]}" + + ### CHECK FOR PLEX MOUNT + if [ ! -f ${PLEX_MOUNT}/mounted ] && [ "${2}" != "vpn" ] && [ ! -f ${TMPFOLDER}/mm.noservices ] && [ ! -f ${MMFOLDER}/mm.noservices ]; then + echo "$(date) - Plex Media Not Mounted, will try and mount" >> ${MM_LOGFILE} + umount ${PLEX_MOUNT} >/dev/null 2>&1 + sleep 2s + mount -a >/dev/null 2>&1 + sleep 2s - if [ ! -f ${PLEX_MOUNT}/mounted ]; then - if [ -f "${TMPFOLDER}/mm.plexmount.fail2" ]; then - fd=$(( `date +%s` - `stat -L --format %Y "${TMPFOLDER}/mm.plexmount.fail2"` )) - [ ${fd} -gt 100 ] && PMFS=true || PMFS=false - elif [ -f ${TMPFOLDER}/mm.plexmount.fail ]; then - fd=$(( `date +%s` - `stat -L --format %Y ${TMPFOLDER}/mm.plexmount.fail` )) - [ ${fd} -gt 100 ] && PMFS=true || PMFS=false - else - PMFS=true - fi + if [ ! -f ${PLEX_MOUNT}/mounted ]; then + if [ -f "${TMPFOLDER}/mm.plexmount.fail2" ]; then + fd=$(( `date +%s` - `stat -L --format %Y "${TMPFOLDER}/mm.plexmount.fail2"` )) + [ ${fd} -gt 100 ] && PMFS=true || PMFS=false + elif [ -f ${TMPFOLDER}/mm.plexmount.fail ]; then + fd=$(( `date +%s` - `stat -L --format %Y ${TMPFOLDER}/mm.plexmount.fail` )) + [ ${fd} -gt 100 ] && PMFS=true || PMFS=false + else + PMFS=true + fi - if [ ${PMFS} = true ]; then - [ -f "${TMPFOLDER}/mm.plexmount.fail2" ] && touch ${TMPFOLDER}/mm.plexmount.fail2 || touch ${TMPFOLDER}/mm.plexmount.fail - SENDNOTICE "Plex Media Not Mounted" "Could not mount the Plex Media Folder" 1 - echo "$(date) - Plex Media could not be mounted" >> ${MM_LOGFILE} - fi - if [ ! -f ${TMPFOLDER}/mm.plexmount.fail2 ]; then - echo -e "${idsCL[Red]}Not Mounted${idsCL[Default]}" + if [ ${PMFS} = true ]; then + [ -f "${TMPFOLDER}/mm.plexmount.fail2" ] && touch ${TMPFOLDER}/mm.plexmount.fail2 || touch ${TMPFOLDER}/mm.plexmount.fail + SENDNOTICE "Plex Media Not Mounted" "Could not mount the Plex Media Folder" 1 + echo "$(date) - Plex Media could not be mounted" >> ${MM_LOGFILE} + fi + if [ ! -f ${TMPFOLDER}/mm.plexmount.fail2 ]; then + echo -e "${idsCL[Red]}Not Mounted${idsCL[Default]}" + for srvc in "${SERVICES_CHECK[@]}"; do + /bin/systemctl stop ${srvc} >/dev/null 2>&1 & + done + else + echo -e "${idsCL[Red]}Not Mounted${idsCL[LightCyan]}, running services as chosen previously though${idsCL[Default]}" + fi + + else + echo -e "${idsCL[Green]}Mounted, fixed${idsCL[Default]}" + SENDNOTICE "Plex Media Mounted" "The Plex Media Folder was successfully re-mounted again!" + echo "$(date) - Plex Media now mounted, restarting services" >> ${MM_LOGFILE} for srvc in "${SERVICES_CHECK[@]}"; do - /bin/systemctl stop ${srvc} >/dev/null 2>&1 & + /bin/systemctl restart ${srvc} >/dev/null 2>&1 & done - else - echo -e "${idsCL[Red]}Not Mounted${idsCL[LightCyan]}, running services as chosen previously though${idsCL[Default]}" + rm -f ${TMPFOLDER}/mm.plexmount.fail* fi - + elif [ "${2}" == "vpn" ] || [ -f ${TMPFOLDER}/mm.noservices ] || [ -f ${MMFOLDER}/mm.noservices ]; then + echo -e "${idsCL[LightCyan]}Skipping, started wtih VPN only${idsCL[Default]}" else - echo -e "${idsCL[Green]}Mounted, fixed${idsCL[Default]}" - SENDNOTICE "Plex Media Mounted" "The Plex Media Folder was successfully re-mounted again!" - echo "$(date) - Plex Media now mounted, restarting services" >> ${MM_LOGFILE} - for srvc in "${SERVICES_CHECK[@]}"; do - /bin/systemctl restart ${srvc} >/dev/null 2>&1 & - done - rm -f ${TMPFOLDER}/mm.plexmount.fail* + echo -e "${idsCL[Green]}Mounted${idsCL[Default]}" + if [ -f ${TMPFOLDER}/mm.plexmount.fail ]; then + echo -e "${idsCL[Green]}Mounted, fixed${idsCL[Default]}" + SENDNOTICE "Plex Media Mounted" "The Plex Media Folder was successfully re-mounted again!" + echo "$(date) - Plex Media now mounted, restarting services" >> ${MM_LOGFILE} + for srvc in "${SERVICES_CHECK[@]}"; do + /bin/systemctl restart ${srvc} >/dev/null 2>&1 & + done + rm -f ${TMPFOLDER}/mm.plexmount.fail* + fi fi - elif [ "${2}" == "vpn" ] || [ -f ${TMPFOLDER}/mm.noservices ] || [ -f ${MMFOLDER}/mm.noservices ]; then - echo -e "${idsCL[LightCyan]}Skipping, started wtih VPN only${idsCL[Default]}" else - echo -e "${idsCL[Green]}Mounted${idsCL[Default]}" - if [ -f ${TMPFOLDER}/mm.plexmount.fail ]; then - echo -e "${idsCL[Green]}Mounted, fixed${idsCL[Default]}" - SENDNOTICE "Plex Media Mounted" "The Plex Media Folder was successfully re-mounted again!" - echo "$(date) - Plex Media now mounted, restarting services" >> ${MM_LOGFILE} - for srvc in "${SERVICES_CHECK[@]}"; do - /bin/systemctl restart ${srvc} >/dev/null 2>&1 & - done - rm -f ${TMPFOLDER}/mm.plexmount.fail* - fi + echo -e "${idsCL[LightCyan]}Skipping, started wtih VPN only${idsCL[Default]}" fi - if [ -f ${TMPFOLDER}/mm.plexmount.fail ] && [ "${1}" == "start" ] && [ "${2}" != "vpn" ]; then + if [ -f ${TMPFOLDER}/mm.plexmount.fail ] && [ ! -f ${TMPFOLDER}/mm.noservices ] && [ ! -f ${MMFOLDER}/mm.noservices ] && [ "${1}" == "start" ] && [ "${2}" != "vpn" ]; then echo -en "${idsCL[LightCyan]}Would you like to start services without Plex Media being mounted? ${idsCL[LightYellow]}(y/N)${idsCL[LightCyan]}? ${idsCL[Default]}" read -n 1 choice case "$choice" in @@ -417,7 +421,7 @@ MMSTART(){ msg="${mmsv} Services"; c=0; spc=''; spc1=$((${cw_spc}-${#msg})); until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done echo -en "${idsCL[LightCyan]}${msg}${spc} ${idsCL[White]}: ${idsCL[Default]}" - if [ "${2}" != "vpn" ] && [ ! -f ${TMPFOLDER}/mm.noservices ] && [ ! -f ${TMPFOLDER}/mm.plexmount.fail ]; then + if [ "${2}" != "vpn" ] && [ ! -f ${TMPFOLDER}/mm.noservices ] && [ ! -f ${MMFOLDER}/mm.noservices ] && [ ! -f ${TMPFOLDER}/mm.plexmount.fail ]; then for srvc in "${SERVICES_CHECK[@]}"; do [ "$(systemctl is-active ${srvc})" != "active" ] && /bin/systemctl restart ${srvc} done @@ -475,7 +479,7 @@ MMSTART(){ done echo -e "${idsCL[Green]}Done${idsCL[Default]}" - elif [ -f ${TMPFOLDER}/mm.noservices ]; then + elif [ -f ${TMPFOLDER}/mm.noservices ] || [ -f ${MMFOLDER}/mm.noservices ]; then echo -e "${idsCL[LightCyan]}Skipping, started wtih VPN only${idsCL[Default]}" elif [ -f ${TMPFOLDER}/mm.plexmount.fail ]; then echo -e "${idsCL[LightCyan]}Skipping, plex media is not mounted${idsCL[Default]}" @@ -588,8 +592,8 @@ MMSTOP(){ echo -e "${idsCL[Green]}Done${idsCL[Default]}" rm -f ${TMPFOLDER}/vpninfo* - rm -f ${TMPFOLDER}/realwanip - rm -f ${TMPFOLDER}/mm.noservices* + rm -f ${ TMPFOLDER}/realwanip + if [ ! -f ${MMFOLDER}/mm.noservices ] rm -f ${TMPFOLDER}/mm.noservices* rm -f ${TMPFOLDER}/mm.plexmount.fail* rm -f ${TMPFOLDER}/mm.stop.checking @@ -623,7 +627,7 @@ MMSTATUS(){ echo -en " ${idsCL[White]}${dispname}${spc}${idsCL[White]}: ${idsCL[Default]}" if [ "$(systemctl is-active ${srvc})" != "active" ] && [ "${srvc}" != "wireguard" ]; then - if [ -f ${TMPFOLDER}/mm.noservices ]; then + if [ -f ${TMPFOLDER}/mm.noservices ] || [ -f ${MMFOLDER}/mm.noservices ]; then echo -e "${idsCL[LightCyan]}Skipping, started wtih VPN only${idsCL[Default]}" elif [ -f ${TMPFOLDER}/mm.plexmount.fail ]; then echo -e "${idsCL[LightCyan]}Skipping, Plex Media not mounted${idsCL[Default]}" @@ -1194,7 +1198,7 @@ SERVICEBACKUPSTART(){ msg="Starting Service"; c=0; spc=''; spc1=$((${cw_spc}-${#msg})); until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done echo -en "${idsCL[White]}${msg}${spc} : ${idsCL[Default]}" OUT=$(ip link | grep "$VPN_INTERFACE") >/dev/null 2>&1 - if [ ! -f ${TMPFOLDER}/mm.stop ] && [[ " ${SERVICES_CHECK[*]} " =~ " ${usrvc} " ]] && [ ! -f ${TMPFOLDER}/mm.noservices ] && [ ! `find /opt/idssys/mediamanager/ -name 'mm.plexmount.fail*'` ]; then + if [ ! -f ${TMPFOLDER}/mm.stop ] && [[ " ${SERVICES_CHECK[*]} " =~ " ${usrvc} " ]] && [ ! -f ${TMPFOLDER}/mm.noservices ] && [ ! -f ${MMFOLDER}/mm.noservices ] && [ ! `find /opt/idssys/mediamanager/ -name 'mm.plexmount.fail*'` ]; then /bin/systemctl disable ${usrvc} >> ${LOGFOLDER}/update.${usrvc} /bin/systemctl start ${usrvc} >> ${LOGFOLDER}/update.${usrvc} [ "${usrvc}" == "radarr" ] && [[ " ${SERVICES_CHECK[*]} " =~ " radarr3d " ]] && /bin/systemctl start radarr3d >> ${LOGFOLDER}/update.${usrvc} @@ -1773,7 +1777,7 @@ if [ ! -f ${TMPFOLDER}/mm.update.stop ]; then echo exit 1 fi - [ -f ${TMPFOLDER}/mm.noservices ] && rv="vpn" || rv="" + ([ -f ${TMPFOLDER}/mm.noservices ] || [ -f ${MMFOLDER}/mm.noservices ]) && rv="vpn" || rv="" MMSTOP echo -en "${idsCL[LightCyan]}Pausing for 30s to ensure a new VPN WAN IP, or press any key to continue with potentially getting a new address ... ${idsCL[Default]}" read -et 30 -n 1