Skip to content

Commit

Permalink
Merge pull request #278 from Martinski4GitHub/dev
Browse files Browse the repository at this point in the history
Keep ZeroTier connection during F/W updates.
  • Loading branch information
ExtremeFiretop authored Aug 3, 2024
2 parents 2f244bb + a67ec1b commit a6ed737
Showing 1 changed file with 40 additions and 32 deletions.
72 changes: 40 additions & 32 deletions MerlinAU.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# Original Creation Date: 2023-Oct-01 by @ExtremeFiretop.
# Official Co-Author: @Martinski W. - Date: 2023-Nov-01
# Last Modified: 2024-Jul-31
# Last Modified: 2024-Aug-03
###################################################################
set -u

Expand Down Expand Up @@ -2951,8 +2951,9 @@ _Toggle_VPN_Access_()

if [ "$currentSetting" = "ENABLED" ]
then
printf "Disabling this feature will shut down Tailscale VPN access during updates.\n"
printf "Proceed if you do not need VPN access during updates.\n"
printf "\n${REDct}*NOTICE*${NOct}\n"
printf "Disabling this feature will shut down Tailscale/ZeroTier VPN access during updates.\n"
printf "Proceed if you do not need remote VPN access during firmware updates.\n"

if _WaitForYESorNO_ "\nProceed to ${GRNct}DISABLE${NOct}?"
then
Expand All @@ -2962,9 +2963,9 @@ _Toggle_VPN_Access_()
printf "VPN access during updates remains ${REDct}ENABLED.${NOct}\n"
fi
else
printf "${REDct}*WARNING*${NOct}\n"
printf "Enabling this feature will keep Tailscale VPN access active during updates.\n"
printf "Proceed only if you require Tailscale to connect via an SSH session during updates.\n"
printf "\n${REDct}*WARNING*${NOct}\n"
printf "Enabling this feature will keep Tailscale/ZeroTier VPN access active during updates.\n"
printf "Proceed only if you require Tailscale/ZeroTier to connect remotely via an SSH session during firmware updates.\n"
if _WaitForYESorNO_ "\nProceed to ${REDct}ENABLE${NOct}?"
then
Update_Custom_Settings "Allow_Updates_OverVPN" "ENABLED"
Expand Down Expand Up @@ -4445,19 +4446,20 @@ _Toggle_FW_UpdateCheckSetting_()
}

