Update mm-scripts.sh
This commit is contained in:
@@ -38,14 +38,14 @@ MMSTART(){
|
||||
if [ "${1}" = "start" ] || [ "${1}" = "restart" ] || [ "${1}" = "" ]; then
|
||||
GOFORSTART=true;
|
||||
|
||||
elif [ "${1}" = "check" ] && [ "$(ip link | grep "${VPN_INTERFACE}")" = "" ] && [ ! -f ${MMFOLDER}/mm.vpn* ] && [ ! -f ${MMFOLDER}/vpninfo.* ]; then
|
||||
elif [ "${1}" = "check" ] && [ "$(/sbin/ip link | grep "${VPN_INTERFACE}")" = "" ] && [ ! -f ${MMFOLDER}/mm.vpn* ] && [ ! -f ${MMFOLDER}/vpninfo.* ]; then
|
||||
GOFORSTART=true;
|
||||
SENDNOTICE "Starting Media Management Systems" ""
|
||||
echo "$(date) - Starting Media Management system - (fresh start)" >> $logfile
|
||||
echo -e "${idsCL[LightCyan]}Fresh startup${idsCL[Default]}"
|
||||
# sleep 2m
|
||||
|
||||
elif [ "${1}" = "check" ] && [ "$(ip link | grep "${VPN_INTERFACE}")" = "" ] && [ -f ${MMFOLDER}/mm.vpn* ]; then
|
||||
elif [ "${1}" = "check" ] && [ "$(/sbin/ip link | grep "${VPN_INTERFACE}")" = "" ] && [ -f ${MMFOLDER}/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]}"
|
||||
@@ -57,11 +57,11 @@ MMSTART(){
|
||||
if [ ${GOFORSTART} = true ]; then
|
||||
mmsv='Starting'
|
||||
echo
|
||||
OUT=$(ip link | grep "${VPN_INTERFACE}")
|
||||
OUT=$(/usr/bin//usr/bin/wg link | grep "${VPN_INTERFACE}")
|
||||
if [ ${#OUT} = 0 ]; then
|
||||
echo -en "${idsCL[LightCyan]}Setting up the VPN Tunnel config :${idsCL[Default]}"
|
||||
privkey=$(wg genkey)
|
||||
reqpublickey=$(echo "${privkey}" | wg pubkey)
|
||||
privkey=$(/usr/bin/wg genkey)
|
||||
reqpublickey=$(echo "${privkey}" | /usr/bin/wg pubkey)
|
||||
reqpublickey="$(php -r 'echo rawurlencode($argv[1]);' -- "$reqpublickey")"
|
||||
|
||||
JSON=$(curl https://${VPN_SERVER}:1443/api/v1/setup?public-key=${reqpublickey} --user "${VPN_USER}:${VPN_PASS}" -sk)
|
||||
@@ -105,7 +105,7 @@ PersistentKeepalive = 25" >> /etc/wireguard/${VPN_INTERFACE}.conf
|
||||
[ $VERBOSE = true ] && echo "$(date) - ${mmsv} VPN..." >> $logfile
|
||||
|
||||
|
||||
OUT=$(ip link | grep "$VPN_INTERFACE")
|
||||
OUT=$(/sbin/ip link | grep "$VPN_INTERFACE")
|
||||
if [ ${#OUT} = 0 ]; then
|
||||
if [ -f ${MMFOLDER}/mm.vpn.fail ]; then
|
||||
echo -e "${idsCL[Red]} failed, restarting system${idsCL[Default]}"
|
||||
@@ -145,8 +145,8 @@ PersistentKeepalive = 25" >> /etc/wireguard/${VPN_INTERFACE}.conf
|
||||
echo -e "${idsCL[Green]} done${idsCL[Default]}"
|
||||
fi
|
||||
|
||||
zerogw=$(ip route show | grep 0.0.0.0 | cut -d' ' -f 3)
|
||||
defaultgw=$(ip route show | grep default | cut -d' ' -f 3)
|
||||
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)
|
||||
|
||||
# if [ "${zerogw}" != "${defaultgw}" ]; then
|
||||
if [ "${defaultgw}" != "${VPN_INTERFACE}" ]; then
|
||||
@@ -159,8 +159,8 @@ PersistentKeepalive = 25" >> /etc/wireguard/${VPN_INTERFACE}.conf
|
||||
/bin/ip route add $(cat ${MMFOLDER}/vpninfo.address)/32 via 10.10.0.1 dev eth0
|
||||
echo -e "${idsCL[Green]} done${idsCL[Default]}"
|
||||
|
||||
zerogw=$(ip route show | grep 0.0.0.0 | cut -d' ' -f 3)
|
||||
defaultgw=$(ip route show | grep default | cut -d' ' -f 3)
|
||||
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)
|
||||
fi
|
||||
|
||||
|
||||
@@ -186,8 +186,8 @@ PersistentKeepalive = 25" >> /etc/wireguard/${VPN_INTERFACE}.conf
|
||||
fi
|
||||
((cc=${cc}+1))
|
||||
sleep 1s
|
||||
zerogw=$(ip route show | grep 0.0.0.0 | cut -d' ' -f 3)
|
||||
defaultgw=$(ip route show | grep default | cut -d' ' -f 3)
|
||||
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)
|
||||
done
|
||||
echo -e "${idsCL[Green]} done${idsCL[Default]}"
|
||||
|
||||
@@ -198,9 +198,9 @@ PersistentKeepalive = 25" >> /etc/wireguard/${VPN_INTERFACE}.conf
|
||||
mmip=""
|
||||
cc=0
|
||||
until [ "${scip}" != "" ] && [ "${mmip}" != "" ] && [ "${scip}" != ";; connection timed out; no servers could be reached" ] && [ "${mmip}" != ";; connection timed out; no servers could be reached" ]; do
|
||||
scip=$(dig +short +time=2 sc1.scity.us @10.10.10.5 -p 5053)
|
||||
# mmip=$(dig +short myip.opendns.com @resolver1.opendns.com)
|
||||
mmip=$(dig +short +time=2 myip.opendns.com @208.67.222.222)
|
||||
scip=$(/usr/bin/dig +short +time=2 sc1.scity.us @10.10.10.5 -p 5053)
|
||||
# mmip=$(/usr/bin/dig +short myip.opendns.com @resolver1.opendns.com)
|
||||
mmip=$(/usr/bin/dig +short +time=2 myip.opendns.com @208.67.222.222)
|
||||
if [ ${cc} -eq 10 ]; then
|
||||
echo -e "${idsCL[Red]}Cannot get an WAN address, restarting system!${idsCL[Default]}"
|
||||
echo "$(date) - Cannot get an WAN address, restarting system! scip(${scip}) mmip(${mmip})" >> $logfile
|
||||
@@ -357,14 +357,14 @@ MMSTOP(){
|
||||
|
||||
checked=false
|
||||
until [ "${checked}" = "" ]; do
|
||||
OUT=$(ip link | grep "$VPN_INTERFACE")
|
||||
OUT=$(/sbin/ip link | grep "$VPN_INTERFACE")
|
||||
#OUT=`ip a show $VPN_INTERFACE up` >/dev/null 2>&1
|
||||
if [ ${#OUT} = 0 ]; then
|
||||
checked=""
|
||||
fi
|
||||
done
|
||||
|
||||
[ "$(ip route show | grep default | cut -d' ' -f 3)" != "10.10.0.1" ] && /bin/ip route add default via 10.10.0.1 && ip route del $(cat ${MMFOLDER}/vpninfo.address)
|
||||
[ "$(/sbin/ip route show | grep default | cut -d' ' -f 3)" != "10.10.0.1" ] && /bin/ip route add default via 10.10.0.1 && ip route del $(cat ${MMFOLDER}/vpninfo.address)
|
||||
rm -f ${MMFOLDER}/vpninfo.*
|
||||
rm -f ${MMFOLDER}/noservices*
|
||||
[ $VERBOSE = true ] && echo "$(date) - Added default route back in" >> $logfile
|
||||
@@ -392,14 +392,14 @@ MMSTATUS(){
|
||||
if [ "$(systemctl is-active ${srvc})" != "active" ] && [ "${srvc}" != "wireguard" ]; then
|
||||
echo -e "${idsCL[Red]}Not Running${idsCL[Default]}"
|
||||
|
||||
elif [ "${srvc}" == "wireguard" ] && [ "$(ip link | grep $VPN_INTERFACE)" == "" ]; then
|
||||
elif [ "${srvc}" == "wireguard" ] && [ "$(/sbin/ip link | grep $VPN_INTERFACE)" == "" ]; then
|
||||
echo -e "${idsCL[Red]}Not Running${idsCL[Default]}"
|
||||
|
||||
else
|
||||
echo -e "${idsCL[Green]}Running${idsCL[Default]}"
|
||||
if [[ ${srvc} == *"vpn"* ]] || [[ ${srvc} == *"wireguard"* ]]; then
|
||||
zerogw=$(ip route show | grep 0.0.0.0 | cut -d' ' -f 3)
|
||||
defaultgw=$(ip route show | grep default | cut -d' ' -f 3)
|
||||
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)
|
||||
echo -e " |- 0.0.0.0 gateway : ${idsCL[Green]}$zerogw${idsCL[Default]}"
|
||||
echo -en " |- DEFAULT gateway : "
|
||||
if [ "${zerogw}" == "${defaultgw}" ] && [ "${zerogw}" == "${VPN_INTERFACE}" ]; then
|
||||
@@ -416,8 +416,8 @@ MMSTATUS(){
|
||||
MMSTART
|
||||
|
||||
echo -e " ${NM_SERVICES[wireguard]} : ${idsCL[Green]}Running${idsCL[Default]}"
|
||||
zerogw=$(ip route show | grep 0.0.0.0 | cut -d' ' -f 3)
|
||||
defaultgw=$(ip route show | grep default | cut -d' ' -f 3)
|
||||
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)
|
||||
echo -e " |- 0.0.0.0 gateway : ${idsCL[Green]}$zerogw${idsCL[Default]}"
|
||||
echo -en " |- DEFAULT gateway : "
|
||||
if [ "${zerogw}" == "${defaultgw}" ] && [ "${zerogw}" == "${VPN_INTERFACE}" ]; then
|
||||
@@ -435,9 +435,9 @@ MMSTATUS(){
|
||||
fi
|
||||
|
||||
echo -en " |- Verify routing through VPN : "
|
||||
scip=$(dig +short sc1.scity.us @10.10.10.5 -p 5053)
|
||||
# mmip=$(dig +short myip.opendns.com @resolver1.opendns.com)
|
||||
mmip=$(dig +short +time=2 myip.opendns.com @208.67.222.222)
|
||||
scip=$(/usr/bin/dig +short sc1.scity.us @10.10.10.5 -p 5053)
|
||||
# mmip=$(/usr/bin/dig +short myip.opendns.com @resolver1.opendns.com)
|
||||
mmip=$(/usr/bin/dig +short +time=2 myip.opendns.com @208.67.222.222)
|
||||
if [ "${scip}" != "${mmip}" ]; then
|
||||
echo -e "${idsCL[Green]}Good${idsCL[Default]}"
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user