diff options
Diffstat (limited to 'ship/lib')
-rw-r--r-- | ship/lib/core | 13 | ||||
-rw-r--r-- | ship/lib/network | 3 | ||||
-rw-r--r-- | ship/lib/punani | 84 |
3 files changed, 47 insertions, 53 deletions
diff --git a/ship/lib/core b/ship/lib/core index d1a7333e..d6e01352 100644 --- a/ship/lib/core +++ b/ship/lib/core @@ -1,8 +1,13 @@ # logging -msg() { printf "$@\n" >&2 ;} -info() { msg "** $@" ;} -error() { msg "!! $@" ;} -die() { error "$@" ;exit 1;} +msg() { echo "$*" >&2; } +info() { msg "** $*"; } +error() { msg "!! $*"; } +## usage: die [REASON...] +die() { + test $# -gt 0 && error "$*" + error 'Bailing out.' + exit 1 +} exists(){ type "$1" >/dev/null 2>/dev/null; } is_root(){ test $(id -u) -eq 0 diff --git a/ship/lib/network b/ship/lib/network index 74edcbac..e1a9a31e 100644 --- a/ship/lib/network +++ b/ship/lib/network @@ -57,8 +57,7 @@ which_telnet(){ elif exists busybox;then echo `command -v busybox` telnet else - error "Cannot find telnet binary, please install either telnet-client or busybox or netcat or provided TELNET environment.\nbailing out!" - return 1 + die 'Cannot find telnet binary, please install either telnet-client or busybox or netcat or provided TELNET environment.' fi } diff --git a/ship/lib/punani b/ship/lib/punani index c07763a4..34307c42 100644 --- a/ship/lib/punani +++ b/ship/lib/punani @@ -1,60 +1,50 @@ #@include core #@include _punani_db +## usage: punani_has PACKAGE +punani_has() { + eval "_punani_${PACKER}_has \"\$1\"" +} + +## usage: punani_owner PACKAGE +punani_owner() { + eval "_punani_${PACKER}_owner \"\$1\"" +} + +## usage: punani_install PACKAGE +punani_install() { + eval "_punani_${PACKER}_install \"\$1\"" +} + +## usage: punani_remove PACKAGE +punani_remove() { + eval "_punani_${PACKER}_remove \"\$1\"" +} + +## usage: _punani_resolve_package PKGNAME _punani_resolve_package(){ - : ${PACKER?PACKER is not set,bailing out} - pkg=${1?please provide package name to resolve} - eval printf "%s" \"\${_punanidb_${PACKER}_${pkg}-}\" | grep . + eval "set -u; echo \"\${_punanidb_${PACKER}_$1}\"" 2>/dev/null +} + +## usage: _punani_select_packer +_punani_select_packer() { + for p in ${_punani_known_packers:-null}; do + exists $p && info "using $p" && PACKER=`echo $p | tr -d -` && break + done } +_punani_known_packers='pacman apt-get yum brew' +_punani_pacman_install(){ pacman --noconfirm -S --needed "$@" ;} +_punani_pacman_remove(){ pacman -Rcs "$@" ;} +_punani_pacman_has(){ pacman -Q "$1" >/dev/null;} +_punani_pacman_owner() { pacman -Qo "$1"; } _punani_aptget_install(){ apt-get -y install "$@" ;} _punani_aptget_remove(){ apt-get -y remove "$@" ;} _punani_aptget_has() { dpkg -s "$1" | grep -q "Status: install";} +_punani_aptget_owner() { dpkg-query -S "$1" | cut -d: -f1;} _punani_yum_install(){ yum -y install "$@" ;} _punani_yum_remove(){ yum -y remove "$@" ;} _punani_yum_has() { rpm -qa --qf "%{NAME}\n"| egrep "^${1}\$" >/dev/null ;} -_punani_pacman_install(){ pacman --noconfirm -S --needed "$@" ;} -_punani_pacman_remove(){ pacman -Rcs "$@" ;} -_punani_pacman_has(){ pacman -Q "$1" >/dev/null;} +_punani_yum_owner(){ rpm -qf "$1" ;} _punani_brew_install(){ brew install "$@"; } _punani_brew_remove(){ brew remove "$@";} -_punani_brew_has(){ error "not implemented"; return 1 ;} - -punani(){ - ACTION="$1"; shift - PKGS="$*" - for p in apt-get pacman yum brew;do - exists "$p" && PACKER=`printf "%s" "$p" | sed 's/-//g'` && break - done - - [ -z "${PACKER:-}" ] && error "Error 2: no known package manager found; no punani for you!" && return 1 - info "using $PACKER for install" - [ -z "$PKGS" ] && error "no PACKAGE specified." && ACTION="usage" - - - for PKG in $PKGS; do - RES="`_punani_resolve_package $PKG`" - test -z "$RES" && error "could not resolve '$PKG'; no punani for you!"&& return 23 - case "$ACTION" in - install) - eval _punani_${PACKER}_has $RES && info "$RES already installed, skipping" && continue - ! is_root && error "punani requires super-user rights for installing" && return 1 - eval _punani_${PACKER}_install $RES || error "cannot install $RES with $PACKER" - ;; - remove) - ! eval _punani_${PACKER}_has $RES && info "$RES not installed, skipping" && continue - ! is_root && error "punani requires super-user rights for removing" && return 1 - eval _punani_${PACKER}_remove $RES || error "cannot install $RES with $PACKER" - ;; - has) - if eval _punani_${PACKER}_has $RES ;then - info "$RES is installed" - else - info "$RES is not installed" - fi - ;; - *) - error "usage: punani (install|remove|has) PACKAGE..." - return 23 - esac - done -} +# TODO _punani_brew_has |