summaryrefslogtreecommitdiffstats
path: root/ship
diff options
context:
space:
mode:
authortv <tv@nomic.retiolum>2013-11-14 13:35:52 +0100
committertv <tv@nomic.retiolum>2013-11-14 13:35:52 +0100
commit0fbc23c61956c9e208217f32d6a8e233b6e0f96e (patch)
treea2559c8afe83a4237b38c5ab89ab2dcc5aa38495 /ship
parentfb6e147d3ccc17a79cbb2bd91d154b6d9570228d (diff)
ship punani: move user interface to top of file
Diffstat (limited to 'ship')
-rw-r--r--ship/lib/punani114
1 files changed, 59 insertions, 55 deletions
diff --git a/ship/lib/punani b/ship/lib/punani
index 8efa9e8d..dc55c256 100644
--- a/ship/lib/punani
+++ b/ship/lib/punani
@@ -1,45 +1,9 @@
#@include core
#@include _punani_db
-## usage: _punani_resolve_package PKGNAME
-_punani_resolve_package(){
- eval "set -u; echo \"\${_punanidb_${PACKER}_$1}\"" 2>/dev/null
-}
-
-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_aptget_install(){ apt-get -y install "$@" ;}
-_punani_aptget_remove(){ apt-get -y remove "$@" ;}
-_punani_aptget_has() { dpkg -s "$1" | grep -q "Status: install";}
-_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_brew_install(){ brew install "$@"; }
-_punani_brew_remove(){ brew remove "$@";}
-_punani_brew_has(){ error "not implemented"; return 1 ;}
-
-## usage: _punani_has PACKAGE
-_punani_has() {
- eval "_punani_${PACKER}_has \"\$1\""
-}
-
-## usage: _punani_install PACKAGE
-_punani_install() {
- eval "_punani_${PACKER}_install \"\$1\""
-}
-
-## usage: _punani_remove PACKAGE
-_punani_remove() {
- eval "_punani_${PACKER}_remove \"\$1\""
-}
-
_punani_usage='punani {install,remove,has} PACKAGE...'
punani(){
- for p in ${KNOWN_PACKERS:-null}; do
- exists $p && info "using $p" && PACKER=`echo $p | tr -d -` && break
- done || die 'Error 2: no package manager found; no punani for you!'
+ __punani_select_packer || die 'no package manager found; no punani for you!'
ACTION="$1"; shift
@@ -54,29 +18,69 @@ punani(){
case "$ACTION" in
install)
- if _punani_has $RES; then
- info "$RES already installed, skipping"
- else
- _punani_install $RES || error "cannot install $RES with $PACKER"
- fi
- ;;
+ if _punani_has $RES; then
+ info "$RES already installed, skipping"
+ else
+ _punani_install $RES || error "cannot install $RES with $PACKER"
+ fi
+ ;;
remove)
- if ! _punani_has $RES; then
- info "$RES not installed, skipping"
- else
- _punani_remove $RES || error "cannot install $RES with $PACKER"
- fi
- ;;
+ if ! _punani_has $RES; then
+ info "$RES not installed, skipping"
+ else
+ _punani_remove $RES || error "cannot install $RES with $PACKER"
+ fi
+ ;;
has)
- if _punani_has $RES; then
- info "$RES is installed"
- else
- info "$RES is not installed"
- fi
- ;;
+ if _punani_has $RES; then
+ info "$RES is installed"
+ else
+ info "$RES is not installed"
+ fi
+ ;;
*)
error "bad action: $ACTION"
die "usage: $_punani_usage"
esac
done
}
+
+## usage: _punani_has PACKAGE
+_punani_has() {
+ eval "_punani_${PACKER}_has \"\$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(){
+ 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_aptget_install(){ apt-get -y install "$@" ;}
+_punani_aptget_remove(){ apt-get -y remove "$@" ;}
+_punani_aptget_has() { dpkg -s "$1" | grep -q "Status: install";}
+_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_brew_install(){ brew install "$@"; }
+_punani_brew_remove(){ brew remove "$@";}
+_punani_brew_has(){ error "not implemented"; return 1 ;}