From 05fbbb24fe9ce8ef20405b2b88c43f66e7640e09 Mon Sep 17 00:00:00 2001 From: Ky-Anh Huynh Date: Mon, 21 Jun 2021 23:38:57 +0200 Subject: [PATCH] pacapt v3.0.0 --- CHANGELOG.md | 8 +- pacapt | 3720 +++++++++++++++++++++++++++----------------------- 2 files changed, 2021 insertions(+), 1707 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f914a16e..179795ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,14 @@ -## next +## v3.0.0 ### New features +* `lib/opkg`: Add support for `OpenWrt` (and alike) +* `Bash` is not required on `Alpine`, `SunOS` or `OpenWrt`: + The proram can work perfectly with `POSIX` shell on those systems. * Single script can now execute within `POSIX` or `non-POSIX` environment and it detects/loads features dynamically. -* `lib/opkg`: Add support for `OpenWrt` (and alike) + If the system has `bash` installed, the program switches to + `bash` as soon as possible. ### Fixes and Updates diff --git a/pacapt b/pacapt index b95756d0..5da8924a 100755 --- a/pacapt +++ b/pacapt @@ -1,9 +1,9 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh # # Purpose: A wrapper for all Unix package managers # License: Fair license (http://www.opensource.org/licenses/fair) # Source : http://github.com/icy/pacapt/ -# Version: 2.4.4 +# Version: 3.0.0 # Authors: Anh K. Huynh et al. # Copyright (C) 2010 - 2021 \ @@ -45,7 +45,7 @@ _print_pacapt_version() { cat <<_EOF_ -pacapt version '2.4.4' +pacapt version '3.0.0' Copyright (C) 2010 - 2021 \\ | 10sr (10sr) @@ -85,7 +85,7 @@ DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY. _EOF_ } -export PACAPT_VERSION='2.4.4' +export PACAPT_VERSION='3.0.0' _help() { cat <<'EOF' @@ -196,20 +196,26 @@ EOF _error() { - echo >&2 "Error: $*" + echo >&2 ":: Error: $*" return 1 } _warn() { - echo >&2 "Warning: $*" + echo >&2 ":: Warning: $*" return 0 } _die() { - echo >&2 "$@" + echo >&2 ":: $*" exit 1 } +_debug() { + if [ -n "${PACAPT_DEBUG:-}" ]; then + >&2 echo ":: [debug] $*" + fi +} + _not_implemented() { # shellcheck disable=2153 echo >&2 "${_PACMAN}: '${_POPT}:${_SOPT}:${_TOPT}' operation is invalid or not implemented." @@ -222,9 +228,7 @@ _removing_is_dangerous() { } _issue2pacman() { - local _pacman - - _pacman="$1"; shift + local_pacman="$1"; shift # The following line is added by Daniel YC Lin to support SunOS. # @@ -234,13 +238,13 @@ _issue2pacman() { # on Linux/BSD systems. To avoid extra check, I slightly modify # the code to make sure it's only applicable on SunOS. # - [[ "$(uname)" == "SunOS" ]] && _PACMAN="$_pacman" && return + [ "$(uname)" = "SunOS" ] && _PACMAN="$local_pacman" && return $GREP -qis "$@" /etc/issue \ - && _PACMAN="$_pacman" && return + && _PACMAN="$local_pacman" && return $GREP -qis "$@" /etc/os-release \ - && _PACMAN="$_pacman" && return + && _PACMAN="$local_pacman" && return } _PACMAN_detect() { @@ -263,1805 +267,2054 @@ _PACMAN_detect() { # I'm not sure how to support this case easily. Let's wait, e.g, 5 years # from now to make `dnf` becomes a default? Oh no! # - # And here why `pacman` is still smart. Debian has a set of tools. - # Fedora has `yum` (and a set of add-ons). Now Fedora moves to `dnf`. - # This means that a package manager is not a heart of a system ;) - # - # _issue2pacman yum "Fedora" && return - _issue2pacman zypper "SUSE" && return - _issue2pacman pkg_tools "OpenBSD" && return - _issue2pacman pkg_tools "Bitrig" && return - _issue2pacman apk "Alpine Linux" && return - - [[ -z "$_PACMAN" ]] || return - - # Prevent a loop when this script is installed on non-standard system - if [[ -x "/usr/bin/pacman" ]]; then - $GREP -q "${FUNCNAME[0]}" '/usr/bin/pacman' >/dev/null 2>&1 - [[ $? -ge 1 ]] && _PACMAN="pacman" \ - && return - fi - - [[ -x "/usr/bin/apt-get" ]] && _PACMAN="dpkg" && return - [[ -x "/data/data/com.termux/files/usr/bin/apt-get" ]] && _PACMAN="dpkg" && return - [[ -x "/usr/bin/cave" ]] && _PACMAN="cave" && return - [[ -x "/usr/bin/dnf" ]] && _PACMAN="dnf" && return - [[ -x "/usr/bin/yum" ]] && _PACMAN="yum" && return - [[ -x "/opt/local/bin/port" ]] && _PACMAN="macports" && return - [[ -x "/usr/bin/emerge" ]] && _PACMAN="portage" && return - [[ -x "/usr/bin/zypper" ]] && _PACMAN="zypper" && return - [[ -x "/usr/sbin/pkg" ]] && _PACMAN="pkgng" && return - # make sure pkg_add is after pkgng, FreeBSD base comes with it until converted - [[ -x "/usr/sbin/pkg_add" ]] && _PACMAN="pkg_tools" && return - [[ -x "/usr/sbin/pkgadd" ]] && _PACMAN="sun_tools" && return - [[ -x "/sbin/apk" ]] && _PACMAN="apk" && return - [[ -x "/usr/bin/tazpkg" ]] && _PACMAN="tazpkg" && return - [[ -x "/usr/bin/swupd" ]] && _PACMAN="swupd" && return - - command -v brew >/dev/null && _PACMAN="homebrew" && return - - return 1 -} - -_translate_w() { - - echo "$_EOPT" | $GREP -q ":w:" || return 0 - - local _opt= - local _ret=0 - - case "$_PACMAN" in - "dpkg") _opt="-d";; - "cave") _opt="-f";; - "macports") _opt="fetch";; - "portage") _opt="--fetchonly";; - "zypper") _opt="--download-only";; - "pkgng") _opt="fetch";; - "yum") _opt="--downloadonly"; - if ! rpm -q 'yum-downloadonly' >/dev/null 2>&1; then - _error "'yum-downloadonly' package is required when '-w' is used." - _ret=1 - fi - ;; - "tazpkg") - _error "$_PACMAN: Use '$_PACMAN get' to download and save packages to current directory." - _ret=1 - ;; - "apk") _opt="fetch";; - *) - _opt="" - _ret=1 - - _error "$_PACMAN: Option '-w' is not supported/implemented." - ;; - esac - - echo $_opt - return "$_ret" -} - -_translate_debug() { - echo "$_EOPT" | $GREP -q ":v:" || return 0 - - case "$_PACMAN" in - "tazpkg") - _error "$_PACMAN: Option '-v' (debug) is not supported/implemented by tazpkg" - return 1 - ;; - esac - - echo "-v" -} - -_translate_noconfirm() { - - echo "$_EOPT" | $GREP -q ":noconfirm:" || return 0 - - local _opt= - local _ret=0 - - case "$_PACMAN" in - # FIXME: Update environment DEBIAN_FRONTEND=noninteractive - # FIXME: There is also --force-yes for a stronger case - "dpkg") _opt="--yes";; - "dnf") _opt="--assumeyes";; - "yum") _opt="--assumeyes";; - # FIXME: pacman has 'assume-yes' and 'assume-no' - # FIXME: zypper has better mode. Similar to dpkg (Debian). - "zypper") _opt="--no-confirm";; - "pkgng") _opt="-y";; - "tazpkg") _opt="--auto";; - *) - _opt="" - _ret=1 - _error "$_PACMAN: Option '--noconfirm' is not supported/implemented." - ;; - esac - - echo $_opt - return $_ret -} - -_translate_all() { - local _args="" - local _debug= - local _noconfirm= - - _debug="$(_translate_debug)" - _noconfirm="$(_translate_noconfirm)" - _args="$(_translate_w)" || return 1 - _args="${_args}${_noconfirm:+ }${_noconfirm}" || return 1 - _args="${_args}${_debug:+ }${_debug}" || return 1 - - export _EOPT="${_args# }" -} - -_print_supported_operations() { - local _pacman="$1" - echo -n "pacapt($_pacman): available operations:" - # shellcheck disable=2016 - $GREP -E "^${_pacman}_[^ \\t]+\\(\\)" "$0" \ - | $AWK -F '(' '{print $1}' \ - | sed -e "s/${_pacman}_//g" \ - | while read -r O; do - echo -n " $O" - done - echo -} - - -export _SUPPORTED_EXTERNALS=" - :conda - :tlmgr - :texlive - :gem - :npm - :pip -" -readonly _SUPPORTED_EXTERNALS - -_PACMAN_found_from_script_name() { - local _tmp_name= - local _pacman= - - _tmp_name="${BASH_SOURCE[0]:-?}" - if [[ "$_tmp_name" == "?" ]]; then - _error "Unable to get script name." - return 1 - fi - - _tmp_name="${_tmp_name##*/}" # base name (remove everything before the last `/`) - _tmp_name="${_tmp_name%.*}" # remove extension if any (remove everything from the last `.`) - _pacman="${_tmp_name##*-}" # remove every thing before the last `-` - - if grep -Eq -e ":$_pacman[[:space:]]*" <<< "$_SUPPORTED_EXTERNALS"; then - export _PACMAN="$_pacman" - return 0 - else - export _PACMAN="" - return 1 - fi -} - - - -_apk_init() { - : -} - -apk_Q() { - if [[ -z "$_TOPT" ]]; then - apk info - else - _not_implemented - fi -} - -apk_Qi() { - apk info -a -- "$@" -} - -apk_Ql() { - apk info -L -- "$@" -} - -apk_Qo() { - apk info --who-owns -- "$@" -} - -apk_Qs() { - apk info -- "*${*}*" -} - -apk_Qu() { - apk version -l '<' -} - -apk_R() { - apk del -- "$@" -} - -apk_Rn() { - apk del --purge -- "$@" -} - -apk_Rns() { - apk del --purge -r -- "$@" -} - -apk_Rs() { - apk del -r -- "$@" -} - -apk_S() { - case ${_EOPT} in - # Download only - ("fetch") shift - apk fetch -- "$@" ;; - (*) apk add $_TOPT -- "$@" ;; - esac -} - -apk_Sc() { - apk cache -v clean -} - -apk_Scc() { - rm -rf /var/cache/apk/* -} - -apk_Sccc() { - apk_Scc -} - -apk_Si() { - apk_Qi "$@" -} - -apk_Sii() { - apk info -r -- "$@" -} - -apk_Sl() { - apk search -v -- "$@" -} - -apk_Ss() { - apk_Sl "$@" -} - -apk_Su() { - apk upgrade -} - -apk_Suy() { - if [ "$#" -gt 0 ]; then - apk add -U -u -- "$@" - else - apk upgrade -U -a - fi -} - -apk_Sy() { - apk update -} - -apk_Sw() { - apk fetch -- "$@" -} - -apk_U() { - apk add --allow-untrusted -- "$@" -} - - - -_cave_init() { - shopt -u globstar -} - -cave_Q() { - if [[ "$_TOPT" == "q" ]]; then - cave show -f "${@:-world}" \ - | grep -v '^$' - else - cave show -f "${@:-world}" - fi -} - -cave_Qi() { - cave show "$@" -} - -cave_Ql() { - if [[ -n "$*" ]]; then - cave contents "$@" - return - fi - - cave show -f "${@:-world}" \ - | grep -v '^$' \ - | while read -r _pkg; do - if [[ "$_TOPT" == "q" ]]; then - cave --color no contents "$_pkg" - else - cave contents "$_pkg" - fi - done -} - -cave_Qo() { - cave owner "$@" -} - -cave_Qp() { - _not_implemented -} - -cave_Qu() { - if [[ -z "$*" ]];then - cave resolve -c world \ - | grep '^u.*' \ - | while read -r _pkg; do - echo "$_pkg" | cut -d'u' -f2- - done - else - cave resolve -c world \ - | grep '^u.*' \ - | grep -- "$@" - fi -} - -cave_Qs() { - cave show -f world | grep -- "$@" -} - -cave_Rs() { - if [[ "$_TOPT" == "" ]]; then - cave uninstall -r "$@" \ - && echo "Control-C to stop uninstalling..." \ - && sleep 2s \ - && cave uninstall -xr "$@" - else - cave purge "$@" \ - && echo "Control-C to stop uninstalling (+ dependencies)..." \ - && sleep 2s \ - && cave purge -x "$@" - fi -} - -cave_Rn() { - _not_implemented -} - -cave_Rns() { - _not_implemented -} - -cave_R() { - cave uninstall "$@" \ - && echo "Control-C to stop uninstalling..." \ - && sleep 2s \ - && cave uninstall -x "$@" -} - -cave_Si() { - cave show "$@" -} - -cave_Suy() { - cave sync && cave resolve -c "${@:-world}" \ - && echo "Control-C to stop upgrading..." \ - && sleep 2s \ - && cave resolve -cx "${@:-world}" -} - -cave_Su() { - cave resolve -c "$@" \ - && echo "Control-C to stop upgrading..." \ - && sleep 2s \ - && cave resolve -cx "$@" -} - -cave_Sy() { - cave sync "$@" -} - -cave_Ss() { - cave search "$@" -} - -cave_Sc() { - cave fix-cache "$@" -} - -cave_Scc() { - cave fix-cache "$@" -} - -cave_Sccc() { - #rm -fv /var/cache/paludis/* - _not_implemented -} - -cave_S() { - cave resolve $_TOPT "$@" \ - && echo "Control-C to stop installing..." \ - && sleep 2s \ - && cave resolve -x $_TOPT "$@" -} - -cave_U() { - _not_implemented -} - - - -_conda_init() { - : -} - -conda_Q() { - if [[ $# -gt 0 ]]; then - conda list "$(python -c 'import sys; print("^" + "|".join(sys.argv[1:]) + "$")' "$@")" - else - conda list - fi -} - -conda_R() { - conda remove "$@" -} - -conda_S() { - conda install "$@" -} - -conda_Sc() { - conda clean --all "$@" -} - -conda_Si() { - conda search "$@" --info -} - -conda_Ss() { - conda search "*$@*" -} - -conda_Suy() { - conda update --all "$@" -} - - - - -_dnf_init() { - : -} - -dnf_S() { - dnf install $_TOPT "$@" -} - -dnf_Sc() { - dnf clean expire-cache "$@" -} - -dnf_Scc() { - dnf clean packages "$@" -} - -dnf_Sccc() { - dnf clean all "$@" -} - -dnf_Si() { - dnf info "$@" && dnf repoquery --deplist "$@" -} - -dnf_Sg() { - if [[ $# -gt 0 ]]; then - dnf group info "$@" - else - dnf group list - fi -} - -dnf_Sl() { - dnf list available "$@" -} - -dnf_Ss() { - dnf search "$@" -} - -dnf_Su() { - dnf upgrade "$@" -} - -dnf_Suy() { - dnf upgrade "$@" -} - -dnf_Sw() { - dnf download "$@" -} - -dnf_Sy() { - dnf clean expire-cache && dnf check-update -} - -dnf_Q() { - if [[ "$_TOPT" == "q" ]]; then - rpm -qa --qf "%{NAME}\\n" - elif [[ "$_TOPT" == "" ]]; then - rpm -qa --qf "%{NAME} %{VERSION}\\n" - else - _not_implemented - fi -} - -dnf_Qc() { - rpm -q --changelog "$@" -} - -dnf_Qe() { - dnf repoquery --userinstalled "$@" -} - -dnf_Qi() { - dnf info --installed "$@" && dnf repoquery --deplist "$@" -} - -dnf_Ql() { - rpm -ql "$@" -} - -dnf_Qm() { - dnf list extras -} - -dnf_Qo() { - rpm -qf "$@" -} - -dnf_Qp() { - rpm -qp "$@" -} - -dnf_Qs() { - rpm -qa "*${*}*" -} - -dnf_Qu() { - dnf list updates "$@" -} - -dnf_R() { - dnf remove "$@" -} - -dnf_U() { - dnf install "$@" -} - - - -_dpkg_init() { - : -} - -dpkg_Q() { - if [[ "$_TOPT" == "q" ]]; then - dpkg -l \ - | grep -E '^[hi]i' \ - | awk '{print $2}' - elif [[ "$_TOPT" == "" ]]; then - dpkg -l "$@" \ - | grep -E '^[hi]i' - else - _not_implemented - fi -} - -dpkg_Qi() { - dpkg-query -s "$@" -} - -dpkg_Ql() { - if [[ -n "$*" ]]; then - dpkg-query -L "$@" - return - fi - - dpkg -l \ - | grep -E '^[hi]i' \ - | awk '{print $2}' \ - | while read -r _pkg; do - if [[ "$_TOPT" == "q" ]]; then - dpkg-query -L "$_pkg" - else - dpkg-query -L "$_pkg" \ - | while read -r _line; do - echo "$_pkg $_line" - done - fi - done -} - -dpkg_Qo() { - dpkg-query -S "$@" -} - -dpkg_Qp() { - dpkg-deb -I "$@" -} - -dpkg_Qu() { - apt-get upgrade --trivial-only "$@" -} - -dpkg_Qs() { - # dpkg >= 1.16.2 dpkg-query -W -f='${db:Status-Abbrev} ${binary:Package}\t${Version}\t${binary:Summary}\n' - dpkg-query -W -f='${Status} ${Package}\t${Version}\t${Description}\n' \ - | grep -E '^((hold)|(install)|(deinstall))' \ - | sed -r -e 's#^(\w+ ){3}##g' \ - | grep -Ei "${@:-.}" -} - -dpkg_Rs() { - if [[ "$_TOPT" == "" ]]; then - apt-get autoremove "$@" - else - _not_implemented - fi -} - -dpkg_Rn() { - apt-get purge "$@" -} - -dpkg_Rns() { - apt-get --purge autoremove "$@" -} - -dpkg_R() { - apt-get remove "$@" -} - -dpkg_Si() { - apt-cache show "$@" -} - -dpkg_Suy() { - apt-get update \ - && apt-get upgrade "$@" \ - && apt-get dist-upgrade "$@" -} - -dpkg_Su() { - apt-get upgrade "$@" \ - && apt-get dist-upgrade "$@" -} - - -dpkg_Sy() { - apt-get update "$@" -} - -dpkg_Ss() { - apt-cache search "$@" -} - -dpkg_Sc() { - apt-get clean "$@" -} - -dpkg_Scc() { - apt-get autoclean "$@" -} - -dpkg_S() { - apt-get install $_TOPT "$@" -} - -dpkg_U() { - dpkg -i "$@" -} - -dpkg_Sii() { - apt-cache rdepends "$@" -} - -dpkg_Sccc() { - rm -fv /var/cache/apt/*.bin - rm -fv /var/cache/apt/archives/*.* - rm -fv /var/lib/apt/lists/*.* - apt-get autoclean -} - - - -_homebrew_init() { - : -} - -homebrew_Qi() { - brew info "$@" -} - -homebrew_Ql() { - brew list "$@" -} - -homebrew_Qo() { - local pkg prefix cellar - - # FIXME: What happens if the file is not exectutable? - cd "$(dirname -- "$(which "$@")")" || return - pkg="$(pwd -P)/$(basename -- "$@")" - prefix="$(brew --prefix)" - cellar="$(brew --cellar)" - - for package in $cellar/*; do - files=(${package}/*/${pkg/#$prefix\//}) - if [[ -e "${files[${#files[@]} - 1]}" ]]; then - echo "${package/#$cellar\//}" - break - fi - done -} - -homebrew_Qc() { - brew log "$@" -} - -homebrew_Qu() { - brew outdated | grep "$@" -} - -homebrew_Qs() { - brew list | grep "$@" -} - -homebrew_Q() { - if [[ "$_TOPT" == "" ]]; then - if [[ "$*" == "" ]]; then - brew list - else - brew list | grep "$@" - fi - else - _not_implemented - fi -} - -homebrew_Rs() { - which join > /dev/null - if [ $? -ne 0 ]; then - _die "pacapt: join binary does not exist in system." - fi - - which sort > /dev/null - if [ $? -ne 0 ]; then - _die "pacapt: sort binary does not exist in system." - fi - - if [[ "$@" == "" ]]; then - _die "pacapt: ${FUNCNAME[0]} requires arguments" - fi - - for _target in $@; - do - brew rm $_target - - while [ "$(join <(sort <(brew leaves)) <(sort <(brew deps $_target)))" != "" ] - do - brew rm $(join <(sort <(brew leaves)) <(sort <(brew deps $_target))) - done - done - -} - -homebrew_R() { - brew remove "$@" -} - -homebrew_Si() { - brew info "$@" -} - -homebrew_Suy() { - brew update \ - && brew upgrade "$@" -} - -homebrew_Su() { - brew upgrade "$@" -} - -homebrew_Sy() { - brew update "$@" -} - -homebrew_Ss() { - brew search "$@" -} - -homebrew_Sc() { - brew cleanup "$@" -} - -homebrew_Scc() { - brew cleanup -s "$@" -} - -homebrew_Sccc() { - # See more discussion in - # https://github.com/icy/pacapt/issues/47 - - local _dcache - - _dcache="$(brew --cache)" - case "$_dcache" in - ""|"/"|" ") - _error "${FUNCNAME[0]}: Unable to delete '$_dcache'." - ;; - - *) - # FIXME: This is quite stupid!!! But it's an easy way - # FIXME: to avoid some warning from #shellcheck. - # FIXME: Please note that, $_dcache is not empty now. - rm -rf "${_dcache:-/x/x/x/x/x/x/x/x/x/x/x//x/x/x/x/x/}/" - ;; - esac -} - -homebrew_S() { - 2>&1 brew install $_TOPT "$@" \ - | awk '{print; if ($0 ~ /brew cask install/) { exit(126); }}' - ret=( ${PIPESTATUS[*]} ) - if [[ "${ret[1]}" == 126 ]]; then - echo >&2 ":: Now trying with brew/cask..." - brew cask install $_TOPT "$@" - else - return "${ret[0]}" - fi -} - - - -_macports_init() { - : -} - -macports_Ql() { - port contents "$@" -} - -macports_Qo() { - port provides "$@" -} - -macports_Qc() { - port log "$@" -} - -macports_Qu() { - port outdated "$@" -} - -macports_Rs() { - if [[ "$_TOPT" == "" ]]; then - port uninstall --follow-dependencies "$@" - else - _not_implemented - fi -} - -macports_R() { - port uninstall "$@" -} - -macports_Si() { - port info "$@" -} - -macports_Suy() { - port selfupdate \ - && port upgrade outdated "$@" -} - -macports_Su() { - port upgrade outdate "$@" -} - -macports_Sy() { - port selfupdate "$@" -} - -macports_Ss() { - port search "$@" -} - -macports_Sc() { - port clean --all inactive "$@" -} - -macports_Scc() { - port clean --all installed "$@" -} - -macports_S() { - if [[ "$_TOPT" == "fetch" ]]; then - port patch "$@" - else - port install "$@" - fi -} - - - -_pkgng_init() { - : -} - -pkgng_Qi() { - pkg info "$@" -} - -pkgng_Ql() { - pkg info -l "$@" -} - -pkgng_Qo() { - pkg which "$@" -} - -pkgng_Qp() { - pkg query -F "$@" '%n %v' -} - -pkgng_Qu() { - pkg upgrade -n "$@" -} - -pkgng_Q() { - if [[ "$_TOPT" == "q" ]]; then - pkg query '%n' "$@" - elif [[ "$_TOPT" == "" ]]; then - pkg query '%n %v' "$@" - else - _not_implemented - fi -} - -pkgng_Rs() { - if [[ "$_TOPT" == "" ]]; then - pkg remove "$@" - pkg autoremove - else - _not_implemented - fi -} - -pkgng_R() { - pkg remove "$@" -} - -pkgng_Si() { - pkg search -S name -ef "$@" -} - -pkgng_Suy() { - pkg upgrade "$@" -} - -pkgng_Su() { - pkg upgrade -U "$@" -} - -pkgng_Sy() { - pkg update "$@" -} - -pkgng_Ss() { - pkg search "$@" -} - -pkgng_Sc() { - pkg clean "$@" -} - -pkgng_Scc() { - pkg clean -a "$@" -} - -pkgng_S() { - if [[ "$_TOPT" == "fetch" ]]; then - pkg fetch "$@" - else - pkg install "$@" - fi -} - - - -_pkg_tools_init() { - : -} - -pkg_tools_Qi() { - # disable searching mirrors for packages - export PKG_PATH= - pkg_info "$@" -} - -pkg_tools_Ql() { - export PKG_PATH= - pkg_info -L "$@" -} - -pkg_tools_Qo() { - export PKG_PATH= - pkg_info -E "$@" -} - -pkg_tools_Qp() { - _not_implemented -} - -pkg_tools_Qu() { - export PKG_PATH= - pkg_add -u "$@" -} - -pkg_tools_Q() { - export PKG_PATH= - # the dash after the pkg name is so we don't catch partial matches - # because all packages in openbsd have the format 'pkgname-pkgver' - if [[ "$_TOPT" == "q" && ! -z "$*" ]]; then - pkg_info -q | grep "^${*}-" - elif [[ "$_TOPT" == "q" && -z "$*" ]];then - pkg_info -q - elif [[ "$_TOPT" == "" && ! -z "$*" ]]; then - pkg_info | grep "^${*}-" - elif [[ "$_TOPT" == "" && -z "$*" ]];then - pkg_info - else - _not_implemented - fi -} - -pkg_tools_Rs() { - if [[ "$_TOPT" == "" ]]; then - pkg_delete -D dependencies "$@" - else - _not_implemented - fi -} - -pkg_tools_Rn() { - if [[ "$_TOPT" == "" ]];then - pkg_delete -c "$@" - else - _not_implemented - fi -} - -pkg_tools_Rns() { - _not_implemented -} - -pkg_tools_R() { - pkg_delete "$@" -} - -pkg_tools_Si() { - pkg_info "$@" -} - -pkg_tools_Sl() { - pkg_info -L "$@" -} - -pkg_tools_Suy() { - # pkg_tools doesn't really have any concept of a database - # there's actually not really any database to update, so - # this function is mostly just for convienience since on arch - # doing -Su is normally a bad thing to do since it's a partial upgrade - - pkg_tools_Su "$@" -} - -pkg_tools_Su() { - pkg_add -u "$@" -} - -pkg_tools_Sy() { - _not_implemented -} - -pkg_tools_Ss() { - if [[ -z "$*" ]];then - _not_implemented - else - pkg_info -Q "$@" - fi -} - -pkg_tools_Sc() { - # by default no cache directory is used - if [[ -z "$PKG_CACHE" ]];then - echo "You have no cache directory set, set \$PKG_CACHE for a cache directory." - elif [[ ! -d "$PKG_CACHE" ]];then - echo "You have a cache directory set, but it does not exist. Create \"$PKG_CACHE\"." - else - _removing_is_dangerous "rm -rf $PKG_CACHE/*" - fi -} - -pkg_tools_Scc() { - _not_implemented -} - -pkg_tools_S() { - pkg_add "$@" -} - - - -_portage_init() { - : -} - -portage_Qi() { - emerge --info "$@" -} - -portage_Ql() { - if [[ -x '/usr/bin/qlist' ]]; then - qlist "$@" - elif [[ -x '/usr/bin/equery' ]]; then - equery files "$@" - else - _error "'portage-utils' or 'gentoolkit' package is required to perform this opreation." - fi -} - -portage_Qo() { - if [[ -x '/usr/bin/equery' ]]; then - equery belongs "$@" - else - _error "'gentoolkit' package is required to perform this operation." - fi -} - -portage_Qc() { - emerge -p --changelog "$@" -} - -portage_Qu() { - emerge -uvN "$@" -} - -portage_Q() { - if [[ "$_TOPT" == "" ]]; then - if [[ -x '/usr/bin/eix' ]]; then - eix -I "$@" - elif [[ -x '/usr/bin/equery' ]]; then - equery list -i "$@" - else - LS_COLORS=never \ - ls -1 -d /var/db/pkg/*/* - fi - else - _not_implemented - fi -} - -portage_Rs() { - if [[ "$_TOPT" == "" ]]; then - emerge --depclean world "$@" - else - _not_implemented - fi -} - -portage_R() { - emerge --depclean "@" -} - -portage_Si() { - emerge --info "$@" -} - -portage_Suy() { - if [[ -x '/usr/bin/layman' ]]; then - layman --sync-all \ - && emerge --sync \ - && emerge -auND world "$@" - else - emerge --sync \ - && emerge -uND world "$@" - fi -} - -portage_Su() { - emerge -uND world "$@" -} - -portage_Sy() { - if [[ -x "/usr/bin/layman" ]]; then - layman --sync-all \ - && emerge --sync "$@" - else - emerge --sync "$@" - fi -} - -portage_Ss() { - if [[ -x "/usr/bin/eix" ]]; then - eix "$@" - else - emerge --search "$@" - fi -} - -portage_Sc() { - if [[ -x "/usr/bin/eclean-dist" ]]; then - eclean-dist -d -t1m -s50 -f "$@" - else - _error "'gentoolkit' package is required to perform this operation." - fi -} - -portage_Scc() { - if [[ -x "/usr/bin/eclean" ]]; then - eclean -i distfiles "$@" - else - _error "'gentoolkit' package is required to perform this operation." - fi -} - -portage_Sccc() { - rm -fv /usr/portage/distfiles/*.* -} - -portage_S() { - emerge "$@" -} - - - -_sun_tools_init() { - # The purpose of `if` is to make sure this function - # can be invoked on other system (Linux, BSD). - if [[ "$(uname)" == "SunOS" ]]; then - export GREP=/usr/xpg4/bin/grep - export AWK=nawk - fi -} - -sun_tools_Qi() { - pkginfo -l "$@" -} - -sun_tools_Ql() { - pkginfo -l "$@" -} - -sun_tools_Qo() { - $GREP "$@" /var/sadm/install/contents -} - -sun_tools_Qs() { - pkginfo | $GREP -i "$@" -} - -sun_tools_Q() { - # the dash after the pkg name is so we don't catch partial matches - # because all packages in openbsd have the format 'pkgname-pkgver' - if [[ "$_TOPT" == "q" && ! -z "$*" ]]; then - pkginfo | $GREP "$@" - elif [[ "$_TOPT" == "q" && -z "$*" ]]; then - pkginfo - else - pkginfo "$@" - fi -} - -sun_tools_R() { - pkgrm "$@" -} - -sun_tools_U() { - pkgadd "$@" -} - - - -_swupd_init() { - : -} - -swupd_Qk() { - swupd verify "$@" -} - -swupd_Qo() { - swupd search "$@" -} - -swupd_Qs() { - swupd search "$@" -} - -swupd_R() { - swupd bundle-remove "$@" -} - -swupd_Suy() { - swupd update -} - -swupd_Su() { - swupd update -} - -swupd_Sy() { - swupd search -i - swupd update -} - -swupd_Ss() { - swupd search "$@" -} - -swupd_S() { - swupd bundle-add "$@" -} - - -_tazpkg_init() { - : -} - -tazpkg_Q() { - if [[ "$_TOPT" == "q" ]]; then - tazpkg list "$@" \ - | awk '{ if (NF == 2 || NF == 3) { print $1; }}' - elif [[ "$_TOPT" == "" ]]; then - tazpkg list "$@" - else - _not_implemented - fi -} - -tazpkg_Qi() { - tazpkg info "$@" -} + # And here why `pacman` is still smart. Debian has a set of tools. + # Fedora has `yum` (and a set of add-ons). Now Fedora moves to `dnf`. + # This means that a package manager is not a heart of a system ;) + # + # _issue2pacman yum "Fedora" && return + _issue2pacman zypper "SUSE" && return + _issue2pacman pkg_tools "OpenBSD" && return + _issue2pacman pkg_tools "Bitrig" && return + _issue2pacman apk "Alpine Linux" && return + _issue2pacman opkg "OpenWrt" && return -tazpkg_Ql() { - if [[ -z "$*" ]]; then - _not_implemented - return - fi + [ -z "$_PACMAN" ] || return - if [[ "$_TOPT" == "q" ]]; then - { - tazpkg list-files "$@" - tazpkg list-config "$@" - } \ - | grep ^/ - else - tazpkg list-files "$@" - tazpkg list-config "$@" + # Prevent a loop when this script is installed on non-standard system + if [ -x "/usr/bin/pacman" ]; then + $GREP -q "_PACMAN_detect" '/usr/bin/pacman' >/dev/null 2>&1 + [ $? -ge 1 ] && _PACMAN="pacman" \ + && return fi -} -tazpkg_Sy() { - tazpkg recharge -} + [ -x "/usr/bin/apt-get" ] && _PACMAN="dpkg" && return + [ -x "/data/data/com.termux/files/usr/bin/apt-get" ] && _PACMAN="dpkg" && return + [ -x "/usr/bin/cave" ] && _PACMAN="cave" && return + [ -x "/usr/bin/dnf" ] && _PACMAN="dnf" && return + [ -x "/usr/bin/yum" ] && _PACMAN="yum" && return + [ -x "/opt/local/bin/port" ] && _PACMAN="macports" && return + [ -x "/usr/bin/emerge" ] && _PACMAN="portage" && return + [ -x "/usr/bin/zypper" ] && _PACMAN="zypper" && return + [ -x "/usr/sbin/pkg" ] && _PACMAN="pkgng" && return + # make sure pkg_add is after pkgng, FreeBSD base comes with it until converted + [ -x "/usr/sbin/pkg_add" ] && _PACMAN="pkg_tools" && return + [ -x "/usr/sbin/pkgadd" ] && _PACMAN="sun_tools" && return + [ -x "/sbin/apk" ] && _PACMAN="apk" && return + [ -x "/bin/opkg" ] && _PACMAN="opkg" && return + [ -x "/usr/bin/tazpkg" ] && _PACMAN="tazpkg" && return + [ -x "/usr/bin/swupd" ] && _PACMAN="swupd" && return -tazpkg_Su() { - tazpkg up -} + command -v brew >/dev/null && _PACMAN="homebrew" && return -tazpkg_Suy() { - tazpkg_Sy \ - && tazpkg_Su + return 1 } -tazpkg_S() { - local _forced="" - - if grep -q -- "--forced" <<<"$*"; then - _forced="--forced" - fi - - while (( $# )); do - if [[ "$1" == "--forced" ]]; then - _forced="--forced" - shift - continue - fi - - tazpkg get-install "$1" $_forced - shift - done -} +_translate_w() { -tazpkg_R() { - local _auto="" + echo "$_EOPT" | $GREP -q ":w:" || return 0 - if grep -q -- "--auto" <<<"$*"; then - _auto="--auto" - fi + local_opt= + local_ret=0 - while (( $# )); do - if [[ "$1" == "--auto" ]]; then - _auto="--auto" - shift - continue + case "$_PACMAN" in + "dpkg") local_opt="-d";; + "cave") local_opt="-f";; + "dnf") local_opt="--downloadonly";; + "macports") local_opt="fetch";; + "portage") local_opt="--fetchonly";; + "zypper") local_opt="--download-only";; + "pkgng") local_opt="fetch";; + "yum") local_opt="--downloadonly"; + if ! rpm -q 'yum-downloadonly' >/dev/null 2>&1; then + _error "'yum-downloadonly' package is required when '-w' is used." + local_ret=1 fi + ;; + "tazpkg") + _error "$_PACMAN: Use '$_PACMAN get' to download and save packages to current directory." + local_ret=1 + ;; + "apk") local_opt="fetch";; + "opkg") local_opt="--download-only";; + *) + local_opt="" + local_ret=1 - tazpkg remove "$1" $_auto - shift - done -} + _error "$_PACMAN: Option '-w' is not supported/implemented." + ;; + esac -tazpkg_Sc() { - tazpkg clean-cache + echo "$local_opt" + return "$local_ret" } -tazpkg_Scc() { - tazpkg clean-cache - cd /var/lib/tazpkg/ \ - && { - rm -fv \ - ./*.bak \ - ID \ - packages.* \ - files.list.* - } -} +_translate_debug() { + echo "$_EOPT" | $GREP -q ":v:" || return 0 -tazpkg_Ss() { - tazpkg search "$@" -} + case "$_PACMAN" in + "tazpkg") + _error "$_PACMAN: Option '-v' (debug) is not supported/implemented by tazpkg" + return 1 + ;; + esac -tazpkg_Qo() { - tazpkg search-pkgname "$@" + echo "-v" } -tazpkg_U() { - local _forced="" - - if grep -q -- "--forced" <<<"$*"; then - _forced="--forced" - fi - - while (( $# )); do - if [[ "$1" == "--forced" ]]; then - _forced="--forced" - shift - continue - fi - - tazpkg install "$1" $_forced - shift - done -} +_translate_noconfirm() { + echo "$_EOPT" | $GREP -q ":noconfirm:" || return 0 + local_opt= + local_ret=0 + case "$_PACMAN" in + # FIXME: Update environment DEBIAN_FRONTEND=noninteractive + # FIXME: There is also --force-yes for a stronger case + "dpkg") local_opt="--yes";; + "dnf") local_opt="--assumeyes";; + "yum") local_opt="--assumeyes";; + # FIXME: pacman has 'assume-yes' and 'assume-no' + # FIXME: zypper has better mode. Similar to dpkg (Debian). + "zypper") local_opt="--no-confirm";; + "pkgng") local_opt="-y";; + "tazpkg") local_opt="--auto";; + "apk") local_opt="";; + *) + local_opt="" + local_ret=1 + _error "$_PACMAN: Option '--noconfirm' is not supported/implemented." + ;; + esac -_tlmgr_init() { - : + echo "$local_opt" + return "$local_ret" } -tlmgr_Qi() { - tlmgr info --only-installed "$@" -} +_translate_all() { + local_args="" + local_debug= + local_noconfirm= -tlmgr_Qk() { - tlmgr check files -} + local_debug="$(_translate_debug)" || return 1 + local_noconfirm="$(_translate_noconfirm)" || return 1 + local_args="$(_translate_w)" || return 1 -tlmgr_Ql() { - tlmgr info --only-installed --list "$@" -} + local_args="${local_args}${local_noconfirm:+ }${local_noconfirm}" + local_args="${local_args}${local_debug:+ }${local_debug}" -tlmgr_R() { - tlmgr remove "$@" + export _EOPT="${local_args# }" } -tlmgr_S() { - tlmgr install "$@" +_print_supported_operations() { + local_pacman="$1" + printf "pacapt(%s): available operations:" "$local_pacman" + # shellcheck disable=2016 + $GREP -E "^(#_!_POSIX_# )?${local_pacman}_[^ \\t]+\\(\\)" "$0" \ + | $AWK -F '(' '{print $1}' \ + | sed -e "s/.*${local_pacman}_//g" \ + | while read -r O; do + printf " %s" "$O" + done + echo } -tlmgr_Si() { - tlmgr info "$@" +_quiet_field1() { + if [ -z "${_TOPT}" ]; then + cat + else + awk '{print $1}' + fi } -tlmgr_Sl() { - tlmgr info -} +_string_nth() { + local_idx="${1}"; shift + local_args="${*}" -tlmgr_Ss() { - tlmgr search --global "$@" + local_args="${local_args}" local_idx="${local_idx}" \ + "$AWK" 'BEGIN{printf("%s",substr(ENVIRON["local_args"],ENVIRON["local_idx"],1))}' } -tlmgr_Suy() { - tlmgr update --all +_string_less_than() { + a="${1}" b="${2}" "$AWK" 'BEGIN {exit !(ENVIRON["a"] < ENVIRON["b"]) }' } -tlmgr_U() { - tlmgr install --file "$@" -} +export _SUPPORTED_EXTERNALS=" + :conda + :tlmgr + :texlive + :gem + :npm + :pip +" +readonly _SUPPORTED_EXTERNALS +_PACMAN_found_from_script_name() { + local_tmp_name= + local_pacman= + + local_tmp_name="${0}" + # https://github.com/icy/pacapt/pull/161/files#r654800412 + case "$local_tmp_name" in + *-*) : ;; + *) return 1 ;; + esac -_yum_init() { - : -} + local_tmp_name="${local_tmp_name##*/}" # base name (remove everything before the last `/`) + local_tmp_name="${local_tmp_name%.*}" # remove extension if any (remove everything from the last `.`) + local_pacman="${local_tmp_name##*-}" # remove every thing before the last `-` -yum_Q() { - if [[ "$_TOPT" == "q" ]]; then - rpm -qa --qf "%{NAME}\\n" - elif [[ "$_TOPT" == "" ]]; then - rpm -qa --qf "%{NAME} %{VERSION}\\n" + if echo "$_SUPPORTED_EXTERNALS" \ + | "$GREP" -Eq -e ":${local_pacman}[[:space:]]*"; + then + export _PACMAN="$local_pacman" + return 0 else - _not_implemented + export _PACMAN="" + _die "Unable to guess non-system package manager ($local_pacman) from script name '$0'." fi } -yum_Qi() { - yum info "$@" -} -yum_Qs() { - rpm -qa "*${*}*" -} -yum_Ql() { - rpm -ql "$@" +_apk_init() { + : } -yum_Qo() { - rpm -qf "$@" +apk_Q() { + case "$_TOPT" in + "") + apk list --installed "$@" + ;; + "q") + apk info + ;; + *) + _not_implemented + ;; + esac } -yum_Qp() { - rpm -qp "$@" -} +apk_Qi() { + if [ "$#" -eq 0 ]; then + # shellcheck disable=SC2046 + apk info --all $(apk info) + return + fi -yum_Qc() { - rpm -q --changelog "$@" + # shellcheck disable=2086 + if apk info --installed $_TOPT "$@"; then + # shellcheck disable=2086 + apk info --all $_TOPT "$@" + else + >&2 echo ":: Error: Package not installed: '${*}'" + fi } -yum_Qu() { - yum list updates "$@" -} +apk_Ql() { + if [ "$#" -eq 0 ]; then + packages="$(apk info)" + else + packages="$*" + fi -yum_Qm() { - yum list extras "$@" + for pkg in ${packages:-}; do + apk info --contents "$pkg" \ + | awk -v pkg="$pkg" '/\// {printf("%s %s\n", pkg, $0)}' + done \ + | { + case $_TOPT in + "q") awk '{print $NF}';; + "") cat ;; + *) _not_implemented ; exit 1;; + esac + } } -yum_Rs() { - if [[ "$_TOPT" == "" ]]; then - yum erase "$@" +apk_Qo() { + if cmd="$(command -v -- "$@")"; then + apk info --who-owns -- "$cmd" else - _not_implemented + apk info --who-owns -- "$@" fi } -yum_R() { - yum erase "$@" -} - -yum_Si() { - yum info "$@" +apk_Qs() { + # shellcheck disable=2086 + apk list --installed $_TOPT "*${*}*" } -yum_Suy() { - yum update "$@" +apk_Qu() { + apk version -l '<' } -yum_Su() { - yum update "$@" +apk_R() { + # shellcheck disable=2086 + apk del $_TOPT -- "$@" } -yum_Sy() { - yum check-update "$@" +apk_Rn() { + # shellcheck disable=2086 + apk del --purge $_TOPT -- "$@" } -yum_Ss() { - yum -C search "$@" +apk_Rns() { + # shellcheck disable=2086 + apk del --purge -r $_TOPT -- "$@" } -yum_Sc() { - yum clean expire-cache "$@" +apk_Rs() { + # shellcheck disable=2086 + apk del -r $_TOPT -- "$@" } -yum_Scc() { - yum clean packages "$@" +apk_S() { + # shellcheck disable=2086 + case ${_EOPT} in + # Download only + ("fetch") shift + apk fetch $_TOPT -- "$@" ;; + (*) apk add $_TOPT -- "$@" ;; + esac } -yum_Sccc() { - yum clean all "$@" +apk_Sc() { + apk cache -v clean } -yum_S() { - yum install $_TOPT "$@" +apk_Scc() { + rm -rf /var/cache/apk/* } -yum_U() { - yum localinstall "$@" +apk_Sccc() { + apk_Scc } -yum_Sii() { - yum resolvedep "$@" +apk_Si() { + # shellcheck disable=2086 + apk info $_TOPT "$@" } - - -_zypper_init() { - : +apk_Sii() { + apk info -r -- "$@" } -zypper_Qc() { - rpm -q --changelog "$@" +apk_Sl() { + apk search -v -- "$@" } -zypper_Qi() { - zypper info "$@" +apk_Ss() { + apk_Sl "$@" } -zypper_Ql() { - rpm -ql "$@" +apk_Su() { + apk upgrade } -zypper_Qu() { - zypper list-updates "$@" +apk_Suy() { + if [ "$#" -gt 0 ]; then + apk add -U -u -- "$@" + else + apk upgrade -U -a + fi } -zypper_Qm() { - zypper search -si "$@" \ - | grep 'System Packages' +apk_Sy() { + apk update } -zypper_Qo() { - rpm -qf "$@" +apk_U() { + # shellcheck disable=2086 + apk add --allow-untrusted $_TOPT -- "$@" +} +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# _cave_init() { +#_!_POSIX_# shopt -u globstar +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# cave_Q() { +#_!_POSIX_# if [[ "$_TOPT" == "q" ]]; then +#_!_POSIX_# cave show -f "${@:-world}" \ +#_!_POSIX_# | grep -v '^$' +#_!_POSIX_# else +#_!_POSIX_# cave show -f "${@:-world}" +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# cave_Qi() { +#_!_POSIX_# cave show "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# cave_Ql() { +#_!_POSIX_# if [[ -n "$*" ]]; then +#_!_POSIX_# cave contents "$@" +#_!_POSIX_# return +#_!_POSIX_# fi +#_!_POSIX_# +#_!_POSIX_# cave show -f "${@:-world}" \ +#_!_POSIX_# | grep -v '^$' \ +#_!_POSIX_# | while read -r _pkg; do +#_!_POSIX_# if [[ "$_TOPT" == "q" ]]; then +#_!_POSIX_# cave --color no contents "$_pkg" +#_!_POSIX_# else +#_!_POSIX_# cave contents "$_pkg" +#_!_POSIX_# fi +#_!_POSIX_# done +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# cave_Qo() { +#_!_POSIX_# if cmd="$(command -v -- "$@")"; then +#_!_POSIX_# cave owner "$cmd" +#_!_POSIX_# else +#_!_POSIX_# cave owner "$@" +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# cave_Qp() { +#_!_POSIX_# _not_implemented +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# cave_Qu() { +#_!_POSIX_# if [[ -z "$*" ]];then +#_!_POSIX_# cave resolve -c world \ +#_!_POSIX_# | grep '^u.*' \ +#_!_POSIX_# | while read -r _pkg; do +#_!_POSIX_# echo "$_pkg" | cut -d'u' -f2- +#_!_POSIX_# done +#_!_POSIX_# else +#_!_POSIX_# cave resolve -c world \ +#_!_POSIX_# | grep '^u.*' \ +#_!_POSIX_# | grep -- "$@" +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# cave_Qs() { +#_!_POSIX_# cave show -f world | grep -- "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# cave_Rs() { +#_!_POSIX_# if [[ "$_TOPT" == "" ]]; then +#_!_POSIX_# cave uninstall -r "$@" \ +#_!_POSIX_# && echo "Control-C to stop uninstalling..." \ +#_!_POSIX_# && sleep 2s \ +#_!_POSIX_# && cave uninstall -xr "$@" +#_!_POSIX_# else +#_!_POSIX_# cave purge "$@" \ +#_!_POSIX_# && echo "Control-C to stop uninstalling (+ dependencies)..." \ +#_!_POSIX_# && sleep 2s \ +#_!_POSIX_# && cave purge -x "$@" +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# cave_Rn() { +#_!_POSIX_# _not_implemented +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# cave_Rns() { +#_!_POSIX_# _not_implemented +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# cave_R() { +#_!_POSIX_# cave uninstall "$@" \ +#_!_POSIX_# && echo "Control-C to stop uninstalling..." \ +#_!_POSIX_# && sleep 2s \ +#_!_POSIX_# && cave uninstall -x "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# cave_Si() { +#_!_POSIX_# cave show "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# cave_Suy() { +#_!_POSIX_# cave sync && cave resolve -c "${@:-world}" \ +#_!_POSIX_# && echo "Control-C to stop upgrading..." \ +#_!_POSIX_# && sleep 2s \ +#_!_POSIX_# && cave resolve -cx "${@:-world}" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# cave_Su() { +#_!_POSIX_# cave resolve -c "$@" \ +#_!_POSIX_# && echo "Control-C to stop upgrading..." \ +#_!_POSIX_# && sleep 2s \ +#_!_POSIX_# && cave resolve -cx "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# cave_Sy() { +#_!_POSIX_# cave sync "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# cave_Ss() { +#_!_POSIX_# cave search "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# cave_Sc() { +#_!_POSIX_# cave fix-cache "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# cave_Scc() { +#_!_POSIX_# cave fix-cache "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# cave_Sccc() { +#_!_POSIX_# #rm -fv /var/cache/paludis/* +#_!_POSIX_# _not_implemented +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# cave_S() { +#_!_POSIX_# # shellcheck disable=SC2086 +#_!_POSIX_# cave resolve $_TOPT "$@" \ +#_!_POSIX_# && echo "Control-C to stop installing..." \ +#_!_POSIX_# && sleep 2s \ +#_!_POSIX_# && cave resolve -x $_TOPT "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# cave_U() { +#_!_POSIX_# _not_implemented +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# _conda_init() { +#_!_POSIX_# : +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# conda_Q() { +#_!_POSIX_# if [[ $# -gt 0 ]]; then +#_!_POSIX_# conda list "$(python -c 'import sys; print("^" + "|".join(sys.argv[1:]) + "$")' "$@")" +#_!_POSIX_# else +#_!_POSIX_# conda list +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# conda_R() { +#_!_POSIX_# conda remove "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# conda_S() { +#_!_POSIX_# conda install "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# conda_Sc() { +#_!_POSIX_# conda clean --all "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# conda_Si() { +#_!_POSIX_# conda search "$@" --info +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# conda_Ss() { +#_!_POSIX_# conda search "*${*}*" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# conda_Suy() { +#_!_POSIX_# conda update --all "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# _dnf_init() { +#_!_POSIX_# : +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_S() { +#_!_POSIX_# # shellcheck disable=SC2086 +#_!_POSIX_# dnf install $_TOPT "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_Sc() { +#_!_POSIX_# dnf clean expire-cache "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_Scc() { +#_!_POSIX_# dnf clean packages "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_Sccc() { +#_!_POSIX_# dnf clean all "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_Si() { +#_!_POSIX_# dnf info "$@" && dnf repoquery --deplist "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_Sg() { +#_!_POSIX_# if [[ $# -gt 0 ]]; then +#_!_POSIX_# dnf group info "$@" +#_!_POSIX_# else +#_!_POSIX_# dnf group list +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_Sl() { +#_!_POSIX_# dnf list available "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_Ss() { +#_!_POSIX_# dnf search "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_Su() { +#_!_POSIX_# dnf upgrade "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_Suy() { +#_!_POSIX_# dnf upgrade "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_Sy() { +#_!_POSIX_# dnf clean expire-cache && dnf check-update +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_Q() { +#_!_POSIX_# if [[ "$_TOPT" == "q" ]]; then +#_!_POSIX_# rpm -qa --qf "%{NAME}\\n" +#_!_POSIX_# elif [[ "$_TOPT" == "" ]]; then +#_!_POSIX_# rpm -qa --qf "%{NAME} %{VERSION}\\n" +#_!_POSIX_# else +#_!_POSIX_# _not_implemented +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_Qc() { +#_!_POSIX_# rpm -q --changelog "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_Qe() { +#_!_POSIX_# dnf repoquery --userinstalled "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_Qi() { +#_!_POSIX_# dnf info --installed "$@" && dnf repoquery --deplist "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_Ql() { +#_!_POSIX_# rpm -ql "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_Qm() { +#_!_POSIX_# dnf list extras +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_Qo() { +#_!_POSIX_# if cmd="$(command -v -- "$@")"; then +#_!_POSIX_# rpm -qf "$cmd" +#_!_POSIX_# else +#_!_POSIX_# rpm -qf "$@" +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_Qp() { +#_!_POSIX_# rpm -qp "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_Qs() { +#_!_POSIX_# rpm -qa "*${*}*" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_Qu() { +#_!_POSIX_# dnf list updates "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_R() { +#_!_POSIX_# dnf remove "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dnf_U() { +#_!_POSIX_# dnf install "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# _dpkg_init() { +#_!_POSIX_# : +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dpkg_Q() { +#_!_POSIX_# if [[ "$_TOPT" == "q" ]]; then +#_!_POSIX_# dpkg -l \ +#_!_POSIX_# | grep -E '^[hi]i' \ +#_!_POSIX_# | awk '{print $2}' +#_!_POSIX_# elif [[ "$_TOPT" == "" ]]; then +#_!_POSIX_# dpkg -l "$@" \ +#_!_POSIX_# | grep -E '^[hi]i' +#_!_POSIX_# else +#_!_POSIX_# _not_implemented +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dpkg_Qi() { +#_!_POSIX_# dpkg-query -s "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dpkg_Ql() { +#_!_POSIX_# if [[ -n "$*" ]]; then +#_!_POSIX_# dpkg-query -L "$@" +#_!_POSIX_# return +#_!_POSIX_# fi +#_!_POSIX_# +#_!_POSIX_# dpkg -l \ +#_!_POSIX_# | grep -E '^[hi]i' \ +#_!_POSIX_# | awk '{print $2}' \ +#_!_POSIX_# | while read -r _pkg; do +#_!_POSIX_# if [[ "$_TOPT" == "q" ]]; then +#_!_POSIX_# dpkg-query -L "$_pkg" +#_!_POSIX_# else +#_!_POSIX_# dpkg-query -L "$_pkg" \ +#_!_POSIX_# | while read -r _line; do +#_!_POSIX_# echo "$_pkg $_line" +#_!_POSIX_# done +#_!_POSIX_# fi +#_!_POSIX_# done +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dpkg_Qo() { +#_!_POSIX_# if cmd="$(command -v -- "$@")"; then +#_!_POSIX_# dpkg-query -S "$cmd" +#_!_POSIX_# else +#_!_POSIX_# dpkg-query -S "$@" +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dpkg_Qp() { +#_!_POSIX_# dpkg-deb -I "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dpkg_Qu() { +#_!_POSIX_# apt-get upgrade --trivial-only "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dpkg_Qs() { +#_!_POSIX_# # dpkg >= 1.16.2 dpkg-query -W -f='${db:Status-Abbrev} ${binary:Package}\t${Version}\t${binary:Summary}\n' +#_!_POSIX_# dpkg-query -W -f='${Status} ${Package}\t${Version}\t${Description}\n' \ +#_!_POSIX_# | grep -E '^((hold)|(install)|(deinstall))' \ +#_!_POSIX_# | sed -r -e 's#^(\w+ ){3}##g' \ +#_!_POSIX_# | grep -Ei "${@:-.}" \ +#_!_POSIX_# | _quiet_field1 +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dpkg_Rs() { +#_!_POSIX_# if [[ "$_TOPT" == "" ]]; then +#_!_POSIX_# apt-get autoremove "$@" +#_!_POSIX_# else +#_!_POSIX_# _not_implemented +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dpkg_Rn() { +#_!_POSIX_# apt-get purge "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dpkg_Rns() { +#_!_POSIX_# apt-get --purge autoremove "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dpkg_R() { +#_!_POSIX_# apt-get remove "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dpkg_Si() { +#_!_POSIX_# apt-cache show "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dpkg_Suy() { +#_!_POSIX_# apt-get update \ +#_!_POSIX_# && apt-get upgrade "$@" \ +#_!_POSIX_# && apt-get dist-upgrade "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dpkg_Su() { +#_!_POSIX_# apt-get upgrade "$@" \ +#_!_POSIX_# && apt-get dist-upgrade "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# dpkg_Sy() { +#_!_POSIX_# apt-get update "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dpkg_Ss() { +#_!_POSIX_# local IFS=$'\n' +#_!_POSIX_# packages=($(apt-cache search "$@")) +#_!_POSIX_# for package in ${packages[@]:-} +#_!_POSIX_# do +#_!_POSIX_# name=${package%% - *} +#_!_POSIX_# desc=${package#* - } +#_!_POSIX_# dpkg-query -W "$name" > /dev/null 2>&1 +#_!_POSIX_# if [[ $? -eq 1 ]]; then +#_!_POSIX_# echo -e "package/$name \n $desc" +#_!_POSIX_# else +#_!_POSIX_# dpkg-query -W -f='package/${binary:Package} ${Version}\t[${Status}]\n ${binary:Summary}\n' "$name" +#_!_POSIX_# fi +#_!_POSIX_# done +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dpkg_Sc() { +#_!_POSIX_# apt-get clean "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dpkg_Scc() { +#_!_POSIX_# apt-get autoclean "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dpkg_S() { +#_!_POSIX_# apt-get install $_TOPT "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dpkg_U() { +#_!_POSIX_# dpkg -i "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dpkg_Sii() { +#_!_POSIX_# apt-cache rdepends "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# dpkg_Sccc() { +#_!_POSIX_# rm -fv /var/cache/apt/*.bin +#_!_POSIX_# rm -fv /var/cache/apt/archives/*.* +#_!_POSIX_# rm -fv /var/lib/apt/lists/*.* +#_!_POSIX_# apt-get autoclean +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# _homebrew_init() { +#_!_POSIX_# : +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# homebrew_Qi() { +#_!_POSIX_# brew info "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# homebrew_Ql() { +#_!_POSIX_# brew list "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# homebrew_Qo() { +#_!_POSIX_# local pkg prefix cellar +#_!_POSIX_# +#_!_POSIX_# # FIXME: What happens if the file is not exectutable? +#_!_POSIX_# cd "$(dirname -- "$(which "$@")")" || return +#_!_POSIX_# pkg="$(pwd -P)/$(basename -- "$@")" +#_!_POSIX_# prefix="$(brew --prefix)" +#_!_POSIX_# cellar="$(brew --cellar)" +#_!_POSIX_# +#_!_POSIX_# for package in "$cellar"/*; do +#_!_POSIX_# files=(${package}/*/${pkg/#$prefix\//}) +#_!_POSIX_# if [[ -e "${files[${#files[@]} - 1]}" ]]; then +#_!_POSIX_# echo "${package/#$cellar\//}" +#_!_POSIX_# break +#_!_POSIX_# fi +#_!_POSIX_# done +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# homebrew_Qc() { +#_!_POSIX_# brew log "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# homebrew_Qu() { +#_!_POSIX_# brew outdated | grep "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# homebrew_Qs() { +#_!_POSIX_# brew list | grep "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# homebrew_Q() { +#_!_POSIX_# if [[ "$_TOPT" == "" ]]; then +#_!_POSIX_# if [[ "$*" == "" ]]; then +#_!_POSIX_# brew list +#_!_POSIX_# else +#_!_POSIX_# brew list | grep "$@" +#_!_POSIX_# fi +#_!_POSIX_# else +#_!_POSIX_# _not_implemented +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# homebrew_Rs() { +#_!_POSIX_# if ! which join > /dev/null 2>&1; then +#_!_POSIX_# _die "pacapt: join binary does not exist in system." +#_!_POSIX_# fi +#_!_POSIX_# +#_!_POSIX_# if ! which sort > /dev/null 2>&1; then +#_!_POSIX_# _die "pacapt: sort binary does not exist in system." +#_!_POSIX_# fi +#_!_POSIX_# +#_!_POSIX_# if [[ -z "$*" ]]; then +#_!_POSIX_# _die "pacapt: ${FUNCNAME[0]} requires arguments" +#_!_POSIX_# fi +#_!_POSIX_# +#_!_POSIX_# for _target in "${@}"; +#_!_POSIX_# do +#_!_POSIX_# brew rm "$_target" +#_!_POSIX_# +#_!_POSIX_# while [ "$(join <(sort <(brew leaves)) <(sort <(brew deps $_target)))" != "" ] +#_!_POSIX_# do +#_!_POSIX_# brew rm $(join <(sort <(brew leaves)) <(sort <(brew deps $_target))) +#_!_POSIX_# done +#_!_POSIX_# done +#_!_POSIX_# +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# homebrew_R() { +#_!_POSIX_# brew remove "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# homebrew_Si() { +#_!_POSIX_# brew info "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# homebrew_Suy() { +#_!_POSIX_# brew update \ +#_!_POSIX_# && brew upgrade "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# homebrew_Su() { +#_!_POSIX_# brew upgrade "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# homebrew_Sy() { +#_!_POSIX_# brew update "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# homebrew_Ss() { +#_!_POSIX_# brew search "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# homebrew_Sc() { +#_!_POSIX_# brew cleanup "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# homebrew_Scc() { +#_!_POSIX_# brew cleanup -s "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# homebrew_Sccc() { +#_!_POSIX_# # See more discussion in +#_!_POSIX_# # https://github.com/icy/pacapt/issues/47 +#_!_POSIX_# +#_!_POSIX_# local _dcache +#_!_POSIX_# +#_!_POSIX_# _dcache="$(brew --cache)" +#_!_POSIX_# case "$_dcache" in +#_!_POSIX_# ""|"/"|" ") +#_!_POSIX_# _error "${FUNCNAME[0]}: Unable to delete '$_dcache'." +#_!_POSIX_# ;; +#_!_POSIX_# +#_!_POSIX_# *) +#_!_POSIX_# # FIXME: This is quite stupid!!! But it's an easy way +#_!_POSIX_# # FIXME: to avoid some warning from #shellcheck. +#_!_POSIX_# # FIXME: Please note that, $_dcache is not empty now. +#_!_POSIX_# rm -rf "${_dcache:-/x/x/x/x/x/x/x/x/x/x/x//x/x/x/x/x/}/" +#_!_POSIX_# ;; +#_!_POSIX_# esac +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# homebrew_S() { +#_!_POSIX_# # shellcheck disable=SC2086 +#_!_POSIX_# 2>&1 brew install $_TOPT "$@" \ +#_!_POSIX_# | awk '{print; if ($0 ~ /brew cask install/) { exit(126); }}' +#_!_POSIX_# ret=( ${PIPESTATUS[*]} ) +#_!_POSIX_# if [[ "${ret[1]}" == 126 ]]; then +#_!_POSIX_# echo >&2 ":: Now trying with brew/cask..." +#_!_POSIX_# # shellcheck disable=SC2086 +#_!_POSIX_# brew cask install $_TOPT "$@" +#_!_POSIX_# else +#_!_POSIX_# return "${ret[0]}" +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# _macports_init() { +#_!_POSIX_# : +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# macports_Ql() { +#_!_POSIX_# port contents "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# macports_Qo() { +#_!_POSIX_# if cmd="$(command -v -- "$@")"; then +#_!_POSIX_# port provides "$cmd" +#_!_POSIX_# else +#_!_POSIX_# port provides "$@" +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# macports_Qc() { +#_!_POSIX_# port log "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# macports_Qu() { +#_!_POSIX_# port outdated "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# macports_Rs() { +#_!_POSIX_# if [[ "$_TOPT" == "" ]]; then +#_!_POSIX_# port uninstall --follow-dependencies "$@" +#_!_POSIX_# else +#_!_POSIX_# _not_implemented +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# macports_R() { +#_!_POSIX_# port uninstall "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# macports_Si() { +#_!_POSIX_# port info "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# macports_Suy() { +#_!_POSIX_# port selfupdate \ +#_!_POSIX_# && port upgrade outdated "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# macports_Su() { +#_!_POSIX_# port upgrade outdate "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# macports_Sy() { +#_!_POSIX_# port selfupdate "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# macports_Ss() { +#_!_POSIX_# port search "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# macports_Sc() { +#_!_POSIX_# port clean --all inactive "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# macports_Scc() { +#_!_POSIX_# port clean --all installed "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# macports_S() { +#_!_POSIX_# if [[ "$_TOPT" == "fetch" ]]; then +#_!_POSIX_# port patch "$@" +#_!_POSIX_# else +#_!_POSIX_# port install "$@" +#_!_POSIX_# fi +#_!_POSIX_# } + + + +_opkg_init() { + : } -zypper_Qp() { - rpm -qip "$@" +opkg_Sy() { + opkg update } -zypper_Qs() { - zypper search --installed-only "$@" +opkg_Q() { + # shellcheck disable=SC2016 + case "$_TOPT" in + "q") + opkg list-installed "$@" | "$AWK" '{print $1}' + ;; + "") + opkg list-installed "$@" + ;; + *) + _not_implemented + ;; + esac } -zypper_Q() { - if [[ "$_TOPT" == "q" ]]; then - zypper search -i "$@" \ - | grep ^i \ - | awk '{print $3}' - elif [[ "$_TOPT" == "" ]]; then - zypper search -i "$@" - else - _not_implemented - fi +opkg_Qi() { + for pkg in $(opkg__get_local_pkgs "${@}"); do + opkg info "$pkg" + done } -zypper_Rs() { - if [[ "$_TOPT" == "s" ]]; then - zypper remove "$@" --clean-deps +opkg__get_local_pkgs() { + if [ "$#" -eq 0 ]; then + # shellcheck disable=SC2016 + opkg list-installed | "$AWK" '{print $1}' else - _not_implemented + # `opkg status` returns empty if package is not installed/removed. + # shellcheck disable=SC2016 + for pkg in "${@}"; do + opkg status "$pkg" + done \ + | "$AWK" '/^Package: / {print $NF}' fi } -zypper_R() { - zypper remove "$@" +opkg_Ql() { + for pkg in $(opkg__get_local_pkgs "${@}"); do + # shellcheck disable=SC2016 + opkg files "$pkg" \ + | PKG="$pkg" "$AWK" \ + '{ if (NR>1) {printf("%s %s\n", ENVIRON["PKG"], $0)} }' + done } -zypper_Rn() { - # Remove configuration files - while read -r file; do - if [[ -f "$file" ]]; then - rm -fv "$file" - fi - done < <(rpm -ql "$@") - - # Now remove the package per-se - zypper remove "$@" +opkg_Qo() { + if cmd="$(command -v -- "$@")"; then + opkg search "$cmd" + else + opkg search "$@" + fi } -zypper_Rs() { - if [[ "$_TOPT" == "s" ]]; then - zypper remove "$@" --clean-deps +opkg_Qs() { + if command -v sort >/dev/null; then + local_filter="sort -u" else - _not_implemented + local_filter="cat" fi -} -zypper_Rns() { - # Remove configuration files - while read -r file; do - if [[ -f "$file" ]]; then - rm -fv "$file" - fi - done < <(rpm -ql "$@") + # FIXME: opkg doesn't work with wildcard by default. + case "$@" in + *\**) local_pattern="$*" ;; + *) local_pattern="*${*}*" ;; + esac - zypper remove "$@" --clean-deps -} + opkg search "$local_pattern" \ + | ${local_filter} \ + | _quiet_field1 +} + +opkg_Qu() { + opkg list-upgradable +} + +opkg_R() { + opkg remove "$@" +} + +opkg_S() { + opkg install "$@" +} + +opkg_Si() { + # shellcheck disable=2086 + opkg list $_TOPT "$@" +} + +opkg_Sii() { + # shellcheck disable=2086 + opkg list $_TOPT "$@" + opkg whatdepends "$@" +} + +opkg_Ss() { + opkg list "$@" +} + +opkg_Su() { + opkg upgrade "$@" +} + +opkg_U() { + opkg install "$@" +} +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# _pkgng_init() { +#_!_POSIX_# : +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkgng_Qi() { +#_!_POSIX_# pkg info "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkgng_Ql() { +#_!_POSIX_# pkg info -l "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkgng_Qo() { +#_!_POSIX_# if cmd="$(command -v -- "$@")"; then +#_!_POSIX_# pkg which "$cmd" +#_!_POSIX_# else +#_!_POSIX_# pkg which "$@" +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkgng_Qp() { +#_!_POSIX_# pkg query -F "$@" '%n %v' +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkgng_Qu() { +#_!_POSIX_# pkg upgrade -n "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkgng_Q() { +#_!_POSIX_# if [[ "$_TOPT" == "q" ]]; then +#_!_POSIX_# pkg query '%n' "$@" +#_!_POSIX_# elif [[ "$_TOPT" == "" ]]; then +#_!_POSIX_# pkg query '%n %v' "$@" +#_!_POSIX_# else +#_!_POSIX_# _not_implemented +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkgng_Rs() { +#_!_POSIX_# if [[ "$_TOPT" == "" ]]; then +#_!_POSIX_# pkg remove "$@" +#_!_POSIX_# pkg autoremove +#_!_POSIX_# else +#_!_POSIX_# _not_implemented +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkgng_R() { +#_!_POSIX_# pkg remove "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkgng_Si() { +#_!_POSIX_# pkg search -S name -ef "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkgng_Suy() { +#_!_POSIX_# pkg upgrade "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkgng_Su() { +#_!_POSIX_# pkg upgrade -U "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkgng_Sy() { +#_!_POSIX_# pkg update "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkgng_Ss() { +#_!_POSIX_# pkg search "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkgng_Sc() { +#_!_POSIX_# pkg clean "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkgng_Scc() { +#_!_POSIX_# pkg clean -a "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkgng_S() { +#_!_POSIX_# if [[ "$_TOPT" == "fetch" ]]; then +#_!_POSIX_# pkg fetch "$@" +#_!_POSIX_# else +#_!_POSIX_# pkg install "$@" +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# _pkg_tools_init() { +#_!_POSIX_# : +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkg_tools_Qi() { +#_!_POSIX_# # disable searching mirrors for packages +#_!_POSIX_# export PKG_PATH= +#_!_POSIX_# pkg_info "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkg_tools_Ql() { +#_!_POSIX_# export PKG_PATH= +#_!_POSIX_# pkg_info -L "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkg_tools_Qo() { +#_!_POSIX_# export PKG_PATH= +#_!_POSIX_# if cmd="$(command -v -- "$@")"; then +#_!_POSIX_# pkg_info -E "$cmd" +#_!_POSIX_# else +#_!_POSIX_# pkg_info -E "$@" +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkg_tools_Qp() { +#_!_POSIX_# _not_implemented +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkg_tools_Qu() { +#_!_POSIX_# export PKG_PATH= +#_!_POSIX_# pkg_add -u "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkg_tools_Q() { +#_!_POSIX_# export PKG_PATH= +#_!_POSIX_# # the dash after the pkg name is so we don't catch partial matches +#_!_POSIX_# # because all packages in openbsd have the format 'pkgname-pkgver' +#_!_POSIX_# if [[ "$_TOPT" == "q" && -n "$*" ]]; then +#_!_POSIX_# pkg_info -q | grep "^${*}-" +#_!_POSIX_# elif [[ "$_TOPT" == "q" && -z "$*" ]];then +#_!_POSIX_# pkg_info -q +#_!_POSIX_# elif [[ "$_TOPT" == "" && -n "$*" ]]; then +#_!_POSIX_# pkg_info | grep "^${*}-" +#_!_POSIX_# elif [[ "$_TOPT" == "" && -z "$*" ]];then +#_!_POSIX_# pkg_info +#_!_POSIX_# else +#_!_POSIX_# _not_implemented +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkg_tools_Rs() { +#_!_POSIX_# if [[ "$_TOPT" == "" ]]; then +#_!_POSIX_# pkg_delete -D dependencies "$@" +#_!_POSIX_# else +#_!_POSIX_# _not_implemented +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkg_tools_Rn() { +#_!_POSIX_# if [[ "$_TOPT" == "" ]];then +#_!_POSIX_# pkg_delete -c "$@" +#_!_POSIX_# else +#_!_POSIX_# _not_implemented +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkg_tools_Rns() { +#_!_POSIX_# _not_implemented +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkg_tools_R() { +#_!_POSIX_# pkg_delete "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkg_tools_Si() { +#_!_POSIX_# pkg_info "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkg_tools_Sl() { +#_!_POSIX_# pkg_info -L "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkg_tools_Suy() { +#_!_POSIX_# # pkg_tools doesn't really have any concept of a database +#_!_POSIX_# # there's actually not really any database to update, so +#_!_POSIX_# # this function is mostly just for convienience since on arch +#_!_POSIX_# # doing -Su is normally a bad thing to do since it's a partial upgrade +#_!_POSIX_# +#_!_POSIX_# pkg_tools_Su "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkg_tools_Su() { +#_!_POSIX_# pkg_add -u "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkg_tools_Sy() { +#_!_POSIX_# _not_implemented +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkg_tools_Ss() { +#_!_POSIX_# if [[ -z "$*" ]];then +#_!_POSIX_# _not_implemented +#_!_POSIX_# else +#_!_POSIX_# pkg_info -Q "$@" +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkg_tools_Sc() { +#_!_POSIX_# # by default no cache directory is used +#_!_POSIX_# if [[ -z "$PKG_CACHE" ]];then +#_!_POSIX_# echo "You have no cache directory set, set \$PKG_CACHE for a cache directory." +#_!_POSIX_# elif [[ ! -d "$PKG_CACHE" ]];then +#_!_POSIX_# echo "You have a cache directory set, but it does not exist. Create \"$PKG_CACHE\"." +#_!_POSIX_# else +#_!_POSIX_# _removing_is_dangerous "rm -rf $PKG_CACHE/*" +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkg_tools_Scc() { +#_!_POSIX_# _not_implemented +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# pkg_tools_S() { +#_!_POSIX_# pkg_add "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# _portage_init() { +#_!_POSIX_# : +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# portage_Qi() { +#_!_POSIX_# emerge --info "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# portage_Ql() { +#_!_POSIX_# if [[ -x '/usr/bin/qlist' ]]; then +#_!_POSIX_# qlist "$@" +#_!_POSIX_# elif [[ -x '/usr/bin/equery' ]]; then +#_!_POSIX_# equery files "$@" +#_!_POSIX_# else +#_!_POSIX_# _error "'portage-utils' or 'gentoolkit' package is required to perform this opreation." +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# portage_Qo() { +#_!_POSIX_# if [[ -x '/usr/bin/equery' ]]; then +#_!_POSIX_# if cmd="$(command -v -- "$@")"; then +#_!_POSIX_# equery belongs "$cmd" +#_!_POSIX_# else +#_!_POSIX_# equery belongs "$@" +#_!_POSIX_# fi +#_!_POSIX_# else +#_!_POSIX_# _error "'gentoolkit' package is required to perform this operation." +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# portage_Qc() { +#_!_POSIX_# emerge -p --changelog "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# portage_Qu() { +#_!_POSIX_# emerge -uvN "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# portage_Q() { +#_!_POSIX_# if [[ "$_TOPT" == "" ]]; then +#_!_POSIX_# if [[ -x '/usr/bin/eix' ]]; then +#_!_POSIX_# eix -I "$@" +#_!_POSIX_# elif [[ -x '/usr/bin/equery' ]]; then +#_!_POSIX_# equery list -i "$@" +#_!_POSIX_# else +#_!_POSIX_# LS_COLORS=never \ +#_!_POSIX_# ls -1 -d /var/db/pkg/*/* +#_!_POSIX_# fi +#_!_POSIX_# else +#_!_POSIX_# _not_implemented +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# portage_Rs() { +#_!_POSIX_# if [[ "$_TOPT" == "" ]]; then +#_!_POSIX_# emerge --depclean world "$@" +#_!_POSIX_# else +#_!_POSIX_# _not_implemented +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# portage_R() { +#_!_POSIX_# emerge --depclean "@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# portage_Si() { +#_!_POSIX_# emerge --info "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# portage_Suy() { +#_!_POSIX_# if [[ -x '/usr/bin/layman' ]]; then +#_!_POSIX_# layman --sync-all \ +#_!_POSIX_# && emerge --sync \ +#_!_POSIX_# && emerge -auND world "$@" +#_!_POSIX_# else +#_!_POSIX_# emerge --sync \ +#_!_POSIX_# && emerge -uND world "$@" +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# portage_Su() { +#_!_POSIX_# emerge -uND world "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# portage_Sy() { +#_!_POSIX_# if [[ -x "/usr/bin/layman" ]]; then +#_!_POSIX_# layman --sync-all \ +#_!_POSIX_# && emerge --sync "$@" +#_!_POSIX_# else +#_!_POSIX_# emerge --sync "$@" +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# portage_Ss() { +#_!_POSIX_# if [[ -x "/usr/bin/eix" ]]; then +#_!_POSIX_# eix "$@" +#_!_POSIX_# else +#_!_POSIX_# emerge --search "$@" +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# portage_Sc() { +#_!_POSIX_# if [[ -x "/usr/bin/eclean-dist" ]]; then +#_!_POSIX_# eclean-dist -d -t1m -s50 -f "$@" +#_!_POSIX_# else +#_!_POSIX_# _error "'gentoolkit' package is required to perform this operation." +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# portage_Scc() { +#_!_POSIX_# if [[ -x "/usr/bin/eclean" ]]; then +#_!_POSIX_# eclean -i distfiles "$@" +#_!_POSIX_# else +#_!_POSIX_# _error "'gentoolkit' package is required to perform this operation." +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# portage_Sccc() { +#_!_POSIX_# rm -fv /usr/portage/distfiles/*.* +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# portage_S() { +#_!_POSIX_# emerge "$@" +#_!_POSIX_# } -zypper_Suy() { - zypper dup "$@" -} -zypper_Sy() { - zypper refresh "$@" -} -zypper_Sl() { - if [[ $# -eq 0 ]]; then - zypper pa -R - else - zypper pa -r "$@" +_sun_tools_init() { + # The purpose of `if` is to make sure this function + # can be invoked on other system (Linux, BSD). + if [ "$(uname)" = "SunOS" ]; then + export GREP=/usr/xpg4/bin/grep + export AWK=nawk + return 0 fi + return 1 } -zypper_Ss() { - zypper search "$@" -} - -zypper_Su() { - zypper --no-refresh dup "$@" -} - -zypper_Sc() { - zypper clean "$@" -} - -zypper_Scc() { - zypper clean "$@" +sun_tools_Qi() { + pkginfo -l "$@" } -zypper_Sccc() { - # Not way to do this in zypper - _not_implemented +sun_tools_Ql() { + pkginfo -l "$@" } -zypper_Si() { - zypper info --requires "$@" +sun_tools_Qo() { + if cmd="$(command -v -- "$@")"; then + $GREP "$cmd" /var/sadm/install/contents + else + $GREP "$@" /var/sadm/install/contents + fi } -zypper_Sii() { - # Ugly and slow, but does the trick - local packages= - - packages="$(zypper pa -R | cut -d \| -f 3 | tr -s '\n' ' ')" - for package in $packages; do - zypper info --requires "$package" \ - | grep -q "$@" && echo $package - done +sun_tools_Qs() { + pkginfo | $GREP -i "$@" } -zypper_S() { - zypper install $_TOPT "$@" +sun_tools_Q() { + # the dash after the pkg name is so we don't catch partial matches + # because all packages in openbsd have the format 'pkgname-pkgver' + if [ "$_TOPT" = "q" ] && [ -n "$*" ]; then + pkginfo | $GREP "$@" + elif [ "$_TOPT" = "q" ] && [ -z "$*" ]; then + pkginfo + else + pkginfo "$@" + fi } -zypper_Sw() { - zypper install --download-only "$@" +sun_tools_R() { + pkgrm "$@" } -zypper_U() { - zypper install "$@" +sun_tools_U() { + pkgadd "$@" } +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# _swupd_init() { +#_!_POSIX_# : +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# swupd_Qk() { +#_!_POSIX_# swupd verify "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# swupd_Qo() { +#_!_POSIX_# if cmd="$(command -v -- "$@")"; then +#_!_POSIX_# swupd search "$cmd" +#_!_POSIX_# else +#_!_POSIX_# swupd search "$@" +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# swupd_Qs() { +#_!_POSIX_# swupd search "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# swupd_R() { +#_!_POSIX_# swupd bundle-remove "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# swupd_Suy() { +#_!_POSIX_# swupd update +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# swupd_Su() { +#_!_POSIX_# swupd update +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# swupd_Sy() { +#_!_POSIX_# swupd search -i +#_!_POSIX_# swupd update +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# swupd_Ss() { +#_!_POSIX_# swupd search "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# swupd_S() { +#_!_POSIX_# swupd bundle-add "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# _tazpkg_init() { +#_!_POSIX_# : +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tazpkg_Q() { +#_!_POSIX_# if [[ "$_TOPT" == "q" ]]; then +#_!_POSIX_# tazpkg list "$@" \ +#_!_POSIX_# | awk '{ if (NF == 2 || NF == 3) { print $1; }}' +#_!_POSIX_# elif [[ "$_TOPT" == "" ]]; then +#_!_POSIX_# tazpkg list "$@" +#_!_POSIX_# else +#_!_POSIX_# _not_implemented +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tazpkg_Qi() { +#_!_POSIX_# tazpkg info "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tazpkg_Ql() { +#_!_POSIX_# if [[ -z "$*" ]]; then +#_!_POSIX_# _not_implemented +#_!_POSIX_# return +#_!_POSIX_# fi +#_!_POSIX_# +#_!_POSIX_# if [[ "$_TOPT" == "q" ]]; then +#_!_POSIX_# { +#_!_POSIX_# tazpkg list-files "$@" +#_!_POSIX_# tazpkg list-config "$@" +#_!_POSIX_# } \ +#_!_POSIX_# | grep ^/ +#_!_POSIX_# else +#_!_POSIX_# tazpkg list-files "$@" +#_!_POSIX_# tazpkg list-config "$@" +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tazpkg_Sy() { +#_!_POSIX_# tazpkg recharge +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tazpkg_Su() { +#_!_POSIX_# tazpkg up +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tazpkg_Suy() { +#_!_POSIX_# tazpkg_Sy \ +#_!_POSIX_# && tazpkg_Su +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tazpkg_S() { +#_!_POSIX_# local _forced="" +#_!_POSIX_# +#_!_POSIX_# if grep -q -- "--forced" <<<"$*"; then +#_!_POSIX_# _forced="--forced" +#_!_POSIX_# fi +#_!_POSIX_# +#_!_POSIX_# while (( $# )); do +#_!_POSIX_# if [[ "$1" == "--forced" ]]; then +#_!_POSIX_# _forced="--forced" +#_!_POSIX_# shift +#_!_POSIX_# continue +#_!_POSIX_# fi +#_!_POSIX_# +#_!_POSIX_# tazpkg get-install "$1" $_forced +#_!_POSIX_# shift +#_!_POSIX_# done +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tazpkg_R() { +#_!_POSIX_# local _auto="" +#_!_POSIX_# +#_!_POSIX_# if grep -q -- "--auto" <<<"$*"; then +#_!_POSIX_# _auto="--auto" +#_!_POSIX_# fi +#_!_POSIX_# +#_!_POSIX_# while (( $# )); do +#_!_POSIX_# if [[ "$1" == "--auto" ]]; then +#_!_POSIX_# _auto="--auto" +#_!_POSIX_# shift +#_!_POSIX_# continue +#_!_POSIX_# fi +#_!_POSIX_# +#_!_POSIX_# tazpkg remove "$1" $_auto +#_!_POSIX_# shift +#_!_POSIX_# done +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tazpkg_Sc() { +#_!_POSIX_# tazpkg clean-cache +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tazpkg_Scc() { +#_!_POSIX_# tazpkg clean-cache +#_!_POSIX_# cd /var/lib/tazpkg/ \ +#_!_POSIX_# && { +#_!_POSIX_# rm -fv \ +#_!_POSIX_# ./*.bak \ +#_!_POSIX_# ID \ +#_!_POSIX_# packages.* \ +#_!_POSIX_# files.list.* +#_!_POSIX_# } +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tazpkg_Ss() { +#_!_POSIX_# tazpkg search "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tazpkg_Qo() { +#_!_POSIX_# if cmd="$(command -v -- "$@")"; then +#_!_POSIX_# tazpkg search-pkgname "$cmd" +#_!_POSIX_# else +#_!_POSIX_# tazpkg search-pkgname "$@" +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tazpkg_U() { +#_!_POSIX_# local _forced="" +#_!_POSIX_# +#_!_POSIX_# if grep -q -- "--forced" <<<"$*"; then +#_!_POSIX_# _forced="--forced" +#_!_POSIX_# fi +#_!_POSIX_# +#_!_POSIX_# while (( $# )); do +#_!_POSIX_# if [[ "$1" == "--forced" ]]; then +#_!_POSIX_# _forced="--forced" +#_!_POSIX_# shift +#_!_POSIX_# continue +#_!_POSIX_# fi +#_!_POSIX_# +#_!_POSIX_# tazpkg install "$1" $_forced +#_!_POSIX_# shift +#_!_POSIX_# done +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# _tlmgr_init() { +#_!_POSIX_# : +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tlmgr_Qi() { +#_!_POSIX_# tlmgr info --only-installed "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tlmgr_Qk() { +#_!_POSIX_# tlmgr check files +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tlmgr_Ql() { +#_!_POSIX_# tlmgr info --only-installed --list "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tlmgr_R() { +#_!_POSIX_# tlmgr remove "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tlmgr_S() { +#_!_POSIX_# tlmgr install "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tlmgr_Si() { +#_!_POSIX_# tlmgr info "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tlmgr_Sl() { +#_!_POSIX_# tlmgr info +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tlmgr_Ss() { +#_!_POSIX_# tlmgr search --global "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tlmgr_Suy() { +#_!_POSIX_# tlmgr update --all +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# tlmgr_U() { +#_!_POSIX_# tlmgr install --file "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# _yum_init() { +#_!_POSIX_# : +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# yum_Q() { +#_!_POSIX_# if [[ "$_TOPT" == "q" ]]; then +#_!_POSIX_# rpm -qa --qf "%{NAME}\\n" +#_!_POSIX_# elif [[ "$_TOPT" == "" ]]; then +#_!_POSIX_# rpm -qa --qf "%{NAME} %{VERSION}\\n" +#_!_POSIX_# else +#_!_POSIX_# _not_implemented +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# yum_Qi() { +#_!_POSIX_# yum info "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# yum_Qs() { +#_!_POSIX_# if [[ "$_TOPT" == "q" ]]; then +#_!_POSIX_# rpm -qa --qf "%{NAME}\\n" "*${*}*" +#_!_POSIX_# elif [[ "$_TOPT" == "" ]]; then +#_!_POSIX_# rpm -qa --qf "%{NAME} %{VERSION}\\n" "*${*}*" +#_!_POSIX_# else +#_!_POSIX_# _not_implemented +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# yum_Ql() { +#_!_POSIX_# rpm -ql "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# yum_Qo() { +#_!_POSIX_# if cmd="$(command -v -- "$@")"; then +#_!_POSIX_# rpm -qf "$cmd" +#_!_POSIX_# else +#_!_POSIX_# rpm -qf "$@" +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# yum_Qp() { +#_!_POSIX_# rpm -qp "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# yum_Qc() { +#_!_POSIX_# rpm -q --changelog "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# yum_Qu() { +#_!_POSIX_# yum list updates "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# yum_Qm() { +#_!_POSIX_# yum list extras "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# yum_Rs() { +#_!_POSIX_# if [[ "$_TOPT" == "" ]]; then +#_!_POSIX_# yum erase "$@" +#_!_POSIX_# else +#_!_POSIX_# _not_implemented +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# yum_R() { +#_!_POSIX_# yum erase "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# yum_Si() { +#_!_POSIX_# yum info "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# yum_Suy() { +#_!_POSIX_# yum update "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# yum_Su() { +#_!_POSIX_# yum update "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# yum_Sy() { +#_!_POSIX_# yum check-update "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# yum_Ss() { +#_!_POSIX_# yum -C search "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# yum_Sc() { +#_!_POSIX_# yum clean expire-cache "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# yum_Scc() { +#_!_POSIX_# yum clean packages "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# yum_Sccc() { +#_!_POSIX_# yum clean all "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# yum_S() { +#_!_POSIX_# # shellcheck disable=SC2086 +#_!_POSIX_# yum install $_TOPT "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# yum_U() { +#_!_POSIX_# yum localinstall "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# yum_Sii() { +#_!_POSIX_# yum resolvedep "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# +#_!_POSIX_# _zypper_init() { +#_!_POSIX_# : +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Qc() { +#_!_POSIX_# rpm -q --changelog "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Qi() { +#_!_POSIX_# zypper info "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Ql() { +#_!_POSIX_# rpm -ql "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Qu() { +#_!_POSIX_# zypper list-updates "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Qm() { +#_!_POSIX_# zypper search -si "$@" \ +#_!_POSIX_# | grep 'System Packages' +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Qo() { +#_!_POSIX_# if cmd="$(command -v -- "$@")"; then +#_!_POSIX_# rpm -qf "$cmd" +#_!_POSIX_# else +#_!_POSIX_# rpm -qf "$@" +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Qp() { +#_!_POSIX_# rpm -qip "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Qs() { +#_!_POSIX_# zypper search --installed-only "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Q() { +#_!_POSIX_# if [[ "$_TOPT" == "q" ]]; then +#_!_POSIX_# zypper search -i "$@" \ +#_!_POSIX_# | grep ^i \ +#_!_POSIX_# | awk '{print $3}' +#_!_POSIX_# elif [[ "$_TOPT" == "" ]]; then +#_!_POSIX_# zypper search -i "$@" +#_!_POSIX_# else +#_!_POSIX_# _not_implemented +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Rs() { +#_!_POSIX_# if [[ "$_TOPT" == "s" ]]; then +#_!_POSIX_# zypper remove "$@" --clean-deps +#_!_POSIX_# else +#_!_POSIX_# _not_implemented +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_R() { +#_!_POSIX_# zypper remove "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Rn() { +#_!_POSIX_# # Remove configuration files +#_!_POSIX_# while read -r file; do +#_!_POSIX_# if [[ -f "$file" ]]; then +#_!_POSIX_# rm -fv "$file" +#_!_POSIX_# fi +#_!_POSIX_# done < <(rpm -ql "$@") +#_!_POSIX_# +#_!_POSIX_# # Now remove the package per-se +#_!_POSIX_# zypper remove "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Rs() { +#_!_POSIX_# if [[ "$_TOPT" == "s" ]]; then +#_!_POSIX_# zypper remove "$@" --clean-deps +#_!_POSIX_# else +#_!_POSIX_# _not_implemented +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Rns() { +#_!_POSIX_# # Remove configuration files +#_!_POSIX_# while read -r file; do +#_!_POSIX_# if [[ -f "$file" ]]; then +#_!_POSIX_# rm -fv "$file" +#_!_POSIX_# fi +#_!_POSIX_# done < <(rpm -ql "$@") +#_!_POSIX_# +#_!_POSIX_# zypper remove "$@" --clean-deps +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Suy() { +#_!_POSIX_# zypper dup "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Sy() { +#_!_POSIX_# zypper refresh "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Sl() { +#_!_POSIX_# if [[ $# -eq 0 ]]; then +#_!_POSIX_# zypper pa -R +#_!_POSIX_# else +#_!_POSIX_# zypper pa -r "$@" +#_!_POSIX_# fi +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Ss() { +#_!_POSIX_# zypper search "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Su() { +#_!_POSIX_# zypper --no-refresh dup "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Sc() { +#_!_POSIX_# zypper clean "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Scc() { +#_!_POSIX_# zypper clean "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Sccc() { +#_!_POSIX_# # Not way to do this in zypper +#_!_POSIX_# _not_implemented +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Si() { +#_!_POSIX_# zypper info --requires "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_Sii() { +#_!_POSIX_# # Ugly and slow, but does the trick +#_!_POSIX_# local packages= +#_!_POSIX_# +#_!_POSIX_# packages="$(zypper pa -R | cut -d \| -f 3 | tr -s '\n' ' ')" +#_!_POSIX_# for package in $packages; do +#_!_POSIX_# zypper info --requires "$package" \ +#_!_POSIX_# | grep -q "$@" && echo "$package" +#_!_POSIX_# done +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_S() { +#_!_POSIX_# # shellcheck disable=SC2086 +#_!_POSIX_# zypper install $_TOPT "$@" +#_!_POSIX_# } +#_!_POSIX_# +#_!_POSIX_# zypper_U() { +#_!_POSIX_# zypper install "$@" +#_!_POSIX_# } _validate_operation() { case "$1" in "apk_Q") ;; @@ -2085,7 +2338,6 @@ _validate_operation() { "apk_Su") ;; "apk_Suy") ;; "apk_Sy") ;; - "apk_Sw") ;; "apk_U") ;; "cave_Q") ;; "cave_Qi") ;; @@ -2125,7 +2377,6 @@ _validate_operation() { "dnf_Ss") ;; "dnf_Su") ;; "dnf_Suy") ;; - "dnf_Sw") ;; "dnf_Sy") ;; "dnf_Q") ;; "dnf_Qc") ;; @@ -2193,6 +2444,20 @@ _validate_operation() { "macports_Sc") ;; "macports_Scc") ;; "macports_S") ;; + "opkg_Sy") ;; + "opkg_Q") ;; + "opkg_Qi") ;; + "opkg_Ql") ;; + "opkg_Qo") ;; + "opkg_Qs") ;; + "opkg_Qu") ;; + "opkg_R") ;; + "opkg_S") ;; + "opkg_Si") ;; + "opkg_Sii") ;; + "opkg_Ss") ;; + "opkg_Su") ;; + "opkg_U") ;; "pkgng_Qi") ;; "pkgng_Ql") ;; "pkgng_Qo") ;; @@ -2331,7 +2596,6 @@ _validate_operation() { "zypper_Si") ;; "zypper_Sii") ;; "zypper_S") ;; - "zypper_Sw") ;; "zypper_U") ;; *) return 1 ;; esac @@ -2340,16 +2604,42 @@ _validate_operation() { set -u + unset GREP_OPTIONS : "${PACAPT_DEBUG=}" # Show what will be going : "${GREP:=grep}" # Need to update in, e.g, _sun_tools_init : "${AWK:=awk}" # Need to update in, e.g, _sun_tools_init -_sun_tools_init # Dirty tricky patch for SunOS +local_requirements="$GREP $AWK" +if ! _sun_tools_init; then + local_requirements="${local_requirements} sed" +fi + +for cmd in $local_requirements; do + if ! command -v "$cmd" >/dev/null; then + _die "pacapt requires '$cmd' but the tool is not found." + fi +done export PACAPT_DEBUG GREP AWK +if [ -z "${__PACAPT_FORKED__:-}" ]; then + if command -v bash >/dev/null; then + _debug "Switching to Bash shell" + export __PACAPT_FORKED__="yes" + readonly __PACAPT_FORKED__ + + exec bash "$0" "${@}" + fi +else + # Hey, this is very awesome strick to avoid syntax issue. + # Note: in `bocker` (github.com/icy/bocker/) we use `base64`. + eval 'source /dev/stdin < <("$GREP" '^#_!_POSIX_#' "$0" | sed -e 's/^#_!_POSIX_#//')' \ + || _die "$0: Unable to load non-POSIX definitions". +fi + + _POPT="" # primary operation _SOPT="" # secondary operation _TOPT="" # options for operations @@ -2360,10 +2650,20 @@ _PACMAN="" # name of the package manager _PACMAN_detect \ || _die "'pacapt' doesn't support your package manager." -if [[ -z "$PACAPT_DEBUG" ]]; then - [[ "$_PACMAN" != "pacman" ]] \ +if [ -z "${__PACAPT_FORKED__:-}" ]; then + case "$_PACMAN" in + "apk") ;; + "opkg") ;; + "sun_tools" ) ;; + *) + _die "pacapt($_PACMAN) library is not ready for pure-POSIX features." + esac +fi + +if [ -z "$PACAPT_DEBUG" ]; then + [ "$_PACMAN" != "pacman" ] \ || exec "/usr/bin/pacman" "$@" -elif [[ "$PACAPT_DEBUG" != "auto" ]]; then +elif [ "$PACAPT_DEBUG" != "auto" ]; then _PACMAN="$PACAPT_DEBUG" fi @@ -2380,7 +2680,7 @@ esac while :; do _args="${1-}" - [[ "${_args:0:1}" == "-" ]] || break + [ "$(printf "%.1s" "$_args")" = "-" ] || break case "${_args}" in "--help") @@ -2401,9 +2701,9 @@ while :; do esac i=1 - while [[ "$i" -lt "${#_args}" ]]; do - _opt="${_args:$i:1}" - (( i ++ )) + while [ "$i" -lt "${#_args}" ]; do + i=$(( i + 1)) + _opt="$(_string_nth "$i" "$_args")" case "$_opt" in h) @@ -2420,7 +2720,7 @@ while :; do ;; Q|S|R|U) - if [[ -n "$_POPT" && "$_POPT" != "$_opt" ]]; then + if [ -n "$_POPT" ] && [ "$_POPT" != "$_opt" ]; then _error "Only one operation may be used at a time" exit 1 fi @@ -2442,7 +2742,7 @@ while :; do # FIXME: Please check pacman(8) to see if they are really 2nd operation # e|g|i|l|m|n|o|p|s) - if [[ "$_SOPT" == '' ]]; then + if [ -z "$_SOPT" ]; then _SOPT="$_opt" continue fi @@ -2467,12 +2767,13 @@ while :; do # # In any case, the first one matters. # - if [[ "${_SOPT:0:1}" < "$_opt" ]]; then - _SOPT="${_SOPT:0:1}$_opt" - elif [[ "${_SOPT:0:1}" == "$_opt" ]]; then + f_SOPT="$(printf "%.1s" "$_SOPT")" + if _string_less_than "$f_SOPT" "$_opt"; then + _SOPT="${f_SOPT}$_opt" + elif [ "${f_SOPT}" = "$_opt" ]; then _SOPT="$_opt$_opt" else - _SOPT="$_opt${_SOPT:0:1}" + _SOPT="$_opt${f_SOPT}" fi ;; @@ -2481,7 +2782,8 @@ while :; do _TOPT="$_opt" ;; # Thanks to James Pearson u) - if [[ "${_SOPT:0:1}" == "y" ]]; then + f_SOPT="$(printf "%.1s" "$_SOPT")" + if [ "$f_SOPT" = "y" ]; then _SOPT="uy" else _SOPT="u" @@ -2489,7 +2791,8 @@ while :; do ;; y) - if [[ "${_SOPT:0:1}" == "u" ]]; then + f_SOPT="$(printf "%.1s" "$_SOPT")" + if [ "${f_SOPT}" = "y" ]; then _SOPT="uy" else _SOPT="y" @@ -2497,9 +2800,9 @@ while :; do ;; c) - if [[ "${_SOPT:0:2}" == "cc" ]]; then + if [ "$(printf "%.2s" "$_SOPT")" = "cc" ]; then _SOPT="ccc" - elif [[ "${_SOPT:0:1}" == "c" ]]; then + elif [ "$(printf "%.1s" "$_SOPT")" = "c" ]; then _SOPT="cc" else _SOPT="$_opt" @@ -2514,7 +2817,7 @@ while :; do # FIXME: If option is unknown, we will break the loop # FIXME: and this option will be used by the native program. # FIXME: break 2 - _die "pacapt: Unknown option '$_opt'." + _die "$0: Unknown option '$_opt'." ;; esac done @@ -2524,7 +2827,7 @@ while :; do # If the primary option and the secondary are known # we would break the argument detection, but for sure we will look # forward to see there is anything interesting... - if [[ -n "$_POPT" && -n "$_SOPT" ]]; then + if [ -n "$_POPT" ] && [ -n "$_SOPT" ]; then case "${1:-}" in "-w"|"--noconfirm") ;; *) break;; @@ -2533,13 +2836,13 @@ while :; do # Don't have anything from the **first** argument. Something wrong. # FIXME: This means that user must enter at least primary action # FIXME: or secondary action in the very first part... - elif [[ -z "${_POPT}${_SOPT}${_TOPT}" ]]; then + elif [ -z "${_POPT}${_SOPT}${_TOPT}" ]; then break fi done -[[ -n "$_POPT" ]] \ -|| _die "Usage: pacapt # -h for help, -P list supported functions" +[ -n "$_POPT" ] \ +|| _die "Usage: $0 # -h for help, -P list supported functions" _validate_operation "${_PACMAN}_${_POPT}${_SOPT}" \ || { @@ -2549,7 +2852,7 @@ _validate_operation "${_PACMAN}_${_POPT}${_SOPT}" \ _translate_all || exit -if [[ -n "$*" ]]; then +if [ -n "$*" ]; then case "${_POPT}${_SOPT}" in "Su"|"Sy"|"Suy") echo 1>&2 "WARNING ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" @@ -2561,11 +2864,18 @@ if [[ -n "$*" ]]; then esac fi -if [[ -n "$PACAPT_DEBUG" ]]; then +if [ -n "$PACAPT_DEBUG" ]; then echo "pacapt: $_PACMAN, p=$_POPT, s=$_SOPT, t=$_TOPT, e=$_EOPT" echo "pacapt: execute '${_PACMAN}_${_POPT}${_SOPT} $_EOPT ${*}'" - declare -f "${_PACMAN}_${_POPT}${_SOPT}" + if command -v declare >/dev/null; then + # shellcheck disable=SC3044 + declare -f "${_PACMAN}_${_POPT}${_SOPT}" + else + _error "Attempted to print the defintion of the method '${_PACMAN}_${_POPT}${_SOPT}'." + _error "However, unable to find method ('declare'). Maybe your shell is purely POSIX?" + fi else "_${_PACMAN}_init" || exit + # shellcheck disable=SC2086 "${_PACMAN}_${_POPT}${_SOPT}" $_EOPT "$@" fi