2024-05-02 17:10:04 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
2024-05-10 18:53:16 +02:00
|
|
|
set -o nounset
|
|
|
|
|
set -o errexit
|
|
|
|
|
|
|
|
|
|
cpu="$(yaml2json < _machines/"$(hostname --short)".yml | jq --raw-output .cpu)"
|
|
|
|
|
gpu="$(yaml2json < _machines/"$(hostname --short)".yml | jq --raw-output .gpu)"
|
|
|
|
|
|
|
|
|
|
if [[ "${cpu}" ]] ; then
|
|
|
|
|
readarray -d $'\0' -t cpu_packages < <(<drivers.yml yaml2json | jq --raw-output0 ".cpu.${cpu}[]")
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ "${gpu}" ]] ; then
|
|
|
|
|
readarray -d $'\0' -t gpu_packages < <(<drivers.yml yaml2json | jq --raw-output0 ".gpu.${gpu}[]")
|
|
|
|
|
fi
|
|
|
|
|
|
2024-05-02 17:10:04 +02:00
|
|
|
declare -a aurdeps=()
|
|
|
|
|
|
|
|
|
|
proctected=(
|
2024-05-10 18:54:39 +02:00
|
|
|
base # virtual package, would not hurt, but it's weird if its not installed
|
2024-05-02 17:10:04 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
for pkgbuild in pkgbuilds/*/PKGBUILD ; do
|
2025-06-10 10:00:57 +02:00
|
|
|
set +o nounset
|
2024-05-15 13:38:28 +02:00
|
|
|
# shellcheck disable=SC1090
|
2024-05-02 17:10:04 +02:00
|
|
|
source "${pkgbuild}"
|
2025-06-10 10:00:57 +02:00
|
|
|
set -o nounset
|
2024-10-02 22:54:53 +02:00
|
|
|
aurdeps+=("${depends[@]%%[<=>]*}" "${makedepends[@]%%[<=>]*}" "${checkdepends[@]%%[<=>]*}" "${pkgname}")
|
2024-05-02 17:10:04 +02:00
|
|
|
done
|
|
|
|
|
|
2024-05-10 18:53:16 +02:00
|
|
|
declare -a packages_to_remove=()
|
2024-05-02 17:10:04 +02:00
|
|
|
|
|
|
|
|
readarray -d $'\0' -t packages_to_remove < <(comm --zero-terminated -13 \
|
|
|
|
|
<(cat \
|
2025-10-11 17:04:49 +02:00
|
|
|
<(<_machines/"$(hostname --short)".yml yaml2json | jq --raw-output0 '(.additional_packages // [])[]') \
|
2024-05-08 11:52:10 +02:00
|
|
|
<(<packages.yml yaml2json | jq --raw-output0 'map(.archlinux) | flatten[]') \
|
2024-05-10 18:53:16 +02:00
|
|
|
<(for dep in "${aurdeps[@]}" "${cpu_packages[@]}" "${gpu_packages[@]}" ; do printf '%s\0' "${dep}" ; done) \
|
2024-05-15 13:38:40 +02:00
|
|
|
| while IFS= read -r -d $'\0' package; do
|
|
|
|
|
set -o pipefail
|
|
|
|
|
if resolved_name=$(pacman -Qi "${package}" 2>/dev/null | grep ^Name | grep ^Name | cut -d ':' -f 2 | tr -d ' ') ; then
|
|
|
|
|
if [[ "${resolved_name}" != "${package}" ]] ; then
|
|
|
|
|
if pacman -Qq --explicit "${resolved_name}" >/dev/null ; then
|
|
|
|
|
printf '%s\0' "${resolved_name}"
|
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
printf '%s\0' "${package}"
|
|
|
|
|
done | sort -zu
|
|
|
|
|
) \
|
2024-05-02 17:10:04 +02:00
|
|
|
<(pacman -Qq --explicit | xargs -I "{}" printf '%s\0' "{}" | sort -zu) \
|
|
|
|
|
| while IFS= read -r -d $'\0' package; do
|
|
|
|
|
skip=0
|
|
|
|
|
for protected in "${proctected[@]}" ; do
|
|
|
|
|
if [[ "${package}" == "${protected}" ]] ; then
|
|
|
|
|
skip=1
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
if (( skip )) ; then
|
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
printf '%s\0' "${package}"
|
|
|
|
|
done)
|
|
|
|
|
|
2025-10-22 17:03:10 +02:00
|
|
|
packages_removed=0
|
|
|
|
|
|
2024-05-10 18:53:16 +02:00
|
|
|
if (( "${#packages_to_remove[@]}" > 0 )) ; then
|
2024-05-15 13:38:51 +02:00
|
|
|
echo "found the following explicitly installed packages that are not configured:"
|
|
|
|
|
for pkg in "${packages_to_remove[@]}" ; do
|
|
|
|
|
echo "${pkg}"
|
|
|
|
|
done
|
2024-05-06 11:18:56 +02:00
|
|
|
sudo pacman -Rcns "${packages_to_remove[@]}" "${@}" || exit $?
|
2025-10-22 17:03:10 +02:00
|
|
|
packages_removed=1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
readarray -t orphans < <(pacman -Qdtq)
|
|
|
|
|
|
|
|
|
|
if (( "${#orphans[@]}" > 0 )) ; then
|
|
|
|
|
echo "found the following orphaned packages:"
|
|
|
|
|
for pkg in "${orphans[@]}" ; do
|
|
|
|
|
echo "${pkg}"
|
|
|
|
|
done
|
|
|
|
|
sudo pacman -Rcns "${orphans[@]}" "${@}" || exit $?
|
|
|
|
|
packages_removed=1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if (( packages_removed)) ; then
|
2024-05-06 11:18:56 +02:00
|
|
|
exit 123
|
2024-05-03 14:41:09 +02:00
|
|
|
fi
|
2024-05-02 17:10:04 +02:00
|
|
|
|