From 0bf677bf3fd8e61511bbc6a8843f42c94fda4847 Mon Sep 17 00:00:00 2001 From: Yuan Chiu Date: Wed, 23 Apr 2025 23:10:27 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20Script:=20=E6=96=B0=E5=A2=9E=E5=BC=B7?= =?UTF-8?q?=E8=BF=AB=E4=B8=80=E5=AE=9A=E8=A6=81=E6=9B=B4=E6=96=B0=E5=AE=89?= =?UTF-8?q?=E8=A3=9D=E9=83=A8=E4=BB=BD=E5=A5=97=E4=BB=B6=EF=BC=8C=E4=B8=A6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=81=B5=E6=B8=AC=E4=BD=BF=E7=94=A8=E4=B8=AD?= =?UTF-8?q?=E9=8E=96=E5=AE=9A=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .chezmoidata/packages.toml | 2 +- ...ange_before_linux-install-packages.sh.tmpl | 30 +++++++++++++------ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/.chezmoidata/packages.toml b/.chezmoidata/packages.toml index 22236f1..69d7bcf 100644 --- a/.chezmoidata/packages.toml +++ b/.chezmoidata/packages.toml @@ -23,7 +23,7 @@ casks = [ ] [packages.linux.manjaro] -pacman_first = [ +pacman_force = [ 'archlinux-keyring', 'libpamac', 'llvm', diff --git a/.chezmoiscripts/run_onchange_before_linux-install-packages.sh.tmpl b/.chezmoiscripts/run_onchange_before_linux-install-packages.sh.tmpl index 8f7765f..56f7253 100644 --- a/.chezmoiscripts/run_onchange_before_linux-install-packages.sh.tmpl +++ b/.chezmoiscripts/run_onchange_before_linux-install-packages.sh.tmpl @@ -5,7 +5,9 @@ {{- /* https://github.com/mriehl/dotfiles/blob/master/run_onchange_packages.sh.tmpl */ -}} #!/usr/bin/env bash -pacmanFirst_packages=( {{.packages.linux.manjaro.pacman_first | quoteList | join " " }}) +LOCKFILE="/var/lib/pacman/db.lck" + +pacmanForce_packages=( {{.packages.linux.manjaro.pacman_force | quoteList | join " " }}) pacman_packages=( {{.packages.linux.manjaro.pacman | quoteList | join " " }}) aur_packages=( {{.packages.linux.manjaro.aur | quoteList | join " " }}) @@ -15,18 +17,28 @@ is_installed() { [[ " ${installed_packages[*]} " =~ " $1 " ]] } -to_install_pacmanFirst=() -for package in "${pacmanFirst_packages[@]}"; do - if ! is_installed "$package"; then - to_install_pacmanFirst+=("$package") - fi +to_install_pacmanForce=() +for package in "${pacmanForce_packages[@]}"; do + to_install_pacmanForce+=("$package") done -if [[ ${#to_install_pacmanFirst[@]} -gt 0 ]]; then - echo " - Installing missing packages via pacman: ${to_install_pacmanFirst[@]}" - sudo pacman -S --needed --noconfirm "${to_install_pacmanFirst[@]}" +# 等待鎖定檔案被移除 +echo "等待 pacman 鎖定檔案被移除..." +while [ -e "$LOCKFILE" ]; do + sleep 1 +done + +if [[ ${#to_install_pacmanForce[@]} -gt 0 ]]; then + echo " - Installing missing packages via pacman: ${to_install_pacmanForce[@]}" + sudo pacman -S --needed --noconfirm "${to_install_pacmanForce[@]}" fi +# 等待鎖定檔案被移除 +echo "等待 pacman 鎖定檔案被移除..." +while [ -e "$LOCKFILE" ]; do + sleep 1 +done + to_install_pacman=() for package in "${pacman_packages[@]}"; do if ! is_installed "$package"; then