1
0
mirror of https://gitlab.com/JKANetwork/jka-toolkit.git synced 2026-02-21 20:33:48 +01:00
Files
jka-toolkit/jka-toolkit/apw
2016-05-25 11:54:22 +02:00

154 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
# apw, a simple packager wrapper for Arch, Debian, RedHat/Fedora, CentOS 6, Suse, and all his derivates)
# 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
#Force sudo
uid=$(/usr/bin/id -u)
if [[ $uid != "0" ]];then
echo "apw has to run as root, please run as root/with sudo"
exit
fi
if [[ ! -f /etc/apw.conf ]];then
echo "It's the first run of the program, we need a thing before continue"
echo "What, or in what is based your Linux?"
echo "(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)")
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
;;
esac
done
fi
SO=$(cat /etc/apw.conf)
#This option is for make if case insensitive
shopt -s nocasematch
#Reading packages to install/remove.. (The rest of $) , it has to be done before the option echo, logically
packages=$2
for (( i=3; i<=$#; i++ ))
do
valtmp=$(echo $* | cut -f$i -d" ")
packages="$packages $valtmp"
done
#echo for every option
case "$1" in
*h*)
echo "apw - A Packager Wrapper, a Idea from JKA Network, version 1.3"
echo " Usage: apw <option> [packages]"
echo " {-h | h} Show this help"
echo " {-U | U} Update system"
echo " {-I | I} Install packages (Updates system also for preventing problems"
echo " {-R | R} Removes a package"
echo " {-S | S} Search in package database"
echo " {-F | F} Install file (distro family dependent, e.g. .deb , .pkg.tar.xz,...)"
exit
;;
*U*)
echo "Updating system";;
*I*)
echo "You are going to install $packages and dependencies";;
*R*)
echo "You are going to remove $packages";;
*S*)
echo "Searching $packages";;
*F*)
echo "Installing files: $packages";;
"")
echo "apw - A Packager Wrapper"
echo "Use apw -h for help"
exit
;;
*)
echo "Invalid option especified"
echo "Use apw -h for help"
exit
;;
esac
#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
if [[ $SO = "apt" ]];then
case "$1" in
*U*)
apt update
apt upgrade
;;
*I*)
apt update
apt install $packages
;;
*R*)
apt remove $packages;;
*S*)
apt search $packages;;
*F*)
dpkg -I $packages;;
esac
fi
if [[ $SO = "pacman" ]];then
case "$1" in
*U*)
pacman -Syu;;
*I*)
pacman -Syu $packages;;
*R*)
pacman -R $packages;;
*S*)
pacman -Ss $packages;;
*F*)
pacman -U $packages;;
esac
fi
#CentOS 6, RedHat and Suse, use same options of commands, then, I can join it
if [[ $SO = "yum" || $SO = "dnf" || $SO = "zypper" ]];then
case "$1" in
*U*)
$SO update;;
*I*)
$SO install $packages;;
*R*)
$SO remove $packages;;
*S*)
$SO search $packages;;
*F*)
rpm -Uvh $packages;;
esac
fi