This commit is contained in:
2023-05-03 21:32:07 -05:00
parent a6ba65260b
commit 0b76804649
3 changed files with 107 additions and 105 deletions

View File

@@ -1,8 +1,10 @@
#!/usr/bin/env bash
VERS='3.8.209-05022023'
VERS='3.8.210-05022023'
MMFOLDER="/opt/idssys/mediamanager"
TMPFOLDER="${MMFOLDER}/.tmp"
[ ! -d ${TMPFOLDER} ] && mkdir ${TMPFOLDER}
MMSRV=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
AVAILSERVICES=bazarr,jackett,lidarr,ombi,qbittorrent,radarr,radarr3d,sonarr,snap.tautulli.tautulli
@@ -101,10 +103,10 @@ MMUPDATECHECK(){
if curl -m 15 -s --head --request GET https://git.schroedercity.com | grep "HTTP/2 200" > /dev/null; then
cd ${MMFOLDER}
if [ "`git log --pretty=%H ...refs/heads/master^ | head -n 1`" != "`git ls-remote origin -h refs/heads/master |cut -f1`" ]; then
touch ${MMFOLDER}/update.available
touch ${TMPFOLDER}/update.available
fi
else
/bin/rm -f ${MMFOLDER}/update.available
/bin/rm -f ${TMPFOLDER}/update.available
fi
}

View File

