Fix Script: 新增強迫一定要更新安裝部份套件,並增加偵測使用中鎖定功能

This commit is contained in:
Yuan Chiu 2025-04-23 23:10:27 +08:00
parent 385913bb7d
commit 0bf677bf3f
2 changed files with 22 additions and 10 deletions

View File

@ -23,7 +23,7 @@ casks = [
] ]
[packages.linux.manjaro] [packages.linux.manjaro]
pacman_first = [ pacman_force = [
'archlinux-keyring', 'archlinux-keyring',
'libpamac', 'libpamac',
'llvm', 'llvm',

View File

@ -5,7 +5,9 @@
{{- /* https://github.com/mriehl/dotfiles/blob/master/run_onchange_packages.sh.tmpl */ -}} {{- /* https://github.com/mriehl/dotfiles/blob/master/run_onchange_packages.sh.tmpl */ -}}
#!/usr/bin/env bash #!/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 " " }}) pacman_packages=( {{.packages.linux.manjaro.pacman | quoteList | join " " }})
aur_packages=( {{.packages.linux.manjaro.aur | quoteList | join " " }}) aur_packages=( {{.packages.linux.manjaro.aur | quoteList | join " " }})
@ -15,18 +17,28 @@ is_installed() {
[[ " ${installed_packages[*]} " =~ " $1 " ]] [[ " ${installed_packages[*]} " =~ " $1 " ]]
} }
to_install_pacmanFirst=() to_install_pacmanForce=()
for package in "${pacmanFirst_packages[@]}"; do for package in "${pacmanForce_packages[@]}"; do
if ! is_installed "$package"; then to_install_pacmanForce+=("$package")
to_install_pacmanFirst+=("$package")
fi
done done
if [[ ${#to_install_pacmanFirst[@]} -gt 0 ]]; then # 等待鎖定檔案被移除
echo " - Installing missing packages via pacman: ${to_install_pacmanFirst[@]}" echo "等待 pacman 鎖定檔案被移除..."
sudo pacman -S --needed --noconfirm "${to_install_pacmanFirst[@]}" 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 fi
# 等待鎖定檔案被移除
echo "等待 pacman 鎖定檔案被移除..."
while [ -e "$LOCKFILE" ]; do
sleep 1
done
to_install_pacman=() to_install_pacman=()
for package in "${pacman_packages[@]}"; do for package in "${pacman_packages[@]}"; do
if ! is_installed "$package"; then if ! is_installed "$package"; then