mirror of
https://github.com/casjaysdevdocker/bind
synced 2024-11-26 17:23:10 -05:00
141 lines
5.0 KiB
Plaintext
141 lines
5.0 KiB
Plaintext
|
#!/usr/bin/env bash
|
||
|
# shellcheck shell=bash
|
||
|
# shellcheck disable=SC2016
|
||
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||
|
[ -n "$_DEBUG" ] && _DEBUG_OPTIONS="-x"
|
||
|
[ "$1" = "--debug" ] && _DEBUG_OPTIONS="-x" && shift 1
|
||
|
[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS
|
||
|
set -e $_DEBUG_OPTIONS
|
||
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||
|
USER_UID="$(id -u)"
|
||
|
USER_GID="$(id -g)"
|
||
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||
|
[ -f "/etc/pkmgr/options.conf" ] && . "/etc/pkmgr/options.conf"
|
||
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||
|
if [ -x "$(command -v apt 2>/dev/null)" ]; then
|
||
|
export DEBIAN_FRONTEND=noninteractive
|
||
|
pkmgr_cmd="apt"
|
||
|
pkmgr_clean_cmd="$pkmgr_cmd clean"
|
||
|
pkmgr_mkcache_cmd="$pkmgr_cmd update"
|
||
|
pkmgr_update_cmd="$pkmgr_cmd upgrade -yy"
|
||
|
pkmgr_install_cmd="$pkmgr_cmd install -yy $PKMGR_OPTS"
|
||
|
elif [ -x "$(command -v apt-get 2>/dev/null)" ]; then
|
||
|
export DEBIAN_FRONTEND=noninteractive
|
||
|
pkmgr_cmd="apt-get"
|
||
|
pkmgr_clean_cmd="$pkmgr_cmd clean"
|
||
|
pkmgr_mkcache_cmd="$pkmgr_cmd update"
|
||
|
pkmgr_update_cmd="$pkmgr_cmd upgrade -yy"
|
||
|
pkmgr_install_cmd="$pkmgr_cmd install -yy $PKMGR_OPTS"
|
||
|
elif [ -x "$(command -v dnf 2>/dev/null)" ]; then
|
||
|
pkmgr_cmd="dnf"
|
||
|
pkmgr_clean_cmd="$pkmgr_cmd clean all"
|
||
|
pkmgr_mkcache_cmd="$pkmgr_cmd makecache"
|
||
|
pkmgr_update_cmd="$pkmgr_cmd update -y --skip-broken $PKMGR_OPTS"
|
||
|
pkmgr_install_cmd="$pkmgr_cmd install -y --skip-broken $PKMGR_OPTS"
|
||
|
elif [ -x "$(command -v yum 2>/dev/null)" ]; then
|
||
|
pkmgr_cmd="yum"
|
||
|
pkmgr_clean_cmd="$pkmgr_cmd clean all"
|
||
|
pkmgr_mkcache_cmd="$pkmgr_cmd makecache"
|
||
|
pkmgr_update_cmd="$pkmgr_cmd update -y --skip-broken $PKMGR_OPTS"
|
||
|
pkmgr_install_cmd="$pkmgr_cmd install -y --skip-broken $PKMGR_OPTS"
|
||
|
elif [ -n "$(command -v pacman 2>/dev/null)" ]; then
|
||
|
pkmgr_cmd="pacman"
|
||
|
pkmgr_mkcache_cmd="true"
|
||
|
pkmgr_clean_cmd="$pkmgr_cmd -Scc --noconfirm"
|
||
|
pkmgr_update_cmd="$pkmgr_cmd -Syyu --noconfirm $PKMGR_OPTS"
|
||
|
pkmgr_install_cmd="$pkmgr_cmd -Syy --noconfirm $PKMGR_OPTS"
|
||
|
elif [ -x "$(command -v apk 2>/dev/null)" ]; then
|
||
|
pkmgr_cmd="apk"
|
||
|
pkmgr_mkcache_cmd="true"
|
||
|
pkmgr_clean_cmd="$pkmgr_cmd cache clean"
|
||
|
pkmgr_update_cmd="$pkmgr_cmd -U upgrade --no-cache $PKMGR_OPTS"
|
||
|
pkmgr_install_cmd="$pkmgr_cmd add --no-cache $PKMGR_OPTS"
|
||
|
elif [ -x "$(command -v zypper 2>/dev/null)" ]; then
|
||
|
pkmgr_cmd="zypper"
|
||
|
pkmgr_mkcache_cmd="true"
|
||
|
pkmgr_clean_cmd="$pkmgr_cmd clean --all"
|
||
|
pkmgr_update_cmd="$pkmgr_cmd update -y $PKMGR_OPTS"
|
||
|
pkmgr_install_cmd="$pkmgr_cmd install -y $PKMGR_OPTS"
|
||
|
else
|
||
|
pkmgr_cmd="true"
|
||
|
pkmgr_mkcache_cmd="$pkmgr_cmd"
|
||
|
pkmgr_clean_cmd="$pkmgr_cmd"
|
||
|
pkmgr_update_cmd="$pkmgr_cmd"
|
||
|
pkmgr_install_cmd="$pkmgr_cmd"
|
||
|
fi
|
||
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||
|
if [ -f "/config/pkmgr/settings.conf" ]; then
|
||
|
. "/config/pkmgr/settings.conf"
|
||
|
elif [ -f "/etc/pkmgr/settings.conf" ]; then
|
||
|
. "/etc/pkmgr/settings.conf"
|
||
|
else
|
||
|
mkdir -p "/config/pkmgr"
|
||
|
cat <<EEOF >"/config/pkmgr/settings.conf"
|
||
|
pkmgr_cmd="$pkmgr_cmd"
|
||
|
pkmgr_clean_cmd="$pkmgr_clean_cmd"
|
||
|
pkmgr_update_cmd="$pkmgr_update_cmd"
|
||
|
pkmgr_install_cmd="$pkmgr_install_cmd"
|
||
|
pkmgr_mkcache_cmd="$pkmgr_mkcache_cmd"
|
||
|
EEOF
|
||
|
fi
|
||
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||
|
[ -n "$pkmgr_cmd" ] || { echo "Can not determine the package manager" && exit 1; }
|
||
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||
|
case "$1" in
|
||
|
pip)
|
||
|
shift 1
|
||
|
pip_bin="$(command -v python3 2>/dev/null || command -v python2 2>/dev/null || command -v python 2>/dev/null || echo "")"
|
||
|
py_version="$($pip_bin --version | sed 's|[pP]ython ||g' | awk -F '.' '{print $1$2}' | grep '[0-9]' || echo "0")"
|
||
|
[ "$py_version" -gt "310" ] && pip_opts="--break-system-packages " || pip_opts=""
|
||
|
case "$1" in
|
||
|
install)
|
||
|
shift 1
|
||
|
$pip_bin -m $pip_opts "$@"
|
||
|
;;
|
||
|
*)
|
||
|
$pip_bin "$@"
|
||
|
;;
|
||
|
esac
|
||
|
exit $?
|
||
|
;;
|
||
|
update | upgrade)
|
||
|
shift $#
|
||
|
[ "$USER_UID" -eq 0 ] || [ "$USER" = "root" ] || pkmgr_update_cmd="sudo $pkmgr_install_cmd"
|
||
|
echo "Updating packages command: $pkmgr_update_cmd"
|
||
|
$pkmgr_mkcache_cmd
|
||
|
$pkmgr_update_cmd
|
||
|
exit $?
|
||
|
;;
|
||
|
clean)
|
||
|
shift $#
|
||
|
[ -n "$1" ] || exit 0
|
||
|
[ "$USER_UID" -eq 0 ] || [ "$USER" = "root" ] || pkmgr_clean_cmd="sudo $pkmgr_clean_cmd"
|
||
|
echo "Cleaning package cache: $pkmgr_clean_cmd"
|
||
|
$pkmgr_clean_cmd
|
||
|
exit $?
|
||
|
;;
|
||
|
install)
|
||
|
shift 1
|
||
|
[ -n "$1" ] || exit 0
|
||
|
[ "$USER_UID" -eq 0 ] || [ "$USER" = "root" ] || pkmgr_install_cmd="sudo $pkmgr_install_cmd"
|
||
|
if [ -f "$1" ]; then
|
||
|
install_list="$(cat "$1")"
|
||
|
echo 'installing packages from file with command: '$pkmgr_install_cmd' "$(<"$1")"'
|
||
|
else
|
||
|
install_list="$*"
|
||
|
echo "installing packages command: $pkmgr_install_cmd $install_list"
|
||
|
fi
|
||
|
$pkmgr_install_cmd $install_list
|
||
|
exit $?
|
||
|
;;
|
||
|
*)
|
||
|
[ -n "$1" ] || exit 0
|
||
|
[ "$USER_UID" -eq 0 ] || [ "$USER" = "root" ] || pkmgr_cmd="sudo $pkmgr_cmd"
|
||
|
echo "executing packages command: $pkmgr_cmd $*"
|
||
|
$pkmgr_cmd "$@"
|
||
|
exit $?
|
||
|
;;
|
||
|
esac
|
||
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||
|
# end
|