mirror of
https://gitlab.com/JKANetwork/jka-toolkit.git
synced 2026-03-15 23:12:03 +01:00
New apw 1.3
This commit is contained in:
@@ -1,17 +1,52 @@
|
||||
#!/bin/bash
|
||||
# apw, a simple packager wrapper for Arch, Debian, RedHat/Fedora, and Suse (And all his derivates)
|
||||
# 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
|
||||
|
||||
#If facter is not installed..
|
||||
if [[ ! -f /usr/bin/facter ]];then
|
||||
echo "apw can not run without facter. Please install facter, is a dependency of apw"
|
||||
exit
|
||||
#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
|
||||
|
||||
@@ -26,7 +61,7 @@ done
|
||||
#echo for every option
|
||||
case "$1" in
|
||||
*h*)
|
||||
echo "apw - A Packager Wrapper, a Idea from JKA Network, version 1.2"
|
||||
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"
|
||||
@@ -58,28 +93,17 @@ case "$1" in
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
#Obligar sudo antes de hacer operaciones que puedan requerirlo
|
||||
uid=$(/usr/bin/id -u)
|
||||
if [[ $uid != "0" ]];then
|
||||
echo "apw has to run as root, please run as root/with sudo"
|
||||
exit
|
||||
fi
|
||||
|
||||
#Knowing the SO with facter
|
||||
SO=$(facter osfamily)
|
||||
|
||||
#Check if is dnf in RedHat, or apt in Debian, new tools
|
||||
if [[ $SO = "RedHat" && ! -f /usr/bin/dnf ]];then
|
||||
if [[ $SO = "dnf" && ! -f /usr/bin/dnf ]];then
|
||||
yum install dnf
|
||||
fi
|
||||
if [[ $SO = "Debian" && ! -f /usr/bin/apt ]];then
|
||||
if [[ $SO = "apt" && ! -f /usr/bin/apt ]];then
|
||||
apt-get update && apt-get install apt
|
||||
fi
|
||||
|
||||
#Command wrapper
|
||||
|
||||
if [[ $SO = "Debian" ]];then
|
||||
if [[ $SO = "apt" ]];then
|
||||
case "$1" in
|
||||
*U*)
|
||||
apt update
|
||||
@@ -98,7 +122,7 @@ if [[ $SO = "Debian" ]];then
|
||||
esac
|
||||
fi
|
||||
|
||||
if [[ $SO = "Archlinux" ]];then
|
||||
if [[ $SO = "pacman" ]];then
|
||||
case "$1" in
|
||||
*U*)
|
||||
pacman -Syu;;
|
||||
@@ -113,32 +137,17 @@ if [[ $SO = "Archlinux" ]];then
|
||||
esac
|
||||
fi
|
||||
|
||||
#RedHat and Fedora
|
||||
if [[ $SO = "RedHat" ]];then
|
||||
#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*)
|
||||
dnf update;;
|
||||
$SO update;;
|
||||
*I*)
|
||||
dnf install $packages;;
|
||||
$SO install $packages;;
|
||||
*R*)
|
||||
dnf remove $packages;;
|
||||
$SO remove $packages;;
|
||||
*S*)
|
||||
dnf search $packages;;
|
||||
*F*)
|
||||
rpm -Uvh $packages;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [[ $SO = "Suse" ]];then
|
||||
case "$1" in
|
||||
*U*)
|
||||
zypper update;;
|
||||
*I*)
|
||||
zypper install $packages;;
|
||||
*R*)
|
||||
zypper remove $packages;;
|
||||
*S*)
|
||||
zypper search $packages;;
|
||||
$SO search $packages;;
|
||||
*F*)
|
||||
rpm -Uvh $packages;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user