From 910bc1643d883a15fc9cecc33f2c3e99c2c1eaa5 Mon Sep 17 00:00:00 2001 From: wukongdaily <2666180@gmail.com> Date: Sun, 7 Jun 2026 21:55:28 +0800 Subject: [PATCH] fix update --- apk-untrusted-toggle.sh | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/apk-untrusted-toggle.sh b/apk-untrusted-toggle.sh index 148608e..592ad32 100644 --- a/apk-untrusted-toggle.sh +++ b/apk-untrusted-toggle.sh @@ -1,24 +1,20 @@ #!/bin/sh -FILE="/usr/libexec/package-manager-call" -MARKER="# === AUTO ALLOW UNTRUSTED ===" +PKG_SCRIPT="/usr/libexec/package-manager-call" -if grep -q "$MARKER" "$FILE" 2>/dev/null; then - sed -i "/$MARKER/,+5d" "$FILE" - echo "✅ 已关闭!" -else - # 使用正则精准插入到 esac 之后、fi 之前 - sed -i '/^[[:space:]]*esac[[:space:]]*$/{ -n -/^[[:space:]]*fi[[:space:]]*$/!b -i\ - # === AUTO ALLOW UNTRUSTED ===\ - if [ "$action" = "add" ]; then\ - cmd="$cmd --allow-untrusted"\ - fi -}' "$FILE" - echo "✅ 已开启!" +# 检查文件是否存在 +if [ ! -f "$PKG_SCRIPT" ]; then + echo "错误:目标脚本 $PKG_SCRIPT 不存在!" + echo "请修改脚本里的 PKG_SCRIPT 变量为真实路径" + exit 1 fi -echo "当前状态:" -grep -A 12 "$MARKER" "$FILE" 2>/dev/null || echo "未开启" \ No newline at end of file +# 自动替换:add → add --allow-untrusted +sed -i 's/install) action="add" ;;$/install) action="add --allow-untrusted" ;;/' "$PKG_SCRIPT" + +# 验证是否成功 +if grep -q 'add --allow-untrusted' "$PKG_SCRIPT"; then + echo "✅ 成功!已自动在 apk add 后添加 --allow-untrusted 参数" +else + echo "❌ 失败!请检查原脚本格式" +fi \ No newline at end of file