From dd6ec8ea07c108d9f8552c1835ec660324af11e5 Mon Sep 17 00:00:00 2001 From: Yuan Chiu Date: Wed, 23 Apr 2025 23:32:13 +0800 Subject: [PATCH] =?UTF-8?q?Update=20Script:=20=E5=A5=97=E4=BB=B6=E9=8E=96?= =?UTF-8?q?=E5=AE=9A=E5=AF=A6=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ange_before_linux-install-packages.sh.tmpl | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/.chezmoiscripts/run_onchange_before_linux-install-packages.sh.tmpl b/.chezmoiscripts/run_onchange_before_linux-install-packages.sh.tmpl index 25560d5..04c8f75 100644 --- a/.chezmoiscripts/run_onchange_before_linux-install-packages.sh.tmpl +++ b/.chezmoiscripts/run_onchange_before_linux-install-packages.sh.tmpl @@ -6,14 +6,32 @@ #!/usr/bin/env bash wait_for_pacman_unlock() { - echo "檢查 pacman 鎖..." - while \ - [ -e /var/lib/pacman/db.lck ] || \ - pgrep -x pacman >/dev/null || \ - pgrep -x packagekitd >/dev/null || \ - pgrep -x packagekit >/dev/null; do - sleep 1 + local LOCKFILE="/var/lib/pacman/db.lck" + local MAX_IDLE=10 # 如果沒有 pacman process,最多等這麼久再自動移除殘留 + local WAITED=0 + + echo "⏳ 檢查 pacman 鎖定中..." + + while [ -e "$LOCKFILE" ]; do + if ! pgrep -x pacman >/dev/null && \ + ! pgrep -x packagekitd >/dev/null && \ + ! pgrep -x packagekit >/dev/null; then + + echo "🔍 找不到 pacman 或 PackageKit,疑似殘留鎖檔。" + + if [ "$WAITED" -ge "$MAX_IDLE" ]; then + echo "🧹 自動移除殘留鎖檔(已閒置 $MAX_IDLE 秒)" + sudo rm -f "$LOCKFILE" + break + fi + + WAITED=$((WAITED + 1)) + fi + + sleep 1 done + + echo "✅ 鎖定解除,繼續執行。" } pacmanForce_packages=( {{.packages.linux.manjaro.pacman_force | quoteList | join " " }}) @@ -69,9 +87,6 @@ for package in "${aur_packages[@]}"; do fi done -# 等待鎖定檔案被移除 -wait_for_pacman_unlock - if [[ ${#to_install_aur[@]} -gt 0 ]]; then echo " - Installing missing AUR packages via yay: ${to_install_aur[@]}" yay -S --noconfirm "${to_install_aur[@]}"