mirror of
https://gitlab.com/JKANetwork/jka-toolkit.git
synced 2026-02-17 10:31:30 +01:00
323 lines
8.4 KiB
Bash
Executable File
323 lines
8.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# apw, a simple packager wrapper for Arch, Debian, RedHat/Fedora, CentOS 6, Suse, Void, and more)
|
|
# It simplifies the process of remembering pacman,apt,dnf, etc , all in one called apw
|
|
# Author: JKA Network - contacto@jkanetwork.com
|
|
|
|
# $1 is the command
|
|
# $2,$3.. will be $packages
|
|
|
|
# gettext initialization
|
|
export TEXTDOMAIN='apw'
|
|
export TEXTDOMAINDIR='/usr/share/locale'
|
|
#Version variable
|
|
version="1.8.1"
|
|
|
|
#This option is for make if case insensitive
|
|
shopt -s nocasematch
|
|
|
|
#Basic info echo
|
|
case "$1" in
|
|
h|-h)
|
|
printf -- "$(gettext "apw - A Packager Wrapper, a Idea from JKA Network, version %s")" "$version"
|
|
echo
|
|
echo "$(gettext " Usage: apw <option> [packages]")"
|
|
echo "$(gettext " {-h | h} Show this help")"
|
|
echo "$(gettext " {-U | U} Update system. If errors, you can do -Uf to force it")"
|
|
echo "$(gettext " {-I | I} Install packages (Updates system also for preventing problems)")"
|
|
echo "$(gettext " {-Ir | Ir} Reinstall packages (Updates system also for preventing problems)")"
|
|
echo "$(gettext " {-R | R} Removes a package")"
|
|
echo "$(gettext " {-Rd | Rd} Removes a package along with dependencies that are not more in use (Only for Arch)")"
|
|
echo "$(gettext " {-C | C} Clean temp files")"
|
|
echo "$(gettext " {-Cd | Cd} Clean system from dependencies that are not in use (ADVANCED, BE CAREFUL!)")"
|
|
echo "$(gettext " {-S | S} Search in package database")"
|
|
echo "$(gettext " {-F | F} Install file (distro family dependent, e.g. .deb , .pkg.tar.xz,...)")"
|
|
echo "$(gettext " Append y to -U or -I (-Uy -Iy -Iry) for autoconfirm the operations")"
|
|
exit
|
|
;;
|
|
"")
|
|
echo "$(gettext "apw - A Packager Wrapper")"
|
|
echo "$(gettext "Use apw -h for help")"
|
|
exit
|
|
;;
|
|
esac
|
|
|
|
#Force sudo
|
|
uid=$(/usr/bin/id -u)
|
|
if [[ $uid != "0" ]];then
|
|
echo "$(gettext "apw has to run as root, please run as root/with sudo")"
|
|
exit
|
|
fi
|
|
|
|
if [[ ! -f /etc/apw.conf ]];then
|
|
echo "$(gettext "It's the first run of the program, we need a thing before continue")"
|
|
echo "$(gettext "What, or in what is based your Linux?")"
|
|
echo "$(gettext "(The answer will be recorded in /etc/apw.conf, if you want to reset apw, delete this file)")"
|
|
options=("Debian/Ubuntu (apt)" "Fedora/Redhat (dnf)" "CentOS 6 (yum)" "Archlinux (pacman)" "Suse (zypper)" "Void Linux (XBPS)")
|
|
select opt in "${options[@]}"
|
|
do
|
|
case $opt in
|
|
"Debian/Ubuntu (apt)")
|
|
echo "apt" > /etc/apw.conf
|
|
break
|
|
;;
|
|
"Fedora/Redhat (dnf)")
|
|
echo "dnf" > /etc/apw.conf
|
|
break
|
|
;;
|
|
"CentOS 6 (yum)")
|
|
echo "yum" > /etc/apw.conf
|
|
break
|
|
;;
|
|
"Archlinux (pacman)")
|
|
echo "pacman" > /etc/apw.conf
|
|
break
|
|
;;
|
|
"Suse (zypper)")
|
|
echo "zypper" > /etc/apw.conf
|
|
break
|
|
;;
|
|
"Void Linux (XBPS)")
|
|
echo "xbps" > /etc/apw.conf
|
|
break
|
|
;;
|
|
esac
|
|
done
|
|
fi
|
|
|
|
SO=$(cat /etc/apw.conf)
|
|
|
|
#Reading packages to install/remove.. (The rest of $) , it has to be done before the option echo, logically
|
|
packages=$2
|
|
#Control the incompleted arguments
|
|
if [[ -z $packages && ( $1 != *u* && $1 != *c* ) ]];then
|
|
echo "$(gettext "No package specified, aborting")"
|
|
exit
|
|
fi
|
|
for (( i=3; i<=$#; i++ ))
|
|
do
|
|
packages="$packages $(echo $* | cut -f$i -d" ")"
|
|
done
|
|
|
|
#Check if is dnf in RedHat, or apt in Debian, new tools
|
|
if [[ $SO = "dnf" && ! -f /usr/bin/dnf ]];then
|
|
yum install dnf
|
|
fi
|
|
if [[ $SO = "apt" && ! -f /usr/bin/apt ]];then
|
|
apt-get update && apt-get install apt
|
|
fi
|
|
|
|
#Command wrapper
|
|
updating="$(gettext "Updating system")"
|
|
case "$1" in
|
|
U|-U)
|
|
echo $updating
|
|
case "$SO" in
|
|
apt)
|
|
apt update && apt upgrade;;
|
|
pacman)
|
|
pacman -Syu $packages;;
|
|
yum | dnf | zypper)
|
|
$SO update;;
|
|
xbps)
|
|
xbps-install -Su;;
|
|
esac;;
|
|
Uf|-Uf)
|
|
echo $(gettext "Force updating system")
|
|
case "$SO" in
|
|
apt)
|
|
apt update && apt upgrade -f;;
|
|
pacman)
|
|
pacman -Syu $packages --force;;
|
|
yum | dnf | zypper)
|
|
echo "$(gettext "Not supported on your distribution. Doing -U instead")"
|
|
$SO update;;
|
|
xbps)
|
|
echo "$(gettext "Not supported on your distribution. Doing -U instead")"
|
|
xbps-install -Su;;
|
|
esac;;
|
|
Uy|-Uy)
|
|
echo $updating
|
|
case "$SO" in
|
|
apt)
|
|
apt update && apt -y upgrade;;
|
|
pacman)
|
|
pacman -Syu $packages --noconfirm;;
|
|
yum | dnf)
|
|
$SO -y update;;
|
|
zypper)
|
|
$SO --non-interactive update;;
|
|
xbps)
|
|
echo "$(gettext "Not supported on your distribution. Doing -U instead")"
|
|
xbps-install -Su;;
|
|
esac;;
|
|
I|-I)
|
|
printf -- "$(gettext "You are going to install %s and dependencies")" "$packages"
|
|
echo
|
|
case "$SO" in
|
|
apt)
|
|
apt update && apt install $packages;;
|
|
pacman)
|
|
pacman -Syu $packages --needed;;
|
|
yum | dnf | zypper)
|
|
$SO install $packages;;
|
|
xbps)
|
|
xbps-install -S $packages;;
|
|
esac;;
|
|
Iy|-Iy)
|
|
printf -- "$(gettext "You are going to install %s and dependencies")" "$packages"
|
|
echo
|
|
case "$SO" in
|
|
apt)
|
|
apt update && apt -y install $packages;;
|
|
pacman)
|
|
pacman -Syu $packages --noconfirm --needed;;
|
|
yum | dnf)
|
|
$SO -y install $packages;;
|
|
zypper)
|
|
$SO --non-interactive install $packages;;
|
|
xbps)
|
|
echo "$(gettext "Not supported on your distribution. Doing -I instead")"
|
|
xbps-install -S $packages;;
|
|
esac;;
|
|
Ir|-Ir)
|
|
printf -- "$(gettext "You are going to reinstall %s")" "$packages"
|
|
echo
|
|
case "$SO" in
|
|
apt)
|
|
apt update && apt install --reinstall $packages;;
|
|
pacman)
|
|
pacman -Syu $packages;;
|
|
yum | dnf | zypper)
|
|
$SO reinstall $packages;;
|
|
xbps)
|
|
echo "$(gettext "Not supported on your distribution. Reconfiguring instead")"
|
|
xbps-reconfigure -f $packages
|
|
esac;;
|
|
Iry|-Iry)
|
|
printf -- "$(gettext "You are going to reinstall %s")" "$packages"
|
|
case "$SO" in
|
|
apt)
|
|
apt update && apt -y install --reinstall $packages;;
|
|
pacman)
|
|
pacman -Syu $packages --noconfirm;;
|
|
yum | dnf)
|
|
$SO -y reinstall $packages;;
|
|
zypper)
|
|
$SO --non-interactive reinstall $packages;;
|
|
xbps)
|
|
echo "$(gettext "Not supported on your distribution. Reconfiguring instead")"
|
|
xbps-reconfigure -f $packages
|
|
esac;;
|
|
R|-R)
|
|
printf -- "$(gettext "You are going to remove %s")" "$packages"
|
|
case "$SO" in
|
|
apt)
|
|
apt remove $packages;;
|
|
pacman)
|
|
pacman -R $packages;;
|
|
yum | dnf | zypper)
|
|
$SO remove $packages;;
|
|
xbps)
|
|
xbps-remove $packages;;
|
|
esac;;
|
|
Ry|-Ry)
|
|
printf -- "$(gettext "You are going to remove %s")" "$packages"
|
|
case "$SO" in
|
|
apt)
|
|
apt -y remove $packages;;
|
|
pacman)
|
|
pacman -R $packages --noconfirm;;
|
|
yum | dnf)
|
|
$SO -y remove $packages;;
|
|
zypper)
|
|
$SO --non-interactive remove $packages;;
|
|
xbps)
|
|
echo "$(gettext "Not supported on your distribution. Doing -I instead")"
|
|
xbps-remove $packages;;
|
|
esac;;
|
|
Rd|-Rd)
|
|
printf -- "$(gettext "Removing %s along with his dependencies that are not more in use")" "$packages"
|
|
echo
|
|
case "$SO" in
|
|
pacman)
|
|
pacman -Rs $packages;;
|
|
xbps)
|
|
xbps-remove -R $packages;;
|
|
*)
|
|
echo "$(gettext "Not supported on your distribution")";;
|
|
esac;;
|
|
Rdy|-Rdy)
|
|
printf -- "$(gettext "Removing %s along with his dependencies that are not more in use")" "$packages"
|
|
echo
|
|
case "$SO" in
|
|
pacman)
|
|
pacman -Rs $packages --noconfirm;;
|
|
xbps)
|
|
echo "$(gettext "Not supported on your distribution. Doing -Rd instead")"
|
|
xbps-remove -R $packages;;
|
|
*)
|
|
echo "$(gettext "Not supported on your distribution")";;
|
|
esac;;
|
|
C|-C)
|
|
echo "$(gettext "Cleaning package manager")"
|
|
case "$SO" in
|
|
apt)
|
|
apt clean
|
|
apt autoclean
|
|
#apt autoremove
|
|
;;
|
|
pacman)
|
|
pacman -Scc;;
|
|
yum)
|
|
yum clean all;;
|
|
dnf)
|
|
dnf clean all --enablerepo=\*;;
|
|
zypper)
|
|
zypper clean;;
|
|
xbps)
|
|
xbps-remove -O;;
|
|
esac;;
|
|
Cd|-Cd)
|
|
echo "$(gettext "Cleaning system from dependencies that are not in use (BE CAREFUL, ONLY ADVANCED)")"
|
|
case "$SO" in
|
|
apt)
|
|
apt autoremove --purge;;
|
|
pacman)
|
|
pacman -Rs $(pacman -Qdtq);;
|
|
zypper)
|
|
zypper --clean-deps;;
|
|
xbps)
|
|
xbps-remove -o;;
|
|
*)
|
|
echo "$(gettext "Not supported on your distribution")";;
|
|
esac;;
|
|
S|-S)
|
|
printf -- "$(gettext "Searching %s")" "$packages"
|
|
echo
|
|
case "$SO" in
|
|
pacman)
|
|
pacman -Ss $packages;;
|
|
apr | yum | dnf | zypper)
|
|
$SO search $packages;;
|
|
xbps)
|
|
xbps-query $packages;;
|
|
esac;;
|
|
F|-F)
|
|
printf -- "$(gettext "Installing files: %s")" "$packages"
|
|
echo
|
|
case "$SO" in
|
|
apt)
|
|
dpkg -I $packages;;
|
|
pacman)
|
|
pacman -U $packages;;
|
|
yum | dnf | zypper)
|
|
rpm -Uvh $packages;;
|
|
xbps)
|
|
echo "$(gettext "Not supported on your distribution")";;
|
|
esac;;
|
|
*)
|
|
echo "$(gettext "Invalid option especified")"
|
|
echo "$(gettext "Use apw -h for help")"
|
|
exit;;
|
|
esac
|