1
0
mirror of https://gitlab.com/JKANetwork/jka-toolkit.git synced 2026-02-17 18:41:34 +01:00

Add new file

This commit is contained in:
2016-05-23 10:29:27 +00:00
parent 13030bf88b
commit 2a33ff2b05

138
jka-toolkit/apw Normal file
View File

@@ -0,0 +1,138 @@
#!/bin/bash
# apw, a simple packager wrapper for Arch, Debian, RedHat/Fedora, and Suse (And all his derivates)
# It simplifies the process of remembering pacman,apt, etc , all in one, apw
# Author: JKA Network - contacto@jkanetwork.com
# $1 is the command
# $2,$3.. will be $packages
#Knowing the SO with facter
#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
fi
SO=$(facter osfamily)
#Reading packages to install/remove.. (The rest of $)
packages=$2
for (( i=3; i<=$#; i++ ))
do
valtmp=$(echo $* | cut -f$i -d" ")
packages="$packages $valtmp"
done
if [[ -z "$1" ]];then
echo "No option especified"
echo "Use apw -h for help"
exit
fi
if [[ $1 = "-h" || $1 = "-H" ]];then
echo "apw - A Packager Wrapper, a Idea from JKA Network, version 1.0"
echo " Usage: apw <option> [packages]"
echo " -h 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, ej .deb , .pkg.tar.xz,...)"
exit
fi
#Obligar 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
#Check if is dnf in RedHat, or apt in Debian, new tools
if [[ $SO = "RedHat" && ! -f /usr/bin/dnf ]];then
yum install dnf
fi
if [[ $SO = "Debian" && ! -f /usr/bin/apt ]];then
apt-get update && apt-get install apt
fi
#Ejecución de comandos
if [[ $SO = "Debian" ]];then
if [[ $1 = "-U" || $1 = "U" ]];then
apt update
apt upgrade
fi
if [[ $1 = "-I" || $1 = "I" ]];then
echo "You are going to install $packages and dependencies"
apt update
apt install $packages
fi
if [[ $1 = "-R" || $1 = "R" ]];then
apt remove $packages
fi
if [[ $1 = "-S" || $1 = "S" ]];then
apt search $packages
fi
if [[ $1 = "-F" || $1 = "F" ]];then
dpkg -I $packages
fi
fi
if [[ $SO = "Archlinux" ]];then
if [[ $1 = "-U" || $1 = "U" ]];then
pacman -Syu
fi
if [[ $1 = "-I" || $1 = "I" ]];then
echo "You are going to install $packages and dependencies"
pacman -Syu $packages
fi
if [[ $1 = "-R" || $1 = "R" ]];then
pacman -R $packages
fi
if [[ $1 = "-S" || $1 = "S" ]];then
pacman -Ss $packages
fi
if [[ $1 = "-F" || $1 = "F" ]];then
pacman -U $packages
fi
fi
#RedHat and Fedora
if [[ $SO = "RedHat" ]];then
if [[ $1 = "-U" || $1 = "U" ]];then
dnf update
fi
if [[ $1 = "-I" || $1 = "I" ]];then
echo "You are going to install $packages and dependencies"
dnf install $packages
fi
if [[ $1 = "-R" || $1 = "R" ]];then
dnf remove $packages
fi
if [[ $1 = "-S" || $1 = "S" ]];then
dnf search $packages
fi
if [[ $1 = "-F" || $1 = "F" ]];then
rpm -Uvh $packages
fi
fi
if [[ $SO = "Suse" ]];then
if [[ $1 = "-U" || $1 = "U" ]];then
zypper update
fi
if [[ $1 = "-I" || $1 = "I" ]];then
echo "You are going to install $packages and dependencies"
zypper install $packages
fi
if [[ $1 = "-R" || $1 = "R" ]];then
zypper remove $packages
fi
if [[ $1 = "-S" || $1 = "S" ]];then
zypper search $packages
fi
if [[ $1 = "-F" || $1 = "F" ]];then
rpm -Uvh $packages
fi
fi