From e98fa48259bb951ecd7a75dcd13216ed3fa6cb40 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 17 Oct 2023 20:09:33 +0800 Subject: [PATCH] update 2023-10-17 20:09:33 --- luci-app-amlogic/Makefile | 2 +- .../share/amlogic/amlogic_check_firmware.sh | 122 +++++++++++------- 2 files changed, 75 insertions(+), 49 deletions(-) diff --git a/luci-app-amlogic/Makefile b/luci-app-amlogic/Makefile index 1b2f4897..0fd7e742 100644 --- a/luci-app-amlogic/Makefile +++ b/luci-app-amlogic/Makefile @@ -16,7 +16,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-amlogic -PKG_VERSION:=3.1.207 +PKG_VERSION:=3.1.208 PKG_RELEASE:=1 PKG_LICENSE:=GPL-2.0 License diff --git a/luci-app-amlogic/root/usr/share/amlogic/amlogic_check_firmware.sh b/luci-app-amlogic/root/usr/share/amlogic/amlogic_check_firmware.sh index d39b1eeb..a6ebe404 100755 --- a/luci-app-amlogic/root/usr/share/amlogic/amlogic_check_firmware.sh +++ b/luci-app-amlogic/root/usr/share/amlogic/amlogic_check_firmware.sh @@ -20,15 +20,9 @@ AMLOGIC_SOC_FILE="/etc/flippy-openwrt-release" START_LOG="${TMP_CHECK_DIR}/amlogic_check_firmware.log" RUNNING_LOG="${TMP_CHECK_DIR}/amlogic_running_script.log" LOG_FILE="${TMP_CHECK_DIR}/amlogic.log" -all_releases_list="${TMP_CHECK_DIR}/josn_api_releases" support_platform=("allwinner" "rockchip" "amlogic" "qemu-aarch64") LOGTIME="$(date "+%Y-%m-%d %H:%M:%S")" [[ -d ${TMP_CHECK_DIR} ]] || mkdir -p ${TMP_CHECK_DIR} -# Set github API default value -github_page="1" -github_per_page="100" - -rm -f ${all_releases_list} # Clean the running log clean_running() { @@ -46,8 +40,8 @@ tolog() { this_running_log="3@OpenWrt update in progress, try again later!" running_script="$(cat ${RUNNING_LOG} 2>/dev/null | xargs)" if [[ -n "${running_script}" ]]; then - run_num=$(echo "${running_script}" | awk -F "@" '{print $1}') - run_log=$(echo "${running_script}" | awk -F "@" '{print $2}') + run_num="$(echo "${running_script}" | awk -F "@" '{print $1}')" + run_log="$(echo "${running_script}" | awk -F "@" '{print $2}')" fi if [[ -n "${run_log}" && "${run_num}" -ne "3" ]]; then echo -e "${run_log}" >${START_LOG} 2>/dev/null && sync && exit 1 @@ -101,7 +95,7 @@ tolog "PLATFORM: [ ${PLATFORM} ], BOARD: [ ${BOARD} ], Use in [ ${EMMC_NAME} ]" sleep 2 # 01. Query local version information -tolog "01. Query version information." +tolog "01. Query version information..." # 01.01 Query the current version current_kernel_v="$(uname -r 2>/dev/null | grep -oE '^[1-9].[0-9]{1,3}.[0-9]+')" tolog "01.01 current version: ${current_kernel_v}" @@ -137,46 +131,80 @@ fi # 02. Check Updated check_updated() { - tolog "02. Start checking for the latest version..." + tolog "02.01 Search for tags in the first 5 pages of releases..." - # Get the release list - while true; do - response="$( - curl -s -L \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - "https://api.github.com/repos/${server_firmware_url}/releases?per_page=${github_per_page}&page=${github_page}" - )" + # Get the tags list + firmware_tags_array=() + for i in {1..5}; do + while IFS= read -r firmware_tags_name; do + firmware_tags_name="$(echo "${firmware_tags_name}" | sed 's/releases\/tag\///g')" + if [[ -n "${firmware_tags_name}" ]]; then + firmware_tags_array+=("${firmware_tags_name}") + fi + done < <( + curl -fsSL \ + https://github.com/${server_firmware_url}/releases?page=${i} | + grep -oE 'releases/tag/([^" ]+)' + ) + done - # Check if the response is empty or an error occurred - if [[ -z "${response}" ]] || [[ "${response}" == *"Not Found"* ]]; then - tolog "02.01 Invalid OpenWrt download address." "1" - else - # Filter the results and save them to the file - echo "${response}" | - jq '.[]' | - jq -s --arg RTK "${releases_tag_keywords}" '.[] | select(.tag_name | contains($RTK))' | - jq -s '.[].assets[] | {data:.updated_at, url:.browser_download_url}' | - jq -s --arg BOARD "_${BOARD}_" --arg MLV "${main_line_version}." --arg FSX "${firmware_suffix}" \ - '.[] | select((.url | contains($BOARD)) and (.url | contains($MLV)) and (.url | endswith($FSX)))' \ - >>${all_releases_list} - fi + if [[ "${#firmware_tags_array[*]}" -eq "0" ]]; then + tolog "02.01.01 Unable to retrieve a list of firmware tags." "1" + fi - # Check if the current page has fewer results than the per_page limit - if [[ "$(echo "${response}" | jq '. | length')" -lt "${github_per_page}" ]]; then + tolog "02.02 Search for tags containing the keyword..." + + # Search for tags containing the keyword + for i in "${firmware_tags_array[@]}"; do + if [[ "${i}" == *"${releases_tag_keywords}"* ]]; then + firmware_releases_tag="${i}" break - else - # Increase the page number - github_page="$((github_page + 1))" fi done - # Get the latest version - if [[ -s "${all_releases_list}" ]]; then - latest_version="$(cat ${all_releases_list} | jq -s 'sort_by(.data) | reverse | .[0]' -c)" - latest_updated_at="$(echo ${latest_version} | jq -r '.data')" - latest_url="$(echo ${latest_version} | jq -r '.url')" + if [[ -n "${firmware_releases_tag}" ]]; then + tolog "02.02.01 Tags: ${firmware_releases_tag}" + sleep 2 + else + tolog "02.02.01 No matching tags found." "1" + fi + tolog "02.03 Start searching for firmware download links..." + + # Retrieve the HTML code of the tags list page + html_code="$( + curl -fsSL \ + https://github.com/${server_firmware_url}/releases/expanded_assets/${firmware_releases_tag} + )" + + # Define regular expressions to match firmware download links and release dates + regex_href='href="([^"]+)"' + regex_datetime='datetime="([^"]+)"' + link_date_results=() + while [[ "${html_code}" =~ ${regex_href} ]]; do + href="${BASH_REMATCH[1]##*/}" + html_code="${html_code#*"${BASH_REMATCH[1]}"}" + if [[ "${html_code}" =~ $regex_datetime ]]; then + datetime="${BASH_REMATCH[1]}" + + # Search for firmware download links that meet the criteria + if [[ "${href}" =~ .*_${BOARD}_.*${main_line_version}\.[0-9]+.*${firmware_suffix} ]] && + [[ ! "${href}" =~ \.sha ]]; then + link_date_results+=("${href}@${datetime}") + fi + + fi + done + + if [[ "${#link_date_results[*]}" -eq "0" ]]; then + tolog "02.01 No matching download links found." "1" + fi + + # Get the latest version + latest_url_date="$(echo "${link_date_results[*]}" | tr ' ' '\n' | sort -urV | head -n 1)" + if [[ -n "${latest_url_date}" ]]; then + latest_url="$(echo "${latest_url_date}" | awk -F '@' '{print $1}')" + latest_updated_at="$(echo "${latest_url_date}" | awk -F '@' '{print $2}')" # Convert to readable date format date_display_format="$(echo ${latest_updated_at} | tr 'T' '(' | tr 'Z' ')')" else @@ -186,7 +214,7 @@ check_updated() { # Check the firmware update code down_check_code="${latest_updated_at}.${main_line_version}" op_release_code="${FIRMWARE_DOWNLOAD_PATH}/.luci-app-amlogic/op_release_code" - if [[ -f "${op_release_code}" ]]; then + if [[ -s "${op_release_code}" ]]; then update_check_code="$(cat ${op_release_code} | xargs)" if [[ -n "${update_check_code}" && "${update_check_code}" == "${down_check_code}" ]]; then tolog "02.02 Already the latest version, no need to update." "1" @@ -194,10 +222,10 @@ check_updated() { fi # Prompt to update - if [[ "${latest_url}" == "http"* ]]; then - tolog ' Latest updated: '${date_display_format}'' "1" + if [[ -n "${latest_url}" ]]; then + tolog ' Latest updated: '${date_display_format}'' "1" else - tolog "02.03 [${latest_url}] No OpenWrt available, please use another kernel branch." "1" + tolog "02.03 No OpenWrt available, please use another kernel branch." "1" fi exit 0 @@ -205,7 +233,7 @@ check_updated() { # 03. Download Openwrt firmware download_firmware() { - tolog "03. Download Openwrt firmware ..." + tolog "03. Download Openwrt firmware..." # Get the openwrt firmware download path if [[ "${download_version}" == "download_"* ]]; then @@ -228,7 +256,6 @@ download_firmware() { # Restore converted characters in file names(%2B to +) firmware_download_oldname="${opfile_path//%2B/+}" latest_url="https://github.com/${server_firmware_url}/releases/download/${firmware_download_oldname}" - #tolog "${latest_url}" # Download to OpenWrt file firmware_download_name="openwrt_${BOARD}_k${main_line_version}_github${firmware_suffix}" @@ -257,7 +284,6 @@ download_firmware() { tolog "You can update." - #echo 'Update' >$START_LOG tolog '' "1" exit 0