##----------------------------------------##
## Modified by Martinski W. [2024-Jul-24] ##
## Modified by Martinski W. [2024-Aug-02] ##
##----------------------------------------##
_EntwareServicesHandler_()
{
if [ $# -eq 0 ] || [ -z "$1" ] ; then return 1 ; fi
local AllowVPN="$(Get_Custom_Setting Allow_Updates_OverVPN)"

local actionStr=""
local serviceStr serviceCnt=0
local servicesList servicesCnt=0
local entwOPT_init entwOPT_unslung
# space-delimited list #
local skipServiceList="tailscaled"
local skippedService skippedServiceFile skippedServiceList=""
# space-delimited list of services to skip #
local skipServiceList="tailscaled zerotier-one sshd"
local skippedService skippedServiceFile skippedServiceName
local theSkippedServiceList=""

entwOPT_init="/opt/etc/init.d"
entwOPT_unslung="${entwOPT_init}/rc.unslung"
Expand All @@ -4473,10 +4475,11 @@ _EntwareServicesHandler_()

_RenameSkippedService_()
{
[ -z "$skippedServiceList" ] && return 1
for skippedServiceFile in $skippedServiceList
[ -z "$theSkippedServiceList" ] && return 1
for skippedServiceName in $theSkippedServiceList
do # Rename service file back to original state #
if mv -f "${entwOPT_init}/OFF.${skippedServiceFile}.OFF" "${entwOPT_init}/$skippedServiceFile"
skippedServiceFile="${entwOPT_init}/$skippedServiceName"
if mv -f "${entwOPT_init}/OFF.${skippedServiceName}.OFF" "$skippedServiceFile"
then Say "Skipped $skippedServiceFile $1 call." ; fi
done
return 0
Expand All @@ -4485,44 +4488,49 @@ _EntwareServicesHandler_()
if [ ! -x /opt/bin/opkg ] || [ ! -x "$entwOPT_unslung" ]
then return 0 ; fi ## Entware is NOT found ##

serviceStr="$(/usr/bin/find -L "$entwOPT_init" -name "*" -print 2>/dev/null | /bin/grep -E "(${entwOPT_init}/S[0-9]+|${entwOPT_init}/.*[.]sh$)")"
servicesList="$(/usr/bin/find -L "$entwOPT_init" -name "*" -print 2>/dev/null | /bin/grep -E "(${entwOPT_init}/S[0-9]+|${entwOPT_init}/.*[.]sh$)")"
[ -z "$servicesList" ] && return 0

[ -n "$serviceStr" ] && Say "Looking for Entware services..."
Say "Searching for Entware services to ${1}..."

# Filter out services to skip and add a "skip message" #
if [ "$AllowVPN" = "ENABLED" ] && [ -n "$skipServiceList" ]
then
for skipService in $skipServiceList
do
skippedService="$(echo "$serviceStr" | /bin/grep -E "/S[0-9]+.*${skipService}$")"
skippedService="$(echo "$servicesList" | /bin/grep -E "/S[0-9]+.*${skipService}([.]sh)?$")"
if [ -n "$skippedService" ]
then
skippedServiceFile="$(basename "$skippedService")"
Say "Skipping $skippedServiceFile $1 call..."
# Rename service file so it's skipped by Entware #
if mv -f "${entwOPT_init}/$skippedServiceFile" "${entwOPT_init}/OFF.${skippedServiceFile}.OFF"
then
[ -z "$skippedServiceList" ] && \
skippedServiceList="$skippedServiceFile" || \
skippedServiceList="$skippedServiceList $skippedServiceFile"
serviceStr="$(echo "$serviceStr" | /bin/grep -vE "/S[0-9]+.*${skipService}$")"
fi
for skippedServiceFile in $skippedService
do
skippedServiceName="$(basename "$skippedServiceFile")"
Say "Skipping $skippedServiceFile $1 call..."
# Rename service file so it's skipped by Entware #
if mv -f "$skippedServiceFile" "${entwOPT_init}/OFF.${skippedServiceName}.OFF"
then
[ -z "$theSkippedServiceList" ] && \
theSkippedServiceList="$skippedServiceName" || \
theSkippedServiceList="$theSkippedServiceList $skippedServiceName"
servicesList="$(echo "$servicesList" | /bin/grep -vE "${skippedServiceFile}$")"
fi
done
fi
done
fi

[ -n "$serviceStr" ] && serviceCnt="$(echo "$serviceStr" | wc -l)"
if [ "$serviceCnt" -eq 0 ]
[ -n "$servicesList" ] && servicesCnt="$(echo "$servicesList" | wc -l)"
if [ "$servicesCnt" -eq 0 ]
then
Say "No Entware services to ${1}."
_RenameSkippedService_ "$1" && echo
return 0
fi

Say "${actionStr} Entware services..."
"$isInteractive" && printf "Please wait.\n"
Say "-----------------------------------------------------------"
# List the Entware service scripts found #
echo "$serviceStr" | while IFS= read -r servLine ; do Say "$servLine" ; done
# List the Entware services found to stop/start #
echo "$servicesList" | while IFS= read -r servLine ; do Say "$servLine" ; done
Say "-----------------------------------------------------------"

$entwOPT_unslung "$1" ; sleep 5
Expand Down Expand Up @@ -6413,7 +6421,7 @@ _ShowAdvancedOptionsMenu_()
fi

local VPNAccess="$(Get_Custom_Setting "Allow_Updates_OverVPN")"
printf "\n ${GRNct}4${NOct}. Toggle Tailscale Access During Updates"
printf "\n ${GRNct}4${NOct}. Toggle Tailscale/ZeroTier Access During Updates"
if [ "$VPNAccess" = "DISABLED" ]
then
printf "\n${padStr}[Currently ${GRNct}DISABLED${NOct}]\n"
Expand Down

0 comments on commit a6ed737

Please sign in to comment.