1414# # Forked from https://github.com/jackyaz/spdMerlin ##
1515# # ##
1616# #############################################################
17- # Last Modified: 2026-Apr-11
17+ # Last Modified: 2026-Apr-15
1818# -------------------------------------------------------------
1919
2020# ############# Shellcheck directives #############
3838# ## Start of script variables ###
3939readonly SCRIPT_NAME=" spdMerlin"
4040readonly SCRIPT_NAME_LOWER=" $( echo " $SCRIPT_NAME " | tr ' A-Z' ' a-z' ) "
41- readonly SCRIPT_VERSION=" v4.4.19 "
42- readonly SCRIPT_VERSTAG=" 26041103 "
41+ readonly SCRIPT_VERSION=" v4.4.20 "
42+ readonly SCRIPT_VERSTAG=" 26041500 "
4343SCRIPT_BRANCH=" develop"
4444SCRIPT_REPO=" https://raw.githubusercontent.com/AMTM-OSR/$SCRIPT_NAME /$SCRIPT_BRANCH "
4545readonly SCRIPT_DIR=" /jffs/addons/$SCRIPT_NAME_LOWER .d"
@@ -1058,7 +1058,7 @@ Conf_Exists()
10581058{
10591059 local AUTOMATEDopt delCRON=false
10601060
1061- if [ -f " $SCRIPT_CONF " ]
1061+ if [ -s " $SCRIPT_CONF " ]
10621062 then
10631063 dos2unix " $SCRIPT_CONF "
10641064 chmod 0644 " $SCRIPT_CONF "
@@ -1248,7 +1248,7 @@ Auto_ServiceEvent()
12481248 local theScriptFilePath=" /jffs/scripts/$SCRIPT_NAME_LOWER "
12491249 case $1 in
12501250 create)
1251- if [ -f /jffs/scripts/service-event ]
1251+ if [ -s /jffs/scripts/service-event ]
12521252 then
12531253 STARTUPLINECOUNT=" $( grep -c ' # ' " $SCRIPT_NAME " /jffs/scripts/service-event) "
12541254 STARTUPLINECOUNTEX=" $( grep -cx ' if echo "$2" | /bin/grep -qE "(' " $SCRIPT_NAME_LOWER " ' |vpnclient)" ; then { ' " $theScriptFilePath " ' service_event "$@" & }; fi # ' " $SCRIPT_NAME " /jffs/scripts/service-event) "
@@ -1269,14 +1269,15 @@ Auto_ServiceEvent()
12691269 echo ' if echo "$2" | /bin/grep -qE "(' " $SCRIPT_NAME_LOWER " ' |vpnclient)" ; then { ' " $theScriptFilePath " ' service_event "$@" & }; fi # ' " $SCRIPT_NAME "
12701270 echo
12711271 } > /jffs/scripts/service-event
1272- chmod 0755 /jffs/scripts/service-event
12731272 fi
1273+ chmod 0755 /jffs/scripts/service-event
12741274 ;;
12751275 delete)
1276- if [ -f /jffs/scripts/service-event ]
1276+ if [ -s /jffs/scripts/service-event ]
12771277 then
12781278 STARTUPLINECOUNT=" $( grep -c ' # ' " $SCRIPT_NAME " /jffs/scripts/service-event) "
1279- if [ " $STARTUPLINECOUNT " -gt 0 ]; then
1279+ if [ " $STARTUPLINECOUNT " -gt 0 ]
1280+ then
12801281 sed -i -e ' /# ' " $SCRIPT_NAME " ' /d' /jffs/scripts/service-event
12811282 fi
12821283 fi
@@ -1318,9 +1319,11 @@ Auto_OpenVPN_Event()
13181319 case $1 in
13191320 create)
13201321 # Check if any OpenVPN Client is set up/available in NVRAM #
1321- if ! _CheckForOpenVPN_ClientsAvailable_ ; then return 1 ; fi
1322+ if ! _CheckForOpenVPN_ClientsAvailable_
1323+ then return 1
1324+ fi
13221325
1323- if [ -f /jffs/scripts/openvpn-event ]
1326+ if [ -s /jffs/scripts/openvpn-event ]
13241327 then
13251328 STARTUPLINECOUNT=" $( grep -c ' # ' " $SCRIPT_NAME " /jffs/scripts/openvpn-event) "
13261329 STARTUPLINECOUNTEX=" $( grep -cx ' \[ -x ' " $theScriptFilePath " ' \] && ' " $theScriptFilePath " ' openvpn_event "$1" "$script_type" & # ' " $SCRIPT_NAME " /jffs/scripts/openvpn-event) "
@@ -1341,14 +1344,15 @@ Auto_OpenVPN_Event()
13411344 echo ' [ -x ' " $theScriptFilePath " ' ] && ' " $theScriptFilePath " ' openvpn_event "$1" "$script_type" & # ' " $SCRIPT_NAME "
13421345 echo
13431346 } > /jffs/scripts/openvpn-event
1344- chmod 0755 /jffs/scripts/openvpn-event
13451347 fi
1348+ chmod 0755 /jffs/scripts/openvpn-event
13461349 ;;
13471350 delete)
1348- if [ -f /jffs/scripts/openvpn-event ]
1351+ if [ -s /jffs/scripts/openvpn-event ]
13491352 then
13501353 STARTUPLINECOUNT=" $( grep -c ' # ' " $SCRIPT_NAME " /jffs/scripts/openvpn-event) "
1351- if [ " $STARTUPLINECOUNT " -gt 0 ]; then
1354+ if [ " $STARTUPLINECOUNT " -gt 0 ]
1355+ then
13521356 sed -i -e ' /# ' " $SCRIPT_NAME " ' /d' /jffs/scripts/openvpn-event
13531357 fi
13541358 fi
@@ -1396,12 +1400,14 @@ Auto_WG_ClientEvent()
13961400 case $1 in
13971401 create)
13981402 # Check if any WireGuard Client is set up/available in NVRAM #
1399- if ! _CheckForWireGuard_ClientsAvailable_ ; then return 1 ; fi
1403+ if ! _CheckForWireGuard_ClientsAvailable_
1404+ then return 1
1405+ fi
14001406
14011407 for wgClientEvent in stop start
14021408 do
14031409 wgClientFilePath=" /jffs/scripts/wgclient-$wgClientEvent "
1404- if [ -f " $wgClientFilePath " ]
1410+ if [ -s " $wgClientFilePath " ]
14051411 then
14061412 STARTUPLINECOUNT=" $( grep -c ' # ' " $SCRIPT_NAME " " $wgClientFilePath " ) "
14071413 STARTUPLINECOUNTEX=" $( grep -cx ' \[ -x ' " $theScriptFilePath " ' \] && ' " $theScriptFilePath " ' wgclient_event ' " $wgClientEvent " ' "$@" & # ' " $SCRIPT_NAME " " $wgClientFilePath " ) "
@@ -1422,18 +1428,19 @@ Auto_WG_ClientEvent()
14221428 echo ' [ -x ' " $theScriptFilePath " ' ] && ' " $theScriptFilePath " ' wgclient_event ' " $wgClientEvent " ' "$@" & # ' " $SCRIPT_NAME "
14231429 echo
14241430 } > " $wgClientFilePath "
1425- chmod 0755 " $wgClientFilePath "
14261431 fi
1432+ chmod 0755 " $wgClientFilePath "
14271433 done
14281434 ;;
14291435 delete)
14301436 for wgClientEvent in stop start
14311437 do
14321438 wgClientFilePath=" /jffs/scripts/wgclient-$wgClientEvent "
1433- if [ -f " $wgClientFilePath " ]
1439+ if [ -s " $wgClientFilePath " ]
14341440 then
14351441 STARTUPLINECOUNT=" $( grep -c ' # ' " $SCRIPT_NAME " " $wgClientFilePath " ) "
1436- if [ " $STARTUPLINECOUNT " -gt 0 ]; then
1442+ if [ " $STARTUPLINECOUNT " -gt 0 ]
1443+ then
14371444 sed -i -e ' /# ' " $SCRIPT_NAME " ' /d' " $wgClientFilePath "
14381445 fi
14391446 fi
@@ -1450,14 +1457,15 @@ Auto_Startup()
14501457 local theScriptFilePath=" /jffs/scripts/$SCRIPT_NAME_LOWER "
14511458 case $1 in
14521459 create)
1453- if [ -f /jffs/scripts/services-start ]
1460+ if [ -s /jffs/scripts/services-start ]
14541461 then
14551462 STARTUPLINECOUNT=" $( grep -c ' # ' " $SCRIPT_NAME " /jffs/scripts/services-start) "
1456- if [ " $STARTUPLINECOUNT " -gt 0 ]; then
1463+ if [ " $STARTUPLINECOUNT " -gt 0 ]
1464+ then
14571465 sed -i -e ' /# ' " $SCRIPT_NAME " ' /d' /jffs/scripts/services-start
14581466 fi
14591467 fi
1460- if [ -f /jffs/scripts/post-mount ]
1468+ if [ -s /jffs/scripts/post-mount ]
14611469 then
14621470 STARTUPLINECOUNT=" $( grep -c ' # ' " $SCRIPT_NAME " /jffs/scripts/post-mount) "
14631471 STARTUPLINECOUNTEX=" $( grep -cx ' \[ -x "${1}/entware/bin/opkg" \] && \[ -x ' " $theScriptFilePath " ' \] && ' " $theScriptFilePath " ' startup "$@" & # ' " $SCRIPT_NAME " /jffs/scripts/post-mount) "
@@ -1479,21 +1487,23 @@ Auto_Startup()
14791487 echo ' [ -x "${1}/entware/bin/opkg" ] && [ -x ' " $theScriptFilePath " ' ] && ' " $theScriptFilePath " ' startup "$@" & # ' " $SCRIPT_NAME "
14801488 echo
14811489 } > /jffs/scripts/post-mount
1482- chmod 0755 /jffs/scripts/post-mount
14831490 fi
1491+ chmod 0755 /jffs/scripts/post-mount
14841492 ;;
14851493 delete)
1486- if [ -f /jffs/scripts/services-start ]
1494+ if [ -s /jffs/scripts/services-start ]
14871495 then
14881496 STARTUPLINECOUNT=" $( grep -c ' # ' " $SCRIPT_NAME " /jffs/scripts/services-start) "
1489- if [ " $STARTUPLINECOUNT " -gt 0 ]; then
1497+ if [ " $STARTUPLINECOUNT " -gt 0 ]
1498+ then
14901499 sed -i -e ' /# ' " $SCRIPT_NAME " ' /d' /jffs/scripts/services-start
14911500 fi
14921501 fi
1493- if [ -f /jffs/scripts/post-mount ]
1502+ if [ -s /jffs/scripts/post-mount ]
14941503 then
14951504 STARTUPLINECOUNT=" $( grep -c ' # ' " $SCRIPT_NAME " /jffs/scripts/post-mount) "
1496- if [ " $STARTUPLINECOUNT " -gt 0 ]; then
1505+ if [ " $STARTUPLINECOUNT " -gt 0 ]
1506+ then
14971507 sed -i -e ' /# ' " $SCRIPT_NAME " ' /d' /jffs/scripts/post-mount
14981508 fi
14991509 fi
@@ -1510,9 +1520,11 @@ Auto_Cron()
15101520 case $1 in
15111521 create)
15121522 STARTUPLINECOUNT=" $( cru l | grep -c " #${SCRIPT_NAME} #" ) "
1513- if [ " $STARTUPLINECOUNT " -gt 0 ]; then
1523+ if [ " $STARTUPLINECOUNT " -gt 0 ]
1524+ then
15141525 cru d " ${SCRIPT_NAME} "
15151526 fi
1527+
15161528 STARTUPLINECOUNTGEN=" $( cru l | grep -c " ${SCRIPT_NAME} _generate" ) "
15171529 CRU_SCHHOUR=" $( _GetConfigParam_ SCHHOURS ' *' ) "
15181530 CRU_SCHMINS=" $( _GetConfigParam_ SCHMINS ' 12,42' ) "
@@ -1535,21 +1547,25 @@ Auto_Cron()
15351547 cru d " ${SCRIPT_NAME} _trimDB"
15361548 STARTUPLINECOUNTTRIM=" $( cru l | grep -c " ${SCRIPT_NAME} _trimDB" ) "
15371549 fi
1538- if [ " $STARTUPLINECOUNTTRIM " -eq 0 ]; then
1550+ if [ " $STARTUPLINECOUNTTRIM " -eq 0 ]
1551+ then
15391552 cru a " ${SCRIPT_NAME} _trimDB" " $defTrimDB_Mins $defTrimDB_Hour * * * $theScriptFilePath trimdb"
15401553 fi
15411554 ;;
15421555 delete)
15431556 STARTUPLINECOUNT=" $( cru l | grep -c " #${SCRIPT_NAME} #" ) "
1544- if [ " $STARTUPLINECOUNT " -gt 0 ]; then
1557+ if [ " $STARTUPLINECOUNT " -gt 0 ]
1558+ then
15451559 cru d " $SCRIPT_NAME "
15461560 fi
15471561 STARTUPLINECOUNTGEN=" $( cru l | grep -c " #${SCRIPT_NAME} _generate#" ) "
1548- if [ " $STARTUPLINECOUNTGEN " -gt 0 ]; then
1562+ if [ " $STARTUPLINECOUNTGEN " -gt 0 ]
1563+ then
15491564 cru d " ${SCRIPT_NAME} _generate"
15501565 fi
15511566 STARTUPLINECOUNTTRIM=" $( cru l | grep -c " #${SCRIPT_NAME} _trimDB#" ) "
1552- if [ " $STARTUPLINECOUNTTRIM " -gt 0 ]; then
1567+ if [ " $STARTUPLINECOUNTTRIM " -gt 0 ]
1568+ then
15531569 cru d " ${SCRIPT_NAME} _trimDB"
15541570 fi
15551571 ;;
0 commit comments