2024-05-03 21:10:21 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Script that imitates `apt autoremove` for zypper as there is no native solution.
|
|
|
|
|
2024-05-05 14:00:16 +02:00
|
|
|
package_list=$(LC_ALL=C sudo zypper packages --unneeded)
|
2024-05-03 21:10:21 +02:00
|
|
|
table_start=$(echo "$package_list" | grep -n "S | Repository | Name"| gawk '{print $1}' FS=":")
|
|
|
|
|
|
|
|
unneeded_packages=()
|
|
|
|
while IFS= read -r package; do
|
2024-05-10 13:15:31 +02:00
|
|
|
package="$(echo "$package"| awk -F '|' '{ print $3 }' | xargs -r)"
|
2024-05-03 21:10:21 +02:00
|
|
|
unneeded_packages+=("$package")
|
|
|
|
done < <(echo "$package_list" | tail -n+$((table_start+2)))
|
|
|
|
|
|
|
|
unneeded_package_list=$(printf '%s ' "${unneeded_packages[@]}")
|
|
|
|
|
2024-05-14 10:58:26 +02:00
|
|
|
if [ -n "$(echo "$unneeded_package_list" | tr -d ' ')" ]; then
|
|
|
|
# shellcheck disable=SC2086
|
2024-05-03 21:10:21 +02:00
|
|
|
sudo zypper rm -u $unneeded_package_list
|
|
|
|
else
|
|
|
|
echo "No unneeded packages."
|
|
|
|
fi
|
|
|
|
|