#! /bin/sh set -euf PUNANI_HOST="${PUNANI_HOST-http://euer.krebsco.de:9111}" if [ $# -ne 2 ];then echo "usage: `basename $0` (install|remove) PACKAGE" exit 23 fi ## find package manager if ! :; then : # dummy case, so the rest has a common format elif for PACKER_CMD in yum do type $PACKER_CMD 2>/dev/null 1>&2 && break; done; then INSTALL_PARAM='-y install' REMOVE_PARAM='-y remove' elif for PACKER_CMD in brew do type $PACKER_CMD 2>/dev/null 1>&2 && break; done; then INSTALL_PARAM='install' REMOVE_PARAM='remove' elif for PACKER_CMD in bauerbill packer yaourt pacman do type $PACKER_CMD 2>/dev/null 1>&2 && break; done; then INSTALL_PARAM='--noconfirm -S --needed' REMOVE_PARAM='-Rcs' elif for PACKER_CMD in aptitude apt-get do type $PACKER_CMD 2>/dev/null 1>&2 && break; done; then INSTALL_PARAM='--yes install' REMOVE_PARAM='--yes remove' else echo "Error 2: no known package manager found; no punani for you!" >&2 exit 23 fi ## find package name PKG="$2" RESOLVED=`wget -O- $PUNANI_HOST/$PACKER_CMD/$PKG 2>/dev/null || :` if [ ! "$RESOLVED" ];then echo "Error 2: could not resolve '$PKG'; no punani for you!" >&2 exit 23 fi ## dispatch case "$1" in install) exec $PACKER_CMD $INSTALL_PARAM $RESOLVED ;; remove) exec $PACKER_CMD $REMOVE_PARAM $RESOLVED ;; *) echo "usage: `basename $0` (install|remove) PACKAGE" esac