Skip to content

Commit 5923f38

Browse files
Merge pull request #251 from ExtremeFiretop/dev
Dev 1.2.4 As Next Stable Release
2 parents 77f61d4 + f1c4b19 commit 5923f38

File tree

3 files changed

+151
-42
lines changed

3 files changed

+151
-42
lines changed

MerlinAU.sh

Lines changed: 144 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
#
55
# Original Creation Date: 2023-Oct-01 by @ExtremeFiretop.
66
# Official Co-Author: @Martinski W. - Date: 2023-Nov-01
7-
# Last Modified: 2024-Jun-24
7+
# Last Modified: 2024-Jun-28
88
###################################################################
99
set -u
1010

11-
readonly SCRIPT_VERSION=1.2.3
11+
readonly SCRIPT_VERSION=1.2.4
1212
readonly SCRIPT_NAME="MerlinAU"
1313

1414
##-------------------------------------##
@@ -265,12 +265,12 @@ FW_UpdateCheckScript="/usr/sbin/webs_update.sh"
265265
#---------------------------------------------------------#
266266
_GetDefaultUSBMountPoint_()
267267
{
268-
local mounPointPath retCode=0
268+
local mountPointPath retCode=0
269269
local mountPointRegExp="^/dev/sd.* /tmp/mnt/.*"
270270

271-
mounPointPath="$(grep -m1 "$mountPointRegExp" /proc/mounts | awk -F ' ' '{print $2}')"
272-
[ -z "$mounPointPath" ] && retCode=1
273-
echo "$mounPointPath" ; return "$retCode"
271+
mountPointPath="$(grep -m1 "$mountPointRegExp" /proc/mounts | awk -F ' ' '{print $2}')"
272+
[ -z "$mountPointPath" ] && retCode=1
273+
echo "$mountPointPath" ; return "$retCode"
274274
}
275275

276276
##----------------------------------------##
@@ -713,7 +713,7 @@ else
713713
fi
714714

715715
##------------------------------------------##
716-
## Modified by ExtremeFiretop [2024-May-25] ##
716+
## Modified by ExtremeFiretop [2024-Jun-27] ##
717717
##------------------------------------------##
718718
_Init_Custom_Settings_Config_()
719719
{
@@ -734,6 +734,7 @@ _Init_Custom_Settings_Config_()
734734
echo "FW_New_Update_EMail_CC_Name=TBD"
735735
echo "FW_New_Update_EMail_CC_Address=TBD"
736736
echo "CheckChangeLog ENABLED"
737+
echo "Allow_Updates_OverVPN DISABLED"
737738
echo "FW_New_Update_Changelog_Approval=TBD"
738739
echo "FW_Allow_Beta_Production_Up ENABLED"
739740
echo "FW_Auto_Backupmon ENABLED"
@@ -793,6 +794,11 @@ _Init_Custom_Settings_Config_()
793794
sed -i "10 i CheckChangeLog ENABLED" "$SETTINGSFILE"
794795
retCode=1
795796
fi
797+
if ! grep -q "^Allow_Updates_OverVPN " "$SETTINGSFILE"
798+
then
799+
sed -i "10 i Allow_Updates_OverVPN DISABLED" "$SETTINGSFILE"
800+
retCode=1
801+
fi
796802
if ! grep -q "^FW_Allow_Beta_Production_Up " "$SETTINGSFILE"
797803
then
798804
sed -i "11 i FW_Allow_Beta_Production_Up ENABLED" "$SETTINGSFILE"
@@ -812,7 +818,7 @@ _Init_Custom_Settings_Config_()
812818
}
813819

814820
##------------------------------------------##
815-
## Modified by ExtremeFiretop [2024-May-06] ##
821+
## Modified by ExtremeFiretop [2024-Jun-27] ##
816822
##------------------------------------------##
817823
Get_Custom_Setting()
818824
{
@@ -825,6 +831,7 @@ Get_Custom_Setting()
825831
if [ -f "$SETTINGSFILE" ]; then
826832
case "$setting_type" in
827833
"ROGBuild" | "credentials_base64" | "CheckChangeLog" | \
834+
"Allow_Updates_OverVPN" | \
828835
"FW_Allow_Beta_Production_Up" | \
829836
"FW_Auto_Backupmon" | \
830837
"FW_New_Update_Notification_Date" | \
@@ -883,7 +890,7 @@ _GetAllNodeSettings_()
883890
}
884891

