123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- #!/usr/bin/env bash
- set -euo pipefail # bash strict mode
- display_help(){
- echo "Usage: ${0##*/} [OPTIONS] [PACKAGE(S)]"
- echo ""
- echo "Works with: pacman, apt, zypper, dnf"
- echo ""
- echo "OPTIONS:"
- echo " -u, --update Update packages"
- echo " -i, --install Install packages"
- echo " -r, --remove Remove packages"
- echo " -c, --clear-cache Clear package cache"
- echo " -s, --search Search for packages"
- echo " -l, --list List installed packages"
- echo " -d, --depends List package dependencies"
- echo " -h, --help Display this help message"
- echo ""
- exit 2
- }
- [[ $# -lt 1 ]] && display_help
- zypper_manager(){
- if [ -e /etc/os-release ]; then
- . /etc/os-release
- else
- . /usr/lib/os-release
- fi
- action="$1"
- shift
- case "${action,,}" in
- u | update) sudo zypper ref
- if [[ $ID = "opensuse-tumbleweed" ]]; then
- sudo zypper dup
- elif [[ $ID = "opensuse-leap" ]]; then
- sudo zypper up
- fi ;;
- i | install) sudo zypper in -- "$@";;
- r | remove) sudo zypper re -- "$@";;
- c | clear) zypper clean -a;;
- s | search) zypper se -- "$@";;
- l | list) zypper lp -- "$@";;
- d | depends) rpm -qR -- "$@";;
- h|\?|:|*) display_help ;;
- esac
- }
- apt_manager(){
- action="$1"
- shift
- case "${action,,}" in
- u | update) sudo apt update && sudo apt upgrade;;
- i | install) sudo apt install -- "$@";;
- r | remove) sudo apt autopurge -- "$@";;
- c | clear) sudo apt autoremove && sudo apt clean && sudo apt autoclean;;
- s | search) apt search -- "$@";;
- l | list) apt list -- "$@";;
- d | depends) apt-cache depends -- "$@";;
- h|\?|:|*) display_help ;;
- esac
- }
- pacman_manager(){
- action="$1"
- shift
- case "${action,,}" in
- u | update) sudo pacman -Syu --needed;;
- i | install) sudo pacman -Syu --needed -- "$@";;
- r | remove) sudo pacman -Rncssu -- "$@";;
- c | clear) sudo pacman -Scc;;
- s | search) pacman -Qs -- "$@";;
- l | list) pacman -Ss -- "$@";;
- d | depends) pacman -Q -- "$@";;
- h|\?|:|*) display_help ;;
- esac
- }
- dnf_manager(){
- action="$1"
- shift
- case "${action,,}" in
- u | update) sudo dnf upgrade --refresh;;
- i | install) sudo dnf install -- "$@";;
- r | remove) sudo dnf remove -- "$@";;
- c | clear) sudo dnf clean all;;
- s | search) dnf search all -- "$@";;
- l | list) dnf list -- "$@";;
- d | depends) rpm -qR -- "$@";;
- h|\?|:|*) display_help ;;
- esac
- }
- if command -v pacman; then
- pacman_manager "$@"
- elif command -v apt; then
- apt_manager "$@"
- elif command -v zypper; then
- zypper_manager "$@"
- elif command -v dnf; then
- dnf_manager "$@"
- else
- echo "package manager not supported!@!@!@"
- exit 2
- fi
|