├── README.md ├── LICENSE └── zypptools /README.md: -------------------------------------------------------------------------------- 1 | # zypptools 2 | Missing commands for the openSUSE's zypper package manager. 3 | 4 | ### Available commands: 5 | 6 | `zypptools userinstalled` - list all packages that were manually installed by the user 7 | 8 | `zypptools autoremove` - find and remove unneeded dependencies 9 | 10 | `zypptools why ` - list all installed packages that require or recommend the specified package 11 | 12 | `zypptools ban ` - uninstall the package including its dependencies and prevent reinstallation (as a dependency of another package or pattern) 13 | 14 | ### How to install 15 | 16 | `curl -s -o ~/bin/zypptools https://raw.githubusercontent.com/eylenburg/zypptools/main/zypptools && chmod +x ~/bin/zypptools` 17 | 18 | Now you can run `zypptools` in your terminal. 19 | 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 eylenburg 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /zypptools: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # MIT license 3 | # github.com/eylenburg/zypptools 4 | 5 | function autoremove() { 6 | echo -e "The packages listed below are unneeded as they were installed as dependencies of now removed packages:" 7 | 8 | # List all unneeded packages 9 | unneeded=$(zypper packages --unneeded | awk -F'|' 'NR==0 || NR==1 || NR==2 || NR==3 || NR==4 {next} {print $3}' | grep -v Name) 10 | echo -e "\e[31m$unneeded\e[0m\n" 11 | 12 | # Check if there is anything to remove 13 | if [ -z "$unneeded" ] 14 | then 15 | echo "No packages to remove" 16 | else 17 | 18 | # Ask to remove unneeded packages 19 | while true; do 20 | read -p "Do you want to remove these packages including their dependencies? [y/n] " yn 21 | case $yn in 22 | [Yy]* ) sudo zypper remove --clean-deps $unneeded && break;; 23 | [Nn]* ) exit;; 24 | * ) echo "Please answer yes or no.";; 25 | esac 26 | done 27 | fi 28 | } 29 | 30 | 31 | function userinstalled() { 32 | # Make the zypper history file available to the user 33 | sudo cat /var/log/zypp/history > /tmp/history 34 | 35 | # Read list of all packages installed by the user 36 | command_output=$(grep '|root@'`hostname` /tmp/history | grep '|install|' | sort -r | cut -d'|' -f3) 37 | 38 | echo -e "The packages listed below were manually installed by a user. This list does not include preinstalled packages or packages that were installed as dependencies or recommendations. If you want to remove a package including its dependencies, you can use the command \033[3msudo zypper remove --clean-deps \033[0m\n" 39 | 40 | # Compare the above list to the list of currently installed packages 41 | comm -12 <(echo "$command_output" | sort) <(echo "$command_output" | xargs zypper search -i | grep "^i" | awk '{print $3}' | sort) 42 | 43 | # Remove the temporary file 44 | rm /tmp/history 45 | } 46 | 47 | package=$2 48 | function why() { 49 | if [ -z "$package" ] 50 | then 51 | echo "Please specify a package name: zypptools why " 52 | else 53 | echo "Showing all currently installed packages that require or recommend the specified package:" 54 | zypper search --recommends --requires $package | grep -E '^i' 55 | fi 56 | } 57 | 58 | 59 | function ban() { 60 | if [ -z "$package" ] 61 | then 62 | echo "Please specify a package name: zypptools why " 63 | else 64 | # Remove package and set as taboo 65 | sudo zypper remove --clean-deps $package && sudo zypper addlock $package 66 | fi 67 | } 68 | 69 | 70 | if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then 71 | case $1 in 72 | "userinstalled") 73 | userinstalled 74 | ;; 75 | "autoremove") 76 | autoremove 77 | ;; 78 | "why") 79 | why 80 | ;; 81 | "ban") 82 | ban 83 | ;; 84 | *) 85 | echo -e "Invalid function name. Please specify a valid function to run:\n\033[4mzypptools userinstalled\033[0m - list all packages that were manually installed by the user\n\033[4mzypptools autoremove\033[0m - find and remove unneeded dependencies\n\033[4mzypptools why package\033[0m - list all installed packages that require or recommend the specified package\n\033[4mzypptools ban package\033[0m - uninstall the package including its dependencies and prevent reinstallation (as a dependency of another package or pattern)\n\033[3mzypptools v1.1\033[0m" 86 | ;; 87 | esac 88 | fi 89 | --------------------------------------------------------------------------------