188 lines
4.6 KiB
Bash
Executable File
188 lines
4.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
: 'The MIT License (MIT)
|
|
|
|
Copyright (c) 2018 Justin moore
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
SOFTWARE.'
|
|
|
|
# Colors
|
|
RED='\033[0;31m'
|
|
LRED="\033[1;31m"
|
|
BLUE="\033[0;34m"
|
|
LBLUE="\033[1;34m"
|
|
GREEN="\033[0;32m"
|
|
LGREEN="\033[1;32m"
|
|
YELLOW="\033[1;33m"
|
|
CYAN="\033[0;36m"
|
|
LCYAN="\033[1;36m"
|
|
PURPLE="\033[0;35m"
|
|
LPURPLE="\033[1;35m"
|
|
BWHITE="\e[1m"
|
|
|
|
######################
|
|
## PATHS & DEBUG ##
|
|
######################
|
|
WORK_DIR="/usr/bin"
|
|
DEBUG="false" # shows debug mesages, values: true, false
|
|
|
|
#######################
|
|
## PACKAGE MANAGERS ##
|
|
#######################
|
|
# Add your package manager to the list
|
|
|
|
declare -a MANAGER=(
|
|
'apt'
|
|
'dnf'
|
|
'xbps-install'
|
|
'pacman'
|
|
'eopkg')
|
|
|
|
######################
|
|
|
|
for i in "${MANAGER[@]}";do
|
|
|
|
if [ -f ${WORK_DIR}/${i} ];then
|
|
MANAGER=$i
|
|
|
|
if [ "${DEBUG}" = "true" ];then
|
|
echo -e "\n${LGREEN}Detected '$MANAGER${NC}'\n"
|
|
fi
|
|
elif [ -z ${i} ];then
|
|
echo -e "\n${LRED}Unsupported distribution${NC}\n"
|
|
fi
|
|
done
|
|
|
|
###########################
|
|
## PACKAGE MANAGER ARGS ##
|
|
###########################
|
|
# Create additional 'elif' and add specific commands for your package manager
|
|
|
|
if [ "${MANAGER}" = "apt" ];then
|
|
installCmd="${MANAGER} install"
|
|
cleanCmd="${MANAGER} clean"
|
|
orphanCmd="${MANAGER} autoremove"
|
|
reinstallCmd="${MANAGER} install --reinstall"
|
|
removeCmd="${MANAGER} remove"
|
|
searchCmd="${MANAGER} search"
|
|
updateCmd="${MANAGER} update"
|
|
upgradeCmd="${MANAGER} upgrade"
|
|
supCmd="${MANAGER} update ; sudo ${MANAGER} upgrade"
|
|
|
|
elif [ "${MANAGER}" = "dnf" ];then
|
|
installCmd="${MANAGER} install"
|
|
cleanCmd="${MANAGER} clean all"
|
|
orphanCmd="${MANAGER} autoremove"
|
|
removeCmd="${MANAGER} remove"
|
|
reinstallCmd="${MANAGER} reinstall"
|
|
searchCmd="${MANAGER} search"
|
|
supCmd="${MANAGER} --refresh upgrade"
|
|
|
|
elif [ "${MANAGER}" = "xbps-install" ];then
|
|
installCmd="${MANAGER}"
|
|
cleanCmd="${MANAGER} -o"
|
|
orphanCmd="${MANAGER} -O"
|
|
removeCmd="xbps-remove"
|
|
reinstallCmd="${MANAGER} -f"
|
|
searchCmd="xbps-query -Rs"
|
|
supCmd="${MANAGER} -Su"
|
|
|
|
elif [ "${MANAGER}" = "pacman" ];then
|
|
installCmd="${MANAGER} -S"
|
|
cleanCmd="${MANAGER} -Scc"
|
|
orphanCmd="${MANAGER} -Rns $(pacman -Qtdq)"
|
|
removeCmd="${MANAGER} -R"
|
|
reinstallCmd="${MANAGER} -S"
|
|
searchCmd="${MANAGER} -Ss"
|
|
supCmd="${MANAGER} -Syu"
|
|
|
|
elif [ "${MANAGER}" = "eopkg" ];then
|
|
installCmd="${MANAGER} it"
|
|
cleanCmd="${MANAGER} dc"
|
|
orphanCmd="${MANAGER} rmo"
|
|
removeCmd="${MANAGER} rm"
|
|
reinstallCmd="${MANAGER} install --reinstall"
|
|
searchCmd="${MANAGER} sr"
|
|
supCmd="${MANAGER} up"
|
|
fi
|
|
|
|
checkArg(){
|
|
if [ -z "${1}" ];then
|
|
echo -e "\n${YELLOW}You need to supply at least 1 argument!${NC}\n"
|
|
exit 1;
|
|
fi
|
|
}
|
|
|
|
#find ${WORK_DIR}/ -iname ${MANAGERS}
|
|
|
|
case ${1} in
|
|
|
|
i | -i | install)
|
|
|
|
${installCmd} "${2}"
|
|
;;
|
|
|
|
c | -c | clean)
|
|
|
|
${cleanCmd}
|
|
;;
|
|
|
|
o | -o | orphans)
|
|
|
|
${orphanCmd}
|
|
;;
|
|
|
|
ri | -ri | reinstall)
|
|
|
|
checkArg ${2}
|
|
${reinstallCmd} "${2}"
|
|
|
|
;;
|
|
|
|
s | -s | search)
|
|
|
|
checkArg ${2}
|
|
${searchCmd} "${2}"
|
|
;;
|
|
|
|
-Syu | -Su | sup)
|
|
|
|
${updateCmd} && ${upgradeCmd}
|
|
;;
|
|
|
|
r | -r | remove)
|
|
|
|
checkArg ${2}
|
|
${removeCmd} "${2}"
|
|
;;
|
|
|
|
* | -h | --help | help)
|
|
echo -e "${0} [option] <argument>\n\n"
|
|
|
|
echo -e "i,-i,install Install package(s)\n"
|
|
echo -e "c,-c,clean Clean package cache\n"
|
|
echo -e "o,-o,orphans Remove disassociated packages\n"
|
|
echo -e "ri,-ri,reinstall Reinstall package(s)\n"
|
|
echo -e "r,-r,remove Remove package(s)\n"
|
|
echo -e "s,-s,search Search for packages\n"
|
|
echo -e "-Syu,-Su,sup Sync repodata and upgrade all\n"
|
|
|
|
|
|
esac
|