885892
##------------------------------------------##
886-
## Modified by ExtremeFiretop [2024-May-06] ##
893+
## Modified by ExtremeFiretop [2024-Jun-27] ##
887894
##------------------------------------------##
888895
Update_Custom_Settings()
889896
{
@@ -897,6 +904,7 @@ Update_Custom_Settings()
897904

898905
case "$setting_type" in
899906
"ROGBuild" | "credentials_base64" | "CheckChangeLog" | \
907+
"Allow_Updates_OverVPN" | \
900908
"FW_Allow_Beta_Production_Up" | \
901909
"FW_Auto_Backupmon" | \
902910
"FW_New_Update_Notification_Date" | \
@@ -1081,7 +1089,7 @@ _Set_FW_UpdateLOG_DirectoryPath_()
10811089
# Move any existing log files to new directory #
10821090
mv -f "${FW_LOG_DIR}"/*.log "$newLogFileDirPath" 2>/dev/null
10831091
# Remove now the obsolete directory path #
1084-
rm -fr "$FW_LOG_DIR"
1092+
rm -fr "${FW_LOG_DIR:?}"
10851093
# Update the log directory path after validation #
10861094
Update_Custom_Settings FW_New_Update_LOG_Directory_Path "$newLogBaseDirPath"
10871095
Update_Custom_Settings FW_New_Update_LOG_Preferred_Path "$newLogBaseDirPath"
@@ -1156,7 +1164,7 @@ _Set_FW_UpdateZIP_DirectoryPath_()
11561164
return 1
11571165
fi
11581166
# Remove now the obsolete directory path #
1159-
rm -fr "$FW_ZIP_DIR"
1167+
rm -fr "${FW_ZIP_DIR:?}"
11601168
rm -f "${newZIP_FileDirPath}"/*.zip "${newZIP_FileDirPath}"/*.sha256
11611169
Update_Custom_Settings FW_New_Update_ZIP_Directory_Path "$newZIP_BaseDirPath"
11621170
echo "The directory path for the F/W ZIP file was updated successfully."
@@ -1274,7 +1282,7 @@ if echo "$UserPreferredLogPath" | grep -qE "^(/tmp/mnt/|/tmp/opt/|/opt/)" && \
12741282
[ "$UserPreferredLogPath" != "$FW_LOG_BASE_DIR" ]
12751283
then
12761284
mv -f "${FW_LOG_DIR}"/*.log "${UserPreferredLogPath}/$FW_LOG_SUBDIR" 2>/dev/null
1277-
rm -fr "$FW_LOG_DIR"
1285+
rm -fr "${FW_LOG_DIR:?}"
12781286
Update_Custom_Settings FW_New_Update_LOG_Directory_Path "$UserPreferredLogPath"
12791287
fi
12801288

@@ -1907,8 +1915,8 @@ _DoCleanUp_()
19071915
"$keepZIPfile" && [ -f "$FW_ZIP_FPATH" ] && \
19081916
mv -f "$FW_ZIP_FPATH" "${FW_ZIP_BASE_DIR}/$ScriptDirNameD" && moveZIPback=true
19091917

1910-
rm -f "${FW_ZIP_DIR}"/*
1911-
"$delBINfiles" && rm -f "${FW_BIN_DIR}"/*
1918+
rm -f "${FW_ZIP_DIR:?}"/*
1919+
"$delBINfiles" && rm -f "${FW_BIN_DIR:?}"/*
19121920

19131921
# Move file back to original location #
19141922
"$keepZIPfile" && "$moveZIPback" && \
@@ -2443,7 +2451,9 @@ _GetNodeInfo_()
24432451
--cookie-jar '/tmp/nodecookies.txt' \
24442452
--max-time 2 > /tmp/login_response.txt 2>&1
24452453

2446-
if [ $? -ne 0 ]; then
2454+
if [ $? -ne 0 ]
2455+
then
2456+
printf "\n${REDct}Login failed for AiMesh Node [$NodeIP_Address].${NOct}\n"
24472457
return 1
24482458
fi
24492459

@@ -2459,7 +2469,9 @@ _GetNodeInfo_()
24592469
--cookie '/tmp/nodecookies.txt' \
24602470
--max-time 2 2>&1)"
24612471

2462-
if [ $? -ne 0 ]; then
2472+
if [ $? -ne 0 ] || [ -z "$htmlContent" ]
2473+
then
2474+
printf "\n${REDct}Failed to get information for AiMesh Node [$NodeIP_Address].${NOct}\n"
24632475
return 1
24642476
fi
24652477

@@ -2596,6 +2608,41 @@ _toggle_change_log_check_()
25962608
_WaitForEnterKey_
25972609
}
25982610

2611+
##------------------------------------------##
2612+
## Modified by ExtremeFiretop [2024-Jun-27] ##
2613+
##------------------------------------------##
2614+
_Toggle_VPN_Access_()
2615+
{
2616+
local currentSetting="$(Get_Custom_Setting "Allow_Updates_OverVPN")"
2617+
2618+
if [ "$currentSetting" = "ENABLED" ]
2619+
then
2620+
printf "${REDct}*WARNING*${NOct}\n"
2621+
printf "Disabling this feature will shut down Diversion and Tailscale VPN access during updates.\n"
2622+
printf "Proceed only if you do not need VPN access during updates.\n"
2623+
2624+
if _WaitForYESorNO_ "\nProceed to ${GRNct}DISABLE${NOct}?"
2625+
then
2626+
Update_Custom_Settings "Allow_Updates_OverVPN" "DISABLED"
2627+
printf "VPN access will now be ${GRNct}DISABLED.${NOct}\n"
2628+
else
2629+
printf "VPN access during updates remains ${REDct}ENABLED.${NOct}\n"
2630+
fi
2631+
else
2632+
printf "${REDct}*WARNING*${NOct}\n"
2633+
printf "Enabling this feature will keep Diversion and Tailscale VPN access active during updates.\n"
2634+
printf "Proceed only if you need VPN access during updates.\n"
2635+
if _WaitForYESorNO_ "\nProceed to ${REDct}ENABLE${NOct}?"
2636+
then
2637+
Update_Custom_Settings "Allow_Updates_OverVPN" "ENABLED"
2638+
printf "VPN access will now be ${REDct}ENABLED.${NOct}\n"
2639+
else
2640+
printf "VPN access during updates remains ${GRNct}DISABLED.${NOct}\n"
2641+
fi
2642+
fi
2643+
_WaitForEnterKey_
2644+
}
2645+
25992646
##----------------------------------------##
26002647
## Modified by Martinski W. [2024-May-27] ##
26012648
##----------------------------------------##
@@ -4063,38 +4110,75 @@ _Toggle_FW_UpdateCheckSetting_()
40634110
}
40644111

40654112
##----------------------------------------##
4066-
## Modified by Martinski W. [2024-Jun-16] ##
4113+
## Modified by Martinski W. [2024-Jun-28] ##
40674114
##----------------------------------------##
40684115
_EntwareServicesHandler_()
40694116
{
40704117
if [ $# -eq 0 ] || [ -z "$1" ] ; then return 1 ; fi
4118+
local AllowVPN="$(Get_Custom_Setting Allow_Updates_OverVPN)"
40714119

4072-
local actionStr="" divAction=""
4120+
local actionStr=""
40734121
local serviceStr serviceCnt=0
40744122
local entwOPT_init entwOPT_unslung
4123+
# space-delimited list #
4124+
local skipServiceList="tailscaled"
4125+
local skippedService skippedServiceFile skippedServiceList=""
4126+
4127+
entwOPT_init="/opt/etc/init.d"
4128+
entwOPT_unslung="${entwOPT_init}/rc.unslung"
40754129

40764130
case "$1" in
4077-
stop) actionStr="Stopping" ; divAction="unmount" ;;
4078-
start) actionStr="Restarting" ; divAction="mount" ;;
4131+
stop) actionStr="Stopping" ;;
4132+
start) actionStr="Restarting" ;;
40794133
*) return 1 ;;
40804134
esac
40814135

4082-
if [ -f /opt/bin/diversion ]
4083-
then
4084-
Say "${actionStr} Diversion service..."
4085-
/opt/bin/diversion "$divAction" &
4086-
sleep 3
4087-
fi
4088-
4089-
entwOPT_init="/opt/etc/init.d"
4090-
entwOPT_unslung="${entwOPT_init}/rc.unslung"
4136+
_RenameSkippedService_()
4137+
{
4138+
[ -z "$skippedServiceList" ] && return 1
4139+
for skippedServiceFile in $skippedServiceList
4140+
do # Rename service file back to original state #
4141+
if mv -f "${entwOPT_init}/OFF.${skippedServiceFile}.OFF" "${entwOPT_init}/$skippedServiceFile"
4142+
then Say "Skipped $skippedServiceFile $1 call." ; fi
4143+
done
4144+
return 0
4145+
}
40914146

40924147
if [ ! -x /opt/bin/opkg ] || [ ! -x "$entwOPT_unslung" ]
40934148
then return 0 ; fi ## Entware is NOT found ##
40944149

4095-
serviceStr="$(/usr/bin/find -L "$entwOPT_init" -name "S*" -exec ls -1 {} \; 2>/dev/null | /bin/grep -E "${entwOPT_init}/S[0-9]+")"
4150+
serviceStr="$(/usr/bin/find -L "$entwOPT_init" -name "*" -print 2>/dev/null | /bin/grep -E "(${entwOPT_init}/S[0-9]+|${entwOPT_init}/.*[.]sh$)")"
4151+
4152+
[ -n "$serviceStr" ] && Say "Looking for Entware services..."
4153+
4154+
# Filter out services to skip and add a skip message #
4155+
if [ "$AllowVPN" = "ENABLED" ]
4156+
then
4157+
for skipService in $skipServiceList
4158+
do
4159+
skippedService="$(echo "$serviceStr" | /bin/grep -E "/S[0-9]+.*${skipService}$")"
4160+
if [ -n "$skippedService" ]
4161+
then
4162+
skippedServiceFile="$(basename "$skippedService")"
4163+
Say "Skipping $skippedServiceFile $1 call..."
4164+
# Rename service file so it's skipped by Entware #
4165+
if mv -f "${entwOPT_init}/$skippedServiceFile" "${entwOPT_init}/OFF.${skippedServiceFile}.OFF"
4166+
then
4167+
[ -z "$skippedServiceList" ] && \
4168+
skippedServiceList="$skippedServiceFile" || \
4169+
skippedServiceList="$skippedServiceList $skippedServiceFile"
4170+
serviceStr="$(echo "$serviceStr" | /bin/grep -vE "/S[0-9]+.*${skipService}$")"
4171+
fi
4172+
fi
4173+
done
4174+
fi
4175+
40964176
[ -n "$serviceStr" ] && serviceCnt="$(echo "$serviceStr" | wc -l)"
4097-
[ "$serviceCnt" -eq 0 ] && return 0
4177+
if [ "$serviceCnt" -eq 0 ]
4178+
then
4179+
_RenameSkippedService_ "$1" && echo
4180+
return 0
4181+
fi
40984182

40994183
Say "${actionStr} Entware services..."
41004184
"$isInteractive" && printf "Please wait.\n"
@@ -4104,6 +4188,7 @@ _EntwareServicesHandler_()
41044188
Say "-----------------------------------------------------------"
41054189

41064190
$entwOPT_unslung "$1" ; sleep 5
4191+
_RenameSkippedService_ "$1" && echo
41074192
"$isInteractive" && printf "\nDone.\n"
41084193
}
41094194

@@ -4648,6 +4733,18 @@ Please manually update to version $minimum_supported_version or higher to use th
46484733
Say "Flashing ${GRNct}${firmware_file}${NOct}... ${REDct}Please wait for reboot in about 4 minutes or less.${NOct}"
46494734
echo
46504735

4736+
local AllowVPN="$(Get_Custom_Setting Allow_Updates_OverVPN)"
4737+
if [ "$AllowVPN" = "DISABLED" ]
4738+
then
4739+
if [ -f /opt/bin/diversion ]
4740+
then
4741+
# Diversion unmount command also unloads entware services #
4742+
Say "Stopping Diversion service..."
4743+
/opt/bin/diversion unmount &
4744+
sleep 5
4745+
fi
4746+
fi
4747+
46514748
# *WARNING*: No more logging at this point & beyond #
46524749
/sbin/ejusb -1 0 -u 1
46534750

@@ -4705,6 +4802,7 @@ Please manually update to version $minimum_supported_version or higher to use th
47054802
_SendEMailNotification_ FAILED_FW_UPDATE_STATUS
47064803
_DoCleanUp_ 1 "$keepZIPfile"
47074804
_EntwareServicesHandler_ start
4805+
# /opt/bin/diversion mount >/dev/null #Does not work temporarily
47084806
fi
47094807

47104808
"$inMenuMode" && _WaitForEnterKey_ "$mainMenuReturnPromptStr"
@@ -5646,7 +5744,7 @@ _ShowMainMenu_()
56465744
}
56475745

56485746
##------------------------------------------##
5649-
## Modified by ExtremeFiretop [2024-Jun-03] ##
5747+
## Modified by ExtremeFiretop [2024-Jun-27] ##
56505748
##------------------------------------------##
56515749
_ShowAdvancedOptionsMenu_()
56525750
{
@@ -5662,15 +5760,23 @@ _ShowAdvancedOptionsMenu_()
56625760
printf "\n${padStr}[Current Schedule: ${GRNct}${FW_UpdateCronJobSchedule}${NOct}]\n"
56635761

56645762
local BetaProductionSetting="$(Get_Custom_Setting "FW_Allow_Beta_Production_Up")"
5763+
printf "\n ${GRNct}3${NOct}. Toggle Beta-to-Release F/W Updates"
56655764
if [ "$BetaProductionSetting" = "DISABLED" ]
56665765
then
5667-
printf "\n ${GRNct}3${NOct}. Toggle Beta-to-Release F/W Updates"
56685766
printf "\n${padStr}[Currently ${REDct}DISABLED${NOct}]\n"
56695767
else
5670-
printf "\n ${GRNct}3${NOct}. Toggle Beta-to-Release F/W Updates"
56715768
printf "\n${padStr}[Currently ${GRNct}ENABLED${NOct}]\n"
56725769
fi
56735770

5771+
local VPNAccess="$(Get_Custom_Setting "Allow_Updates_OverVPN")"
5772+
printf "\n ${GRNct}4${NOct}. Toggle VPN Service During Updates"
5773+
if [ "$VPNAccess" = "DISABLED" ]
5774+
then
5775+
printf "\n${padStr}[Currently ${GRNct}DISABLED${NOct}]\n"
5776+
else
5777+
printf "\n${padStr}[Currently ${REDct}ENABLED${NOct}]\n"
5778+
fi
5779+
56745780
if [ -f "/jffs/scripts/backupmon.sh" ]
56755781
then
56765782
# Retrieve the current backup settings
@@ -5851,7 +5957,7 @@ _AdvancedLogsOptions_()
58515957
}
58525958

58535959
##------------------------------------------##
5854-
## Modified by ExtremeFiretop [2024-Jun-03] ##
5960+
## Modified by ExtremeFiretop [2024-Jun-27] ##
58555961
##------------------------------------------##
58565962
_advanced_options_menu_()
58575963
{
@@ -5868,6 +5974,8 @@ _advanced_options_menu_()
58685974
;;
58695975
3) _Toggle_FW_UpdatesFromBeta_
58705976
;;
5977+
4) _Toggle_VPN_Access_
5978+
;;
58715979
ab) if [ -f "/jffs/scripts/backupmon.sh" ]
58725980
then _Toggle_Auto_Backups_
58735981
else _InvalidMenuSelection_
@@ -5932,6 +6040,7 @@ do
59326040
fi
59336041
;;
59346042
1) _RunFirmwareUpdateNow_
6043+
FlashStarted=false
59356044
;;
59366045
2) _GetLoginCredentials_
59376046
;;

0 commit comments

Comments
 (0)