add zypper_autoremove.bash
This commit is contained in:
parent
66c860bcc5
commit
0220cccb29
1 changed files with 21 additions and 0 deletions
21
zypper_autoremove.bash
Executable file
21
zypper_autoremove.bash
Executable file
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Script that imitates `apt autoremove` for zypper as there is no native solution.
|
||||
|
||||
package_list=$(sudo zypper packages --unneeded)
|
||||
table_start=$(echo "$package_list" | grep -n "S | Repository | Name"| gawk '{print $1}' FS=":")
|
||||
|
||||
unneeded_packages=()
|
||||
while IFS= read -r package; do
|
||||
package="$(echo "$package"| awk -F '|' '{ print $3 }' | xargs)"
|
||||
unneeded_packages+=("$package")
|
||||
done < <(echo "$package_list" | tail -n+$((table_start+2)))
|
||||
|
||||
unneeded_package_list=$(printf '%s ' "${unneeded_packages[@]}")
|
||||
|
||||
if [ "$unneeded_package_list" = " " ]; then
|
||||
sudo zypper rm -u $unneeded_package_list
|
||||
else
|
||||
echo "No unneeded packages."
|
||||
fi
|
||||
|
Loading…
Reference in a new issue