From 89edde9b5c32b0883824b6ea34546b11d44034c7 Mon Sep 17 00:00:00 2001 From: mollusk Date: Thu, 19 Jul 2018 15:17:03 -0700 Subject: [PATCH] add: apt, xbps, and dnf support, help section --- tux.sh | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 141 insertions(+), 2 deletions(-) diff --git a/tux.sh b/tux.sh index 2a89672..b045181 100755 --- a/tux.sh +++ b/tux.sh @@ -2,7 +2,7 @@ : 'The MIT License (MIT) -Copyright (c) 2015 Joe Martella +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 @@ -22,5 +22,144 @@ 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') + +###################### + +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" + supCmd="${MANAGER} update && ${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" +fi + +checkArg(){ + if [ -z "${1}" ];then + echo -e "\n${YELLOW}You need to supply and 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) + + ${supCmd} +;; + +r | -r | remove) + + checkArg ${2} + ${removeCmd} "${2}" +;; + +* | -h | --help | help) + echo -e "${0} [option] \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 \ No newline at end of file