@@ -9,8 +9,8 @@ source /opt/idssys/defaults/colors.inc
source /opt/idssys/defaults/default.inc
source /opt/idssys/mediamanager/settings.conf
source /opt/idssys/mediamanager/defaults.inc
[ -f ${MMFOLDER}/realwanip ] && source ${MMFOLDER}/realwanip
[ -f ${MMFOLDER}/vers.info ] && source ${MMFOLDER}/vers.info
[ -f ${TMPFOLDER}/realwanip ] && source ${TMPFOLDER}/realwanip
[ -f ${TMPFOLDER}/vers.info ] && source ${TMPFOLDER}/vers.info
[ "${GITBRANCH}" != "" ] && GBRANCH="${GITBRANCH}" || GBRANCH="master"
if [ "${2}" == "q" ]; then
@@ -20,10 +20,10 @@ if [ "${2}" == "q" ]; then
idsST=('')
fi
[ -f ${MMFOLDER}/vpninfo ] && source ${MMFOLDER}/vpninfo
[ -f ${TMPFOLDER}/vpninfo ] && source ${TMPFOLDER}/vpninfo
if [[ "${noheader}" != *" ${1} "* ]] && [[ "${noheader}" != *" ${2} "* ]]; then
if [ -f ${MMFOLDER}/update.available ]; then
if [ -f ${TMPFOLDER}/update.available ]; then
dispup="${idsCL[Yellow]} - Update Available! (run '${idsCL[LightCyan]}mm update${idsCL[Yellow]}')${idsCL[Default]}"
else
dispup=""
@@ -40,7 +40,7 @@ unset IFS
cw_spc=40
MMCRONCHECK(){
if [ -f ${MMFOLDER}/mm.stop ]; then
if [ -f ${TMPFOLDER}/mm.stop ]; then
/usr/local/bin/mm check q >/dev/null 2>&1
else
echo -e "$(date) - Starting log #############################" >> ${outputlogfile}
@@ -50,7 +50,7 @@ MMCRONCHECK(){
# if [ $(date +%H)$(date +%u) -eq 4 ] && [ $(date +%H)$(date +%M) -ge 0400 ] && [ $(date +%H)$(date +%M) -le 0405 ] ; then
if [ $(date +%H)$(date +%M) -ge 0400 ] && [ $(date +%H)$(date +%M) -lt 0405 ] ; then
if [ $(expr `date +%s` - $(stat -c %Y ${MMFOLDER}/vers.info)) -gt 600 ]; then
if [ $(expr `date +%s` - $(stat -c %Y ${TMPFOLDER}/vers.info)) -gt 600 ]; then
/usr/local/bin/mm update-allservices q >/dev/null 2>&1
echo "$(date) - Updated All Services" >> $logfile
fi
@@ -68,18 +68,18 @@ MMCRONCHECK(){
MMSTART(){
[ $VERBOSE = true ] && chktmstart=`date +%s`
([ "${1}" == "start" ] || [ "${1}" == "check" ]) && touch ${MMFOLDER}/mm.stop.checking
[ "${2}" == "vpn" ] && touch ${MMFOLDER}/mm.noservices
([ "${1}" == "start" ] || [ "${1}" == "check" ]) && touch ${TMPFOLDER}/mm.stop.checking
[ "${2}" == "vpn" ] && touch ${TMPFOLDER}/mm.noservices
if [ "${1}" = "start" ] || [ "${1}" = "restart" ] || [ "${1}" = "" ]; then
GOFORSTART=true;
elif [ "${1}" == "check" ] && [ "$(/sbin/ip link | grep "${VPN_INTERFACE}")" == "" ] && [ ! -f ${MMFOLDER}/mm.vpn* ] && [ ! -f ${MMFOLDER}/vpninfo.* ]; then
elif [ "${1}" == "check" ] && [ "$(/sbin/ip link | grep "${VPN_INTERFACE}")" == "" ] && [ ! -f ${TMPFOLDER}/mm.vpn* ] && [ ! -f ${TMPFOLDER}/vpninfo.* ]; then
GOFORSTART=true;
SENDNOTICE "Starting Media Management Systems" "Fresh Startup"
echo "$(date) - Starting Media Management system - (fresh start)" >> $logfile
echo -e "${idsCL[LightCyan]}Fresh Startup${idsCL[Default]}"
elif [ "${1}" = "check" ] && [ "$(/sbin/ip link | grep "${VPN_INTERFACE}")" = "" ] && [ -f ${MMFOLDER}/mm.vpn* ]; then
elif [ "${1}" = "check" ] && [ "$(/sbin/ip link | grep "${VPN_INTERFACE}")" = "" ] && [ -f ${TMPFOLDER}/mm.vpn* ]; then
GOFORSTART=true;
echo "$(date) - Attempting to restart systems after VPN failure..." >> $logfile
echo -e "${idsCL[LightCyan]}Attempting to restart systems after VPN failure...${idsCL[Default]}"
@@ -108,8 +108,8 @@ MMSTART(){
until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
echo -en "${idsCL[LightCyan]}${msg}${spc} ${idsCL[White]}: ${idsCL[Default]}"
echo "REALWANIP=\"$(/usr/bin/dig +short +time=2 myip.opendns.com @208.67.222.222)\"" > ${MMFOLDER}/realwanip
source ${MMFOLDER}/realwanip
echo "REALWANIP=\"$(/usr/bin/dig +short +time=2 myip.opendns.com @208.67.222.222)\"" > ${TMPFOLDER}/realwanip
source ${TMPFOLDER}/realwanip
"${VPN_START[@]}" >/dev/null 2>&1
sleep 5s
@@ -132,20 +132,20 @@ MMSTART(){
OUT=$(/sbin/ip link | grep "$VPN_INTERFACE")
if [ ${#OUT} = 0 ]; then
if [ -f ${MMFOLDER}/mm.vpn.fail ]; then
if [ -f ${TMPFOLDER}/mm.vpn.fail ]; then
echo -e "${idsCL[Red]} failed, restarting system${idsCL[Default]}"
echo "$(date) - VPN Failure #2 - restarting system" >> $logfile
SENDNOTICE "VPN Failure" "2nd Failure, will try and restart the VPN" 1
touch ${MMFOLDER}/mm.vpn.fail2
rm -f ${MMFOLDER}/mm.vpn.fail
touch ${TMPFOLDER}/mm.vpn.fail2
rm -f ${TMPFOLDER}/mm.vpn.fail
MMSTOP
# sleep 2m
# "${VPN_START[@]}" >/dev/null 2>&1
# sleep 10s
rm -f ${MMFOLDER}/mm.stop*
rm -f ${TMPFOLDER}/mm.stop*
[ $VERBOSE = true ] && DEBUGLOGSTOP
exit 1
elif [ -f ${MMFOLDER}/mm.vpn.fail2 ]; then
elif [ -f ${TMPFOLDER}/mm.vpn.fail2 ]; then
echo "$(date) - VPN Failure #3 - Shutting down Media Management systems" >> $logfile
SENDNOTICE "VPN Failure" "Final Failure, shutting down system" 2
MMSTOP
@@ -155,12 +155,12 @@ MMSTART(){
echo -e "${idsCL[Red]} failed, restarting system${idsCL[Default]}"
echo "$(date) - VPN Failure #1 - restarting system" >> $logfile
SENDNOTICE "VPN Failure" "1st Failure, will try and restart the VPN" 1
touch ${MMFOLDER}/mm.vpn.fail
touch ${TMPFOLDER}/mm.vpn.fail
MMSTOP
# sleep 10s
# "${VPN_START[@]}" >/dev/null 2>&1
# sleep 10s
rm -f ${MMFOLDER}/mm.stop*
rm -f ${TMPFOLDER}/mm.stop*
[ $VERBOSE = true ] && DEBUGLOGSTOP
exit 1
fi
@@ -174,11 +174,11 @@ MMSTART(){
echo -e "${idsCL[Green]}Done${idsCL[Default]}"
fi
vpnuptime=$(expr `date +%s` - $(stat -c %Y ${MMFOLDER}/vpninfo))
vpnuptime=$(expr `date +%s` - $(stat -c %Y ${TMPFOLDER}/vpninfo))
if [ ${vpnuptime} -ge 86400 ]; then
echo "$(date) - 24hr session limit reached, restarting vpn & services" >> $logfile
echo -en "${idsCL[LightCyan]}24hr session limit reached, restarting vpn & services ."
[ -f ${MMFOLDER}/mm.noservices ] && rv="vpn" || rv=""
[ -f ${TMPFOLDER}/mm.noservices ] && rv="vpn" || rv=""
MMSTOP >/dev/null 2>&1
echo -en "."
read -et 10
@@ -232,12 +232,12 @@ MMSTART(){
echo -e "${idsCL[Red]}Could not confirm default routes, restarting system!${idsCL[Default]}"
echo "$(date) - Could not confirm default routes, restarting system" >> $logfile
SENDNOTICE "Network Failure" "Default route failure, will try and restart the VPN" 1
touch ${MMFOLDER}/mm.vpn.fail
touch ${TMPFOLDER}/mm.vpn.fail
MMSTOP
sleep 10s
# "${VPN_START[@]}" >/dev/null 2>&1
# sleep 10s
rm -f ${MMFOLDER}/mm.stop*
rm -f ${TMPFOLDER}/mm.stop*
[ $VERBOSE = true ] && DEBUGLOGSTOP
exit 1
fi
@@ -264,12 +264,12 @@ MMSTART(){
echo "$(date) - Cannot get an WAN address, restarting system! wanip(${REALWANIP}) vpnip(${mmip})" >> $logfile
[ $VERBOSE = true ] && echo "$(date) - Default Routes: zerogw(${zerogw}) defaultgw(${defaultgw})" >> $logfile
SENDNOTICE "Network Failure" "Cannot get an WAN address, will try and restart the VPN" 1
touch ${MMFOLDER}/mm.vpn.fail
touch ${TMPFOLDER}/mm.vpn.fail
MMSTOP >/dev/null 2>&1
sleep 10s
# "${VPN_START[@]}" >/dev/null 2>&1
# sleep 10s
rm -f ${MMFOLDER}/mm.stop*
rm -f ${TMPFOLDER}/mm.stop*
[ $VERBOSE = true ] && DEBUGLOGSTOP
exit 1
fi
@@ -285,12 +285,12 @@ MMSTART(){
echo "$(date) - Traffic is not routing through VPN, restarting system! wanip(${REALWANIP}) vpnip(${mmip})" >> $logfile
[ $VERBOSE = true ] && echo "$(date) - Default Routes: zerogw(${zerogw}) defaultgw(${defaultgw})" >> $logfile
SENDNOTICE "Network Failure" "Traffic route failure, will try and restart the VPN" 1
touch ${MMFOLDER}/mm.vpn.fail
touch ${TMPFOLDER}/mm.vpn.fail
MMSTOP
sleep 10s
# "${VPN_START[@]}" >/dev/null 2>&1
# sleep 10s
rm -f ${MMFOLDER}/mm.stop*
rm -f ${TMPFOLDER}/mm.stop*
[ $VERBOSE = true ] && DEBUGLOGSTOP
exit 1
fi
@@ -301,7 +301,7 @@ MMSTART(){
echo -en "${idsCL[LightCyan]}${msg}${spc} ${idsCL[White]}: ${idsCL[Default]}"
### CHECK FOR PLEX MOUNT
if [ ! -f ${PLEX_MOUNT}/mounted ] && [ "${2}" != "vpn" ] && [ ! -f ${MMFOLDER}/mm.noservices ]; then
if [ ! -f ${PLEX_MOUNT}/mounted ] && [ "${2}" != "vpn" ] && [ ! -f ${TMPFOLDER}/mm.noservices ]; then
echo "$(date) - Plex Media Not Mounted, will try and mount" >> $logfile
umount ${PLEX_MOUNT} >/dev/null 2>&1
sleep 2s
@@ -309,22 +309,22 @@ MMSTART(){
sleep 2s
if [ ! -f ${PLEX_MOUNT}/mounted ]; then
if [ -f "${MMFOLDER}/mm.plexmount.fail2" ]; then
fd=$(( `date +%s` - `stat -L --format %Y "${MMFOLDER}/mm.plexmount.fail2"` ))
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 ${MMFOLDER}/mm.plexmount.fail ]; then
fd=$(( `date +%s` - `stat -L --format %Y ${MMFOLDER}/mm.plexmount.fail` ))
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 "${MMFOLDER}/mm.plexmount.fail2" ] && touch ${MMFOLDER}/mm.plexmount.fail2 || touch ${MMFOLDER}/mm.plexmount.fail
[ -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" >> $logfile
fi
if [ ! -f ${MMFOLDER}/mm.plexmount.fail2 ]; then
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 &
@@ -340,30 +340,30 @@ MMSTART(){
for srvc in "${SERVICES_CHECK[@]}"; do
/bin/systemctl restart ${srvc} >/dev/null 2>&1 &
done
rm -f ${MMFOLDER}/mm.plexmount.fail*
rm -f ${TMPFOLDER}/mm.plexmount.fail*
fi
elif [ "${2}" == "vpn" ] || [ -f ${MMFOLDER}/mm.noservices ]; then
elif [ "${2}" == "vpn" ] || [ -f ${TMPFOLDER}/mm.noservices ]; then
echo -e "${idsCL[LightCyan]}Skipping, started wtih VPN only${idsCL[Default]}"
else
echo -e "${idsCL[Green]}Mounted${idsCL[Default]}"
if [ -f ${MMFOLDER}/mm.plexmount.fail ]; then
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" >> $logfile
for srvc in "${SERVICES_CHECK[@]}"; do
/bin/systemctl restart ${srvc} >/dev/null 2>&1 &
done
rm -f ${MMFOLDER}/mm.plexmount.fail*
rm -f ${TMPFOLDER}/mm.plexmount.fail*
fi
fi
if [ -f ${MMFOLDER}/mm.plexmount.fail ] && [ "${1}" == "start" ] && [ "${2}" != "vpn" ]; then
if [ -f ${TMPFOLDER}/mm.plexmount.fail ] && [ "${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
[Yy])
rm -f ${MMFOLDER}/mm.plexmount.fail*
touch ${MMFOLDER}/mm.plexmount.fail2
rm -f ${TMPFOLDER}/mm.plexmount.fail*
touch ${TMPFOLDER}/mm.plexmount.fail2
echo;echo
;;
* )
@@ -373,12 +373,12 @@ MMSTART(){
esac
fi
[ "${1}" == "start" ] && [ "${2}" != "vpn" ] && rm -f ${MMFOLDER}/mm.noservices
[ "${1}" == "start" ] && [ "${2}" != "vpn" ] && rm -f ${TMPFOLDER}/mm.noservices
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 ${MMFOLDER}/mm.noservices ] && [ ! -f ${MMFOLDER}/mm.plexmount.fail ]; then
if [ "${2}" != "vpn" ] && [ ! -f ${TMPFOLDER}/mm.noservices ] && [ ! -f ${TMPFOLDER}/mm.plexmount.fail ]; then
for srvc in "${SERVICES_CHECK[@]}"; do
[ "$(systemctl is-active ${srvc})" != "active" ] && /bin/systemctl restart ${srvc}
done
@@ -395,7 +395,7 @@ MMSTART(){
cc=0
until [ "${checkport}" != "" ]; do
if [ ${cc} -eq 10 ]; then
if [ -f ${MMFOLDER}/mm.${srvc}.starting ]; then
if [ -f ${TMPFOLDER}/mm.${srvc}.starting ]; then
msg="${srvc^} Service is not starting properly, will try and update"
echo -e "${idsCL[Red]}${msg}${idsCL[Default]}"
echo "$(date) - ${msg}" >> $logfile
@@ -408,10 +408,10 @@ MMSTART(){
until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
echo -en "${idsCL[LightCyan]}${msg}${spc} ${idsCL[White]}: ${idsCL[Default]}"
rm -f ${MMFOLDER}/mm.${srvc}.starting
rm -f ${TMPFOLDER}/mm.${srvc}.starting
else
[ "${MM_UPDATE_REPO[$srvc]}" != "" ] && touch ${MMFOLDER}/mm.${srvc}.starting
[ "${MM_UPDATE_REPO[$srvc]}" != "" ] && touch ${TMPFOLDER}/mm.${srvc}.starting
fi
checkport="go"
@@ -431,15 +431,15 @@ MMSTART(){
elif [ "${tryupdate}" == "true" ]; then
echo -e "${idsCL[Green]}Done${idsCL[Default]}"
fi
[ "${checkport}" != "" ] && rm -f ${MMFOLDER}/mm.${srvc}.starting >/dev/null 2>&1
[ "${checkport}" != "" ] && rm -f ${TMPFOLDER}/mm.${srvc}.starting >/dev/null 2>&1
fi
done
echo -e "${idsCL[Green]}Done${idsCL[Default]}"
elif [ -f ${MMFOLDER}/mm.noservices ]; then
elif [ -f ${TMPFOLDER}/mm.noservices ]; then
echo -e "${idsCL[LightCyan]}Skipping, started wtih VPN only${idsCL[Default]}"
elif [ -f ${MMFOLDER}/mm.plexmount.fail ]; then
elif [ -f ${TMPFOLDER}/mm.plexmount.fail ]; then
echo -e "${idsCL[LightCyan]}Skipping, plex media is not mounted${idsCL[Default]}"
else
echo -e "${idsCL[LightYellow]}Skipping${idsCL[Default]}"
@@ -450,12 +450,12 @@ MMSTART(){
#echo -e "${idsCL[LightCyan]}It may take a couple of minutes before all services fully start${idsCL[Default]}"
MMSTATUS
fi
if [ -f ${MMFOLDER}/mm.vpn.fail* ]; then
if [ -f ${TMPFOLDER}/mm.vpn.fail* ]; then
echo "$(date) - VPN issue has been fixed" >> $logfile
SENDNOTICE "Services Restored" "VPN issue has been fixed"
rm -f ${MMFOLDER}/mm.vpn.fail*
rm -f ${TMPFOLDER}/mm.vpn.fail*
fi
rm -f ${MMFOLDER}/mm.stop*
rm -f ${TMPFOLDER}/mm.stop*
echo -e "${idsCL[Green]}All systems are go!${idsCL[Default]}"
if [ "${1}" = "start" ] || [ "${1}" = "" ]; then
echo "$(date) - Media Management systems started" >> $logfile
@@ -470,13 +470,13 @@ MMSTART(){
}
MMSTOP(){
if [ -f ${MMFOLDER}/mm.stop ]; then
if [ -f ${TMPFOLDER}/mm.stop ]; then
echo -e "${idsCL[Yellow]}The system is already stopped, will verify anyway...${idsCL[Default]}"
else
echo -e "${idsCL[Green]}Stopping System...${idsCL[Default]}"
fi
echo
touch ${MMFOLDER}/mm.stop
touch ${TMPFOLDER}/mm.stop
# echo -en "${idsCL[LightCyan]}Stopping background MM scripts... ${idsCL[Default]}"
# getMMbash=$(pgrep -f '/mm')
@@ -542,18 +542,18 @@ MMSTOP(){
echo -e "${idsCL[Green]}Done${idsCL[Default]}"
rm -f ${MMFOLDER}/vpninfo*
rm -f ${MMFOLDER}/realwanip
rm -f ${MMFOLDER}/mm.noservices*
rm -f ${MMFOLDER}/mm.plexmount.fail*
rm -f ${MMFOLDER}/mm.stop.checking
rm -f ${TMPFOLDER}/vpninfo*
rm -f ${TMPFOLDER}/realwanip
rm -f ${TMPFOLDER}/mm.noservices*
rm -f ${TMPFOLDER}/mm.plexmount.fail*
rm -f ${TMPFOLDER}/mm.stop.checking
echo "$(date) - Media Management systems stopped" >> $logfile
echo
echo -e "${idsCL[Red]}All services have been stopped${idsCL[Default]}"
echo
touch ${MMFOLDER}/mm.stop
touch ${TMPFOLDER}/mm.stop
}
MMSTATUS(){
@@ -568,9 +568,9 @@ MMSTATUS(){
echo -en " ${idsCL[White]}${dispname}${spc}${idsCL[White]}: ${idsCL[Default]}"
if [ "$(systemctl is-active ${srvc})" != "active" ] && [ "${srvc}" != "wireguard" ]; then
if [ -f ${MMFOLDER}/mm.noservices ]; then
if [ -f ${TMPFOLDER}/mm.noservices ]; then
echo -e "${idsCL[LightCyan]}Skipping, started wtih VPN only${idsCL[Default]}"
elif [ -f ${MMFOLDER}/mm.plexmount.fail ]; then
elif [ -f ${TMPFOLDER}/mm.plexmount.fail ]; then
echo -e "${idsCL[LightCyan]}Skipping, Plex Media not mounted${idsCL[Default]}"
else
echo -e "${idsCL[Red]}Not Running${idsCL[Default]}"
@@ -591,7 +591,7 @@ MMSTATUS(){
zerogw=$(/sbin/ip route show | grep 0.0.0.0 | cut -d' ' -f 3)
defaultgw=$(/sbin/ip route show | grep default | cut -d' ' -f 3)
vpnuptime=$(expr `date +%s` - $(stat -c %Y ${MMFOLDER}/vpninfo))
vpnuptime=$(expr `date +%s` - $(stat -c %Y ${TMPFOLDER}/vpninfo))
msg=" |- ${idsCL[Default]}VPN/Services Uptime"
c=0; spc=''; spc1=$((${cw_spc}-${#msg}+6)); until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
echo -e "${idsCL[White]}${msg}${spc}${idsCL[White]} : ${idsCL[Green]}$(SHOW_TIME ${vpnuptime})${idsCL[Default]}"
@@ -611,7 +611,7 @@ MMSTATUS(){
echo -e "${idsCL[Green]}$defaultgw${idsCL[Default]}"
else
echo -e "${idsCL[Red]}$defaultgw - Incorrect Gateways${idsCL[Default]}"
if ([ ! -f ${MMFOLDER}/mm.stop* ] && [ "${1}" == "fix" ]) || ([ ! -f ${MMFOLDER}/mm.stop ] && [ -f ${MMFOLDER}/mm.stop.checking ] && [ "${1}" == "fix" ]); then
if ([ ! -f ${TMPFOLDER}/mm.stop* ] && [ "${1}" == "fix" ]) || ([ ! -f ${TMPFOLDER}/mm.stop ] && [ -f ${TMPFOLDER}/mm.stop.checking ] && [ "${1}" == "fix" ]); then
echo
echo -e "${idsCL[LightCyan]}Restarting system...${idsCL[Default]}"
MMSTOP
@@ -629,7 +629,7 @@ MMSTATUS(){
echo -en "${idsCL[White]}${msg}${spc}${idsCL[White]}: ${idsCL[Default]}"
echo -e "${idsCL[Green]}Running${idsCL[Default]}"
vpnuptime=$(expr `date +%s` - $(stat -c %Y ${MMFOLDER}/vpninfo))
vpnuptime=$(expr `date +%s` - $(stat -c %Y ${TMPFOLDER}/vpninfo))
msg=" |- ${idsCL[Default]}VPN/Services Uptime"
c=0; spc=''; spc1=$((${cw_spc}-${#msg}+6)); until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
echo -e "${idsCL[White]}${msg}${spc}${idsCL[White]} : ${idsCL[Green]}$(SHOW_TIME ${vpnuptime})${idsCL[Default]}"
@@ -653,7 +653,7 @@ MMSTATUS(){
else
echo -e "${idsCL[Red]}$defaultgw - Incorrect Gateways${idsCL[Default]}"
echo
if [ ! -f ${MMFOLDER}/mm.stop.checking ]; then
if [ ! -f ${TMPFOLDER}/mm.stop.checking ]; then
echo -e "${idsCL[LightCyan]}Shutting down system... fix yo shit${idsCL[Default]}"
MMSTOP
fi
@@ -673,7 +673,7 @@ MMSTATUS(){
echo -e "${idsCL[Green]}Good${idsCL[Default]}"
else
echo -e "${idsCL[Red]}Not Routing${idsCL[Default]}"
if ([ ! -f ${MMFOLDER}/mm.stop* ] && [ "${1}" == "fix" ]) || ([ ! -f ${MMFOLDER}/mm.stop ] && [ -f ${MMFOLDER}/mm.stop.checking ] && [ "${1}" == "fix" ]); then
if ([ ! -f ${TMPFOLDER}/mm.stop* ] && [ "${1}" == "fix" ]) || ([ ! -f ${TMPFOLDER}/mm.stop ] && [ -f ${TMPFOLDER}/mm.stop.checking ] && [ "${1}" == "fix" ]); then
echo
echo -e "${idsCL[LightCyan]}Restarting system...${idsCL[Default]}"
MMSTOP
@@ -704,7 +704,7 @@ MMSTATUS(){
until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
echo -en "${idsCL[White]}${msg}${spc}${idsCL[White]} : ${idsCL[Default]}"
if [ -f ${MMFOLDER}/mm.plexmount.fail2 ]; then
if [ -f ${TMPFOLDER}/mm.plexmount.fail2 ]; then
echo -e "${idsCL[Red]}Not Mounted${idsCL[LightCyan]}, running services as chosen previously${idsCL[Default]}"
elif [ ! -f ${PLEX_MOUNT}/mounted ]; then
@@ -712,7 +712,7 @@ MMSTATUS(){
else
echo -e "${idsCL[Green]}Mounted${idsCL[Default]}"
rm -f ${MMFOLDER}/mm.plexmount.fail*
rm -f ${TMPFOLDER}/mm.plexmount.fail*
fi
echo
@@ -742,7 +742,7 @@ VPNCONFIG(){
reqpublickey=$(echo "${privkey}" | /usr/bin/wg pubkey)
reqpublickey="$(php -r 'echo rawurlencode($argv[1]);' -- "$reqpublickey")"
rm -f ${MMFOLDER}/vpninfo
rm -f ${TMPFOLDER}/vpninfo
JSON=$(curl https://${VPN_SERVER}:1443/api/v1/setup?public-key=${reqpublickey} --user "${VPN_USER}:${VPN_PASS}" -sk)
echo -e "vpn_publickey=\"$(echo ${JSON} | jq -r '.server_public_key')\"
vpn_server_ipv4=\"$(echo ${JSON} | jq -r '.server_ipv4')\"
@@ -750,8 +750,8 @@ vpn_client_ipv4=\"$(echo ${JSON} | jq -r '.client_ipv4')\"
vpn_routes=\"$(echo ${JSON} | jq -r '.routes')\"
vpn_server_address=\"$(echo ${JSON} | jq -r '.vpn_server_address')\"
vpn_server_port=\"$(echo ${JSON} | jq -r '.vpn_server_port')\"
" > ${MMFOLDER}/vpninfo
source ${MMFOLDER}/vpninfo
" > ${TMPFOLDER}/vpninfo
source ${TMPFOLDER}/vpninfo
rm -f /etc/wireguard/${VPN_INTERFACE}.conf
@@ -773,7 +773,7 @@ VPNSPEEDTEST(){
echo -e "${idsCL[Green]}VPN Speedtest Comparison${idsCL[Default]}"
DIVIDER . lightGreen
echo
if [ ! -f ${MMFOLDER}/mm.stop ]; then
if [ ! -f ${TMPFOLDER}/mm.stop ]; then
echo -en "${idsCL[LightCyan]}This requires all media management services to be stopped, ok (Y/n)? ${idsCL[Default]}"
read -n 1 choice
case "$choice" in
@@ -826,7 +826,7 @@ VPNSPEEDTEST(){
UPDATESERVICE(){
if [ "${1}" != "" ]; then
usrvc=${1}
echo "${usrvc} Update" > ${MMFOLDER}/mm.update.stop
echo "${usrvc} Update" > ${TMPFOLDER}/mm.update.stop
echo "$(date) - Updating Service (${usrvc}) : Starting" >> $logfile
echo
echo -e "${idsCL[Green]}Updating ${usrvc^} Service${idsCL[Default]}"
@@ -908,9 +908,9 @@ UPDATESERVICE(){
rm -f ${tmpfile} &>/dev/null
echo -e "${idsCL[Green]}Done${idsCL[Default]}"
[ ! -f ${MMFOLDER}/vers.info ] && touch ${MMFOLDER}/vers.info
/bin/sed -i /${usrvc}/d ${MMFOLDER}/vers.info
echo "${usrvc}_VER=\"${latest_ver}\"" >> ${MMFOLDER}/vers.info
[ ! -f ${TMPFOLDER}/vers.info ] && touch ${TMPFOLDER}/vers.info
/bin/sed -i /${usrvc}/d ${TMPFOLDER}/vers.info
echo "${usrvc}_VER=\"${latest_ver}\"" >> ${TMPFOLDER}/vers.info
SERVICEBACKUPSTART ${usrvc}
@@ -955,7 +955,7 @@ UPDATESERVICE(){
else
echo -e "${idsCL[Red]}No service selected for update${idsCL[Default]}"
fi
rm -f ${MMFOLDER}/mm.update.stop
rm -f ${TMPFOLDER}/mm.update.stop
}
@@ -979,7 +979,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 ${MMFOLDER}/mm.stop ] && [[ " ${SERVICES_CHECK[*]} " =~ " ${usrvc} " ]] && [ ! -f ${MMFOLDER}/mm.noservices ] && [ ! `find /opt/idssys/mediamanager/ -name 'mm.plexmount.fail*'` ]; then
if [ ! -f ${TMPFOLDER}/mm.stop ] && [[ " ${SERVICES_CHECK[*]} " =~ " ${usrvc} " ]] && [ ! -f ${TMPFOLDER}/mm.noservices ] && [ ! `find /opt/idssys/mediamanager/ -name 'mm.plexmount.fail*'` ]; then
/bin/systemctl disable ${usrvc} >> ${MMFOLDER}/logs/update.${usrvc}
/bin/systemctl start ${usrvc} >> ${MMFOLDER}/logs/update.${usrvc}
[ "${usrvc}" == "radarr" ] && [[ " ${SERVICES_CHECK[*]} " =~ " radarr3d " ]] && /bin/systemctl start radarr3d >> ${MMFOLDER}/logs/update.${usrvc}
@@ -1402,9 +1402,9 @@ USAGE(){
}
if [ ! -f ${MMFOLDER}/mm.update.stop ]; then
if [ -f ${MMFOLDER}/mm.stop ]; then
stoppedsince=`date +%s`-$(stat -c %Y ${MMFOLDER}/mm.stop)
if [ ! -f ${TMPFOLDER}/mm.update.stop ]; then
if [ -f ${TMPFOLDER}/mm.stop ]; then
stoppedsince=`date +%s`-$(stat -c %Y ${TMPFOLDER}/mm.stop)
stopmsg="${idsCL[Yellow]}The system has currently been stopped for '$(SHOW_TIME ${stoppedsince})'.\n${idsCL[LightCyan]}(You'll need to run \"mm start\" to start services again)${idsCL[Default]}"
fi
case $action in
@@ -1416,7 +1416,7 @@ if [ ! -f ${MMFOLDER}/mm.update.stop ]; then
stop) MMSTOP;;
start | check)
if [ -f ${MMFOLDER}/mm.stop ] && [ "${action}" == "check" ]; then
if [ -f ${TMPFOLDER}/mm.stop ] && [ "${action}" == "check" ]; then
if [ "${2}" != "q" ]; then
echo -e "${stopmsg}"
# [ $VERBOSE = true ] && echo "$(date) - Not checking, system has been stopped" >> $logfile
@@ -1428,14 +1428,14 @@ if [ ! -f ${MMFOLDER}/mm.update.stop ]; then
echo -e "${idsCL[Red]}VPN User Info Missing${idsCL[Default]}"
echo
exit 1
elif [ ! -f ${MMFOLDER}/mm.stop ] && [ -f ${MMFOLDER}/mm.stop.checking ]; then
checkstopped=`expr $(date +%s) - $(stat -c %Y ${MMFOLDER}/mm.stop.checking)`
elif [ ! -f ${TMPFOLDER}/mm.stop ] && [ -f ${TMPFOLDER}/mm.stop.checking ]; then
checkstopped=`expr $(date +%s) - $(stat -c %Y ${TMPFOLDER}/mm.stop.checking)`
if [ $checkstopped -gt 900 ]; then
rm -f ${MMFOLDER}/mm.stop*
rm -f ${TMPFOLDER}/mm.stop*
echo "$(date) - Bash script stuck in stop mode after doing a check, will restart" >> $logfile
SENDNOTICE "MM Script Error" "Bash script stuck in check mode, restarting system"
MMSTOP
rm -f ${MMFOLDER}/mm.stop*
rm -f ${TMPFOLDER}/mm.stop*
getStuckMM=$(pgrep -f '/mm')
for i in $getStuckMM; do
/bin/kill $i
@@ -1445,16 +1445,16 @@ if [ ! -f ${MMFOLDER}/mm.update.stop ]; then
fi
fi
[ ! -f ${MMFOLDER}/mm.stop ] && MMSTART ${action} ${2}
[ "${action}" != "status" ] && rm -f ${MMFOLDER}/mm.stop.checking
[ ! -f ${TMPFOLDER}/mm.stop ] && MMSTART ${action} ${2}
[ "${action}" != "status" ] && rm -f ${TMPFOLDER}/mm.stop.checking
;;
restart)
if [ -f ${MMFOLDER}/mm.stop ]; then
if [ -f ${TMPFOLDER}/mm.stop ]; then
echo -e "${stopmsg}"
echo
exit 1
fi
[ -f ${MMFOLDER}/mm.noservices ] && rv="vpn" || rv=""
[ -f ${TMPFOLDER}/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
@@ -1462,7 +1462,7 @@ if [ ! -f ${MMFOLDER}/mm.update.stop ]; then
MMSTART ${action} ${rv}
;;
status)
if [ -f ${MMFOLDER}/mm.stop ]; then
if [ -f ${TMPFOLDER}/mm.stop ]; then
echo -e "${stopmsg}"
echo
fi

20
run.sh
View File

@@ -72,7 +72,7 @@ if [ "${1}" == "update" ] || [ "${1}" == "setup" ]; then
else
echo -e "${idsCL[LightCyan]}No Updates Available${idsCL[Default]}"
fi
/bin/rm -f ${MMFOLDER}/update.available
/bin/rm -f ${TMPFOLDER}/update.available
else
echo -e "${idsCL[Red]}Could not connect to 'git.schroedercity.com' for updates${idsCL[Default]}"
@@ -81,21 +81,21 @@ if [ "${1}" == "update" ] || [ "${1}" == "setup" ]; then
fi
if [ "${1}" == "clear" ]; then
[ ! -f ${MMFOLDER}/mm.stop ] && rm -f ${MMFOLDER}/mm.* || rm -f ${MMFOLDER}/mm.*; touch ${MMFOLDER}/mm.stop
[ ! -f ${TMPFOLDER}/mm.stop ] && rm -f ${TMPFOLDER}/mm.* || rm -f ${TMPFOLDER}/mm.*; touch ${TMPFOLDER}/mm.stop
fi
if [ -f ${MMFOLDER}/mm.stop.checking ]; then
#fd=$(expr $(date +%s) - $(stat -L --format %Y ${MMFOLDER}/mm.stop.checking))
if [ $(expr $(date +%s) - $(stat -L --format %Y ${MMFOLDER}/mm.stop.checking)) -gt 900 ]; then
rm -f ${MMFOLDER}/mm.stop*
elif [ "${1}" = "check" ] && [ "$(ip link | grep "${VPN_INTERFACE}")" = "" ] && [ ! -f ${MMFOLDER}/mm.vpn* ] && [ $(uptime_minutes) -lt 3 ]; then
rm -f ${MMFOLDER}/mm.stop*
if [ -f ${TMPFOLDER}/mm.stop.checking ]; then
#fd=$(expr $(date +%s) - $(stat -L --format %Y ${TMPFOLDER}/mm.stop.checking))
if [ $(expr $(date +%s) - $(stat -L --format %Y ${TMPFOLDER}/mm.stop.checking)) -gt 900 ]; then
rm -f ${TMPFOLDER}/mm.stop*
elif [ "${1}" = "check" ] && [ "$(ip link | grep "${VPN_INTERFACE}")" = "" ] && [ ! -f ${TMPFOLDER}/mm.vpn* ] && [ $(uptime_minutes) -lt 3 ]; then
rm -f ${TMPFOLDER}/mm.stop*
else
echo -e "${idsCL[LightCyan]}Try again later, 'mm' program currently in use...${idsCL[Default]}"
fi
fi
if [ ! -f ${MMFOLDER}/mm.stop.checking ] || [ "${1}" == "status" ] || [ "${1}" == "update-service" ] || [ "${1}" == "update-allservices" ] || [ "${1}" == "stop" ]; then
[ "${1}" == "start" ] && rm -f ${MMFOLDER}/mm.stop
if [ ! -f ${TMPFOLDER}/mm.stop.checking ] || [ "${1}" == "status" ] || [ "${1}" == "update-service" ] || [ "${1}" == "update-allservices" ] || [ "${1}" == "stop" ]; then
[ "${1}" == "start" ] && rm -f ${TMPFOLDER}/mm.stop
${MMFOLDER}/mm-scripts.sh ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14}
fi