44#
55# Original Creation Date: 2023-Oct-01 by @ExtremeFiretop.
66# Official Co-Author: @Martinski W. - Date: 2023-Nov-01
7- # Last Modified: 2025-Mar-24
7+ # Last Modified: 2025-Mar-28
88# ##################################################################
99set -u
1010
@@ -3485,19 +3485,18 @@ _GetFreeRAM_KB_()
34853485# #----------------------------------------##
34863486_GetRequiredRAM_KB_ ()
34873487{
3488- local url =" $1 "
3488+ local theURL =" $1 "
34893489 local zip_file_size_bytes zip_file_size_kb overhead_kb
34903490 local total_required_kb overhead_percentage=50
34913491
3492- # Size of the ZIP file in bytes
3493- zip_file_size_bytes=" $( curl -LsI --retry 4 --retry-delay 5 " $url " | grep -i Content-Length | tail -1 | awk ' {print $2}' ) "
3494- # Convert bytes to kilobytes
3492+ # Size of the ZIP file in bytes #
3493+ zip_file_size_bytes=" $( curl -LsI --retry 4 --retry-delay 5 " $theURL " | grep -i Content-Length | tail -1 | awk ' {print $2}' ) "
3494+ # Bytes to KBytes #
34953495 zip_file_size_kb=" $(( zip_file_size_bytes / 1024 )) "
34963496
3497- # Calculate overhead based on the percentage
3497+ # Calculate overhead based on the percentage #
34983498 overhead_kb=" $(( zip_file_size_kb * overhead_percentage / 100 )) "
34993499
3500- # Calculate total required space
35013500 total_required_kb=" $(( zip_file_size_kb + overhead_kb)) "
35023501 echo " $total_required_kb "
35033502}
@@ -4569,13 +4568,14 @@ _GetLatestFWUpdateVersionFromNode_()
45694568# #----------------------------------------##
45704569_GetLatestFWUpdateVersionFromWebsite_ ()
45714570{
4572- local url =" $1 "
4571+ local theURL =" $1 "
45734572
4574- local links_and_versions=" $( curl -Ls --retry 4 --retry-delay 5 " $url " | grep -o ' href="[^"]*' " $PRODUCT_ID " ' [^"]*\.zip' | sed ' s/amp;//g; s/href="//' | \
4573+ local links_and_versions=" $( curl -Ls --retry 4 --retry-delay 5 " $theURL " | grep -o ' href="[^"]*' " $PRODUCT_ID " ' [^"]*\.zip' | sed ' s/amp;//g; s/href="//' | \
45754574 awk -F' [_\.]' ' {print $3"."$4"."$5" "$0}' | sort -t. -k1,1n -k2,2n -k3,3n) "
45764575
45774576 if [ -z " $links_and_versions " ]
4578- then echo " **ERROR** **NO_URL**" ; return 1 ; fi
4577+ then echo " **ERROR** **NO_URL**" ; return 1
4578+ fi
45794579
45804580 local latest=" $( echo " $links_and_versions " | tail -n 1) "
45814581 local linkStr=" $( echo " $latest " | cut -d' ' -f2-) "
@@ -4587,165 +4587,164 @@ _GetLatestFWUpdateVersionFromWebsite_()
45874587 else versionStr=" $( echo " ${fileStr% .* } " | sed " s/\/${PRODUCT_ID} _//" | sed ' s/_/./g' ) "
45884588 fi
45894589
4590- # Extracting the correct link from the page
4590+ # Extracting the correct link from the page #
45914591 local correct_link=" $( echo " $linkStr " | sed ' s|^/|https://sourceforge.net/|' ) "
45924592
45934593 if [ -z " $versionStr " ] || [ -z " $correct_link " ]
4594- then echo " **ERROR** **NO_URL**" ; return 1 ; fi
4594+ then echo " **ERROR** **NO_URL**" ; return 1
4595+ fi
45954596
45964597 echo " $versionStr "
45974598 echo " $correct_link "
45984599 return 0
45994600}
46004601
4601- # #---------------------------------------##
4602- # # Added by ExtremeFiretop [2024-Feb-23 ] ##
4603- # #---------------------------------------##
4604- _GetLatestFWUpdateVersionFromGithub_ ()
4602+ # #---------------------------------------- ##
4603+ # # Modified by Martinski W. [2024-Mar-27 ] ##
4604+ # #---------------------------------------- ##
4605+ _GetLatestFWUpdateVersionFromGitHub_ ()
46054606{
4606- local url=" $1 " # GitHub API URL for the latest release
4607- local firmware_type=" $2 " # Type of firmware, e.g., "tuf", "rog" or "pure"
4607+ local routerVersion
4608+ local gitURL=" $1 " # GitHub URL for the latest release #
4609+ local firmware_type=" $2 " # "tuf", "rog" or "pure" #
46084610
4609- local search_type=" $firmware_type " # Default to the input firmware_type
4611+ local search_type=" $firmware_type " # Default to the input firmware_type #
46104612
46114613 # If firmware_type is "pure", set search_type to include "squashfs" as well
4612- if [ " $firmware_type " = " pure" ]; then
4614+ if [ " $firmware_type " = " pure" ]
4615+ then
46134616 search_type=" pure\|squashfs\|ubi"
46144617 fi
46154618
46164619 if ! " $offlineUpdateTrigger "
46174620 then
4618- # Get the router version from the router itself
4619- local router_version=" $( _GetLatestFWUpdateVersionFromRouter_ 1) "
4621+ routerVersion=" $( _GetLatestFWUpdateVersionFromRouter_ 1) "
46204622 else
4621- # Get the router version from the router itself
4622- local router_version=" $( Get_Custom_Setting " FW_New_Update_Notification_Vers" ) "
4623+ routerVersion=" $( Get_Custom_Setting " FW_New_Update_Notification_Vers" ) "
46234624 fi
4624-
4625- if [ -z " $router_version " ] ; then
4625+ if [ -z " $routerVersion " ]
4626+ then
46264627 echo " **ERROR** **NO_ROUTER_VERSION**"
46274628 return 1
46284629 fi
46294630
46304631 # Fetch the latest release data from GitHub #
4631- local release_data=" $( curl -s " $url " ) "
4632+ local release_data=" $( curl -s " $gitURL " ) "
46324633
46334634 # Construct the grep pattern based on search_type #
46344635 local grep_pattern=" \" browser_download_url\" : \" .*${PRODUCT_ID} .*\(${search_type} \).*\.\(w\|pkgtb\)\" "
46354636
4636- # Extract all matched download URLs
4637- local download_urls =" $( echo " $release_data " | \
4637+ # Extract all matched download URLs #
4638+ local downloadURLs =" $( echo " $release_data " | \
46384639 grep -o " $grep_pattern " | \
46394640 grep -o " https://[^ ]*\.\(w\|pkgtb\)" ) "
46404641
4641- # Check if a URL was found
4642- if [ -z " $download_urls " ]
4642+ if [ -z " $downloadURLs " ]
46434643 then
46444644 echo " **ERROR** **NO_GITHUB_URL**"
46454645 return 1
46464646 else
4647- # Loop through each matching URL and compare version to router_version
4648- local url_item version
4649- for url_item in $download_urls ; do
4650- # Extract the version portion from the URL
4651- local version =" $( echo " $url_item " \
4647+ local theURL urlVersion
4648+ for theURL in $downloadURLs
4649+ do
4650+ # Extract the version portion from the URL #
4651+ urlVersion =" $( echo " $theURL " \
46524652 | grep -oE " ${PRODUCT_ID} _[^ ]*\.(w|pkgtb)" \
46534653 | sed " s/${PRODUCT_ID} _//;s/.w$//;s/.pkgtb$//;s/.ubi$//;s/_/./g" | head -n1) "
46544654
4655- # If this URL’s version matches the router version, we're done
4656- if [ " $version " = " $router_version " ] ; then
4657- echo " $version "
4658- echo " $url_item "
4655+ if [ " $urlVersion " = " $routerVersion " ]
4656+ then
4657+ echo " $urlVersion "
4658+ echo " $theURL "
46594659 return 0
46604660 fi
46614661 done
46624662 fi
46634663}
46644664
4665- # #---------------------------------------##
4666- # # Added by ExtremeFiretop [2024-Apr-05 ] ##
4667- # #---------------------------------------##
4668- GetLatestFirmwareMD5Url ()
4665+ # #---------------------------------------- ##
4666+ # # Modified by Martinski W. [2024-Mar-27 ] ##
4667+ # #---------------------------------------- ##
4668+ GetLatestFirmwareMD5URL ()
46694669{
4670- local url=" $1 " # GitHub API URL for the latest release
4671- local firmware_type=" $2 " # Type of firmware, e.g., "tuf", "rog" or "pure"
4670+ local routerVersion
4671+ local gitURL=" $1 " # GitHub URL for the latest release #
4672+ local firmware_type=" $2 " # "tuf", "rog" or "pure" #
46724673
46734674 local search_type=" $firmware_type " # Default to the input firmware_type
46744675
46754676 # If firmware_type is "pure", set search_type to include "squashfs" as well
4676- if [ " $firmware_type " = " pure" ]; then
4677+ if [ " $firmware_type " = " pure" ]
4678+ then
46774679 search_type=" pure\|squashfs\|ubi"
46784680 fi
46794681
46804682 if ! " $offlineUpdateTrigger "
46814683 then
4682- # Get the router version from the router itself
4683- local router_version=" $( _GetLatestFWUpdateVersionFromRouter_ 1) "
4684+ routerVersion=" $( _GetLatestFWUpdateVersionFromRouter_ 1) "
46844685 else
4685- # Get the router version from the router itself
4686- local router_version=" $( Get_Custom_Setting " FW_New_Update_Notification_Vers" ) "
4686+ routerVersion=" $( Get_Custom_Setting " FW_New_Update_Notification_Vers" ) "
46874687 fi
4688-
4689- if [ -z " $router_version " ] ; then
4688+ if [ -z " $routerVersion " ]
4689+ then
46904690 echo " **ERROR** **NO_ROUTER_VERSION**"
46914691 return 1
46924692 fi
46934693
4694- # Fetch the latest release data from GitHub
4695- local release_data=" $( curl -s " $url " ) "
4694+ # Fetch the latest release data from GitHub #
4695+ local release_data=" $( curl -s " $gitURL " ) "
46964696
4697- # Construct the grep pattern based on search_type
4697+ # Construct the grep pattern based on search_type #
46984698 local grep_pattern=" \" browser_download_url\" : \" .*${PRODUCT_ID} .*\(${search_type} \).*\.md5\" "
46994699
4700- # Extract all matched download URLs
4701- local md5_urls =" $( echo " $release_data " |
4700+ # Extract all matched download URLs #
4701+ local md5_URLs =" $( echo " $release_data " |
47024702 grep -o " $grep_pattern " |
47034703 sed -E ' s/.*"browser_download_url": "([^"]+)".*/\1/' ) "
47044704
4705- # Check if a URL was found and output result or error
4706- if [ -z " $md5_urls " ]
4705+ if [ -z " $md5_URLs " ]
47074706 then
47084707 echo " **ERROR** **NO_MD5_FILE_URL_FOUND**"
47094708 return 1
47104709 else
4711- # Loop through each matching URL and compare version to router_version
4712- local url_item version
4713- for url_item in $md5_urls ; do
4714- # Extract the version portion from the URL
4715- local md5 =" $( echo " $url_item " \
4710+ local theURL md5Version
4711+ for theURL in $md5_URLs
4712+ do
4713+ # Extract the version portion from the URL #
4714+ md5Version =" $( echo " $theURL " \
47164715 | grep -oE " ${PRODUCT_ID} _[^ ]*\.(md5)" \
47174716 | sed " s/${PRODUCT_ID} _//;s/.md5$//;s/.w$//;s/.pkgtb$//;s/.ubi$//;s/_/./g" | head -n1) "
47184717
4719- # If this URL’s version matches the router version, we're done
4720- if [ " $md5 " = " $router_version " ] ; then
4721- echo " $md5 "
4718+ if [ " $md5Version " = " $routerVersion " ]
4719+ then
4720+ echo " $theURL "
47224721 return 0
47234722 fi
47244723 done
47254724 fi
47264725}
47274726
4728- # #---------------------------------------##
4729- # # Added by ExtremeFiretop [2024-Apr-17 ] ##
4730- # #---------------------------------------##
4731- GetLatestChangelogUrl ()
4727+ # #---------------------------------------- ##
4728+ # # Modified by Martinski W. [2024-Mar-27 ] ##
4729+ # #---------------------------------------- ##
4730+ GetLatestChangelogURL ()
47324731{
4733- local url=" $1 " # GitHub API URL for the latest release
4732+ local gitURL=" $1 " # GitHub URL for the latest release #
4733+ local changelogURL
47344734
4735- # Fetch the latest release data from GitHub
4736- local release_data=" $( curl -s " $url " ) "
4735+ # Fetch the latest release data from GitHub #
4736+ local release_data=" $( curl -s " $gitURL " ) "
47374737
47384738 # Parse the release data to find the download URL of the CHANGELOG file
47394739 # Directly find the URL without matching a specific model number
4740- local changelog_url =" $( echo " $release_data " | grep -o " \" browser_download_url\" : \" .*CHANGELOG.*\" " | grep -o " https://[^ ]*\" " | tr -d ' "' | head -1 ) "
4740+ changelogURL =" $( echo " $release_data " | grep -o " \" browser_download_url\" : \" .*CHANGELOG.*\" " | grep -o " https://[^ ]*\" " | tr -d ' "' | head -n1 ) "
47414741
4742- # Check if the URL has been found
4743- if [ -z " $changelog_url " ]
4742+ if [ -z " $changelogURL " ]
47444743 then
47454744 echo " **ERROR** **NO_CHANGELOG_FILE_URL_FOUND**"
47464745 return 1
47474746 else
4748- echo " $changelog_url "
4747+ echo " $changelogURL "
47494748 fi
47504749}
47514750
@@ -7322,7 +7321,7 @@ _ManageChangelogGnuton_()
73227321 # Create directory to download changelog if missing
73237322 if ! _CreateDirectory_ " $FW_BIN_DIR " ; then return 1 ; fi
73247323
7325- GnutonChangeLogURL=" $( GetLatestChangelogUrl " $FW_GITURL_RELEASE " ) "
7324+ GnutonChangeLogURL=" $( GetLatestChangelogURL " $FW_GITURL_RELEASE " ) "
73267325
73277326 # Follow redirects and capture the effective URL
73287327 local effective_url=" $( curl -Ls -o /dev/null -w %{url_effective} " $GnutonChangeLogURL " ) "
@@ -7497,7 +7496,7 @@ _CheckNodeFWUpdateNotification_()
74977496 echo " Please click here to review the latest changelog:"
74987497 if " $NodeGNUtonFW "
74997498 then
7500- GnutonChangeLogURL=" $( GetLatestChangelogUrl " $FW_GITURL_RELEASE " ) "
7499+ GnutonChangeLogURL=" $( GetLatestChangelogURL " $FW_GITURL_RELEASE " ) "
75017500 echo " $GnutonChangeLogURL "
75027501 else
75037502 if [ " $node_firmver " -eq 3006 ]
@@ -7529,7 +7528,7 @@ _CheckNodeFWUpdateNotification_()
75297528 echo " Please click here to review the latest changelog:"
75307529 if " $NodeGNUtonFW "
75317530 then
7532- GnutonChangeLogURL=" $( GetLatestChangelogUrl " $FW_GITURL_RELEASE " ) "
7531+ GnutonChangeLogURL=" $( GetLatestChangelogURL " $FW_GITURL_RELEASE " ) "
75337532 echo " $GnutonChangeLogURL "
75347533 else
75357534 if [ " $node_firmver " -eq 3006 ]
@@ -8313,7 +8312,7 @@ _RunOfflineUpdateNow_()
83138312 extension=" ${sanitized_filename##* .} "
83148313 FW_DL_FPATH=" ${FW_ZIP_DIR} /${FW_FileName} .${extension} "
83158314 _GnutonBuildSelection_
8316- set -- $( _GetLatestFWUpdateVersionFromGithub_ " $FW_GITURL_RELEASE " " $firmware_choice " )
8315+ set -- $( _GetLatestFWUpdateVersionFromGitHub_ " $FW_GITURL_RELEASE " " $firmware_choice " )
83178316 retCode=" $? "
83188317 else
83198318 set -- $( _GetLatestFWUpdateVersionFromWebsite_ " $FW_SFURL_RELEASE " )
@@ -8474,9 +8473,9 @@ Please manually update to version ${GRNct}${MinSupportedFirmwareVers}${NOct} or
84748473 then
84758474 Say " Using release information for Gnuton Firmware."
84768475 _GnutonBuildSelection_
8477- md5_url=" $( GetLatestFirmwareMD5Url " $FW_GITURL_RELEASE " " $firmware_choice " ) "
8478- GnutonChangeLogURL=" $( GetLatestChangelogUrl " $FW_GITURL_RELEASE " ) "
8479- set -- $( _GetLatestFWUpdateVersionFromGithub_ " $FW_GITURL_RELEASE " " $firmware_choice " )
8476+ md5_url=" $( GetLatestFirmwareMD5URL " $FW_GITURL_RELEASE " " $firmware_choice " ) "
8477+ GnutonChangeLogURL=" $( GetLatestChangelogURL " $FW_GITURL_RELEASE " ) "
8478+ set -- $( _GetLatestFWUpdateVersionFromGitHub_ " $FW_GITURL_RELEASE " " $firmware_choice " )
84808479 retCode=" $? "
84818480 else
84828481 Say " Using release information for Merlin Firmware."
0 commit comments