From 56afd639a492a911765caed7ce145c18ed300f46 Mon Sep 17 00:00:00 2001 From: KOWX712 Date: Sun, 18 May 2025 21:14:30 +0800 Subject: [PATCH] fix: unable to fetch security patch x2 #42 --- module/common/get_extra.sh | 13 +++++++++++-- module/webui/locales/strings/en.xml | 1 + module/webui/locales/strings/zh-CN.xml | 1 + module/webui/locales/strings/zh-TW.xml | 1 + module/webui/scripts/security_patch.js | 9 ++++++++- 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/module/common/get_extra.sh b/module/common/get_extra.sh index 8e1b3a1..baa9ade 100644 --- a/module/common/get_extra.sh +++ b/module/common/get_extra.sh @@ -136,8 +136,17 @@ set_security_patch() { } get_latest_security_patch() { - security_patch=$(download "https://source.android.com/docs/security/bulletin/pixel" | grep -o "[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}" | head -n 1 | sed 's/\(.*\)<\/td>/\1/') - [ -n "$security_patch" ] && echo "$security_patch" || exit 1 + security_patch=$(download "https://source.android.com/docs/security/bulletin/pixel" | + sed -n 's/.*\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\)<\/td>.*/\1/p' | + head -n 1) + + if [ -n "$security_patch" ]; then + echo "$security_patch" + exit 0 + elif ! ping -c 1 -W 5 "source.android.com" >/dev/null 2>&1; then + echo "Connection failed" >&2 + fi + exit 1 } unknown_kb() { diff --git a/module/webui/locales/strings/en.xml b/module/webui/locales/strings/en.xml index 36ec45f..8a2c616 100644 --- a/module/webui/locales/strings/en.xml +++ b/module/webui/locales/strings/en.xml @@ -113,6 +113,7 @@ Fetching... Done Failed to fetch security patch date + Unable to connect to source.android.com Auto config enabled successfully Failed to enable auto config Security patch saved successfully diff --git a/module/webui/locales/strings/zh-CN.xml b/module/webui/locales/strings/zh-CN.xml index 1cd017f..8d5a836 100644 --- a/module/webui/locales/strings/zh-CN.xml +++ b/module/webui/locales/strings/zh-CN.xml @@ -113,6 +113,7 @@ 获取中... 完成 获取安全补丁日期失败 + 无法连接至 source.android.com 自动配置成功启用 无法启用自动配置 安全补丁成功保存 diff --git a/module/webui/locales/strings/zh-TW.xml b/module/webui/locales/strings/zh-TW.xml index f51012b..452e010 100644 --- a/module/webui/locales/strings/zh-TW.xml +++ b/module/webui/locales/strings/zh-TW.xml @@ -113,6 +113,7 @@ 獲取中... 完成 獲取安全補丁日期失敗 + 無法連線至 source.android.com 自動配置成功啟用 無法啟用自動配置 安全補丁成功保存 diff --git a/module/webui/scripts/security_patch.js b/module/webui/scripts/security_patch.js index 20dc4a7..a4c3fc1 100644 --- a/module/webui/scripts/security_patch.js +++ b/module/webui/scripts/security_patch.js @@ -314,7 +314,7 @@ export function securityPatch() { getButton.addEventListener('click', async () => { showPrompt('security_patch_fetching'); const output = spawn('sh', [`${basePath}/common/get_extra.sh`, '--get-security-patch'], - { env: { PATH: "/data/adb/ap/bin:/data/adb/ksu/bin:/data/adb/magisk:/data/data/com.termux/files/usr/bin:$PATH" }}); + { cwd: "/data/local/tmp", env: { PATH: "/data/adb/ap/bin:/data/adb/ksu/bin:/data/adb/magisk:/data/data/com.termux/files/usr/bin:$PATH" }}); output.stdout.on('data', (data) => { showPrompt('security_patch_fetched', true, 1000); checkAdvanced(true); @@ -324,6 +324,13 @@ export function securityPatch() { bootPatchInput.value = data; vendorPatchInput.value = data; }); + output.stderr.on('data', (data) => { + if (data.includes("failed")) { + showPrompt('security_patch_unable_to_connect', false); + } else { + console.error(data); + } + }); output.on('exit', (code) => { if (code !== 0) showPrompt('security_patch_get_failed', false); });