Update Script: 套件鎖定實作

This commit is contained in:
Yuan Chiu 2025-04-23 23:32:13 +08:00
parent e0312a002b
commit dd6ec8ea07

View File

@ -6,14 +6,32 @@
#!/usr/bin/env bash #!/usr/bin/env bash
wait_for_pacman_unlock() { wait_for_pacman_unlock() {
echo "檢查 pacman 鎖..." local LOCKFILE="/var/lib/pacman/db.lck"
while \ local MAX_IDLE=10 # 如果沒有 pacman process最多等這麼久再自動移除殘留
[ -e /var/lib/pacman/db.lck ] || \ local WAITED=0
pgrep -x pacman >/dev/null || \
pgrep -x packagekitd >/dev/null || \ echo "⏳ 檢查 pacman 鎖定中..."
pgrep -x packagekit >/dev/null; do
sleep 1 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 done
echo "✅ 鎖定解除,繼續執行。"
} }
pacmanForce_packages=( {{.packages.linux.manjaro.pacman_force | quoteList | join " " }}) pacmanForce_packages=( {{.packages.linux.manjaro.pacman_force | quoteList | join " " }})
@ -69,9 +87,6 @@ for package in "${aur_packages[@]}"; do
fi fi
done done
# 等待鎖定檔案被移除
wait_for_pacman_unlock
if [[ ${#to_install_aur[@]} -gt 0 ]]; then if [[ ${#to_install_aur[@]} -gt 0 ]]; then
echo " - Installing missing AUR packages via yay: ${to_install_aur[@]}" echo " - Installing missing AUR packages via yay: ${to_install_aur[@]}"
yay -S --noconfirm "${to_install_aur[@]}" yay -S --noconfirm "${to_install_aur[@]}"