summaryrefslogtreecommitdiffstats
path: root/ship
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2013-11-19 08:35:51 +0100
committermakefu <github@syntax-fehler.de>2013-11-19 08:35:51 +0100
commit5788b95fe7834d3049df9de1009f3d8dbc34fea2 (patch)
tree76675a9579c7c5e269825bfa73d29fe5256b8afb /ship
parentc15a8d15e910a39a641b21df08e13325a0e29293 (diff)
parent6f956cfe65ee00871bc9be19b2acadabb6638a69 (diff)
Merge branch 'master' of github.com:krebscode/painload
Diffstat (limited to 'ship')
-rwxr-xr-xship/build8
-rw-r--r--ship/lib/core13
-rw-r--r--ship/lib/network3
-rw-r--r--ship/lib/punani84
-rwxr-xr-xship/src/punani46
-rwxr-xr-xship/src/remaster_arch_iso6
-rwxr-xr-xship/src/retiolum26
7 files changed, 109 insertions, 77 deletions
diff --git a/ship/build b/ship/build
index bd26482d..5863e325 100755
--- a/ship/build
+++ b/ship/build
@@ -44,8 +44,8 @@ EOF
build_info() { cat<<EOF
$1a\\
# this file was generated by //ship/build\\
-# date: $(date -u --rfc-3339=s)\\
-# version: $(git rev-parse HEAD)
+# build date: $(date -u --rfc-3339=s)\\
+# git describe: $(git describe --always --dirty --abbrev=0)
EOF
}
@@ -181,4 +181,6 @@ buildcache_add() {
### main invocation
###
-build "$@"
+if echo "$0" | grep -q '^\(.*/\)\?build$'; then
+ build "$@"
+fi
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
diff --git a/ship/src/punani b/ship/src/punani
index ceabd667..2c956f02 100755
--- a/ship/src/punani
+++ b/ship/src/punani
@@ -1,4 +1,50 @@
#! /bin/sh
#@info
#@include punani
+punani(){
+ _punani_usage='punani {install,remove,has,owner} PACKAGE...'
+ _punani_select_packer || die 'no package manager found; no punani for you!'
+
+ ACTION="$1"; shift
+
+ if test $# = 0; then
+ error 'no PACKAGE specified.'
+ die "usage: $_punani_usage"
+ fi
+
+ for PKG; do
+ RES="`_punani_resolve_package $PKG`" ||
+ die "could not resolve '$PKG'; no punani for you!"
+
+ 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
+ ;;
+ remove)
+ 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
+ ;;
+ owner)
+ punani_owner $RES
+ ;;
+ *)
+ error "bad action: $ACTION"
+ die "usage: $_punani_usage"
+ esac
+ done
+}
punani "$@"
diff --git a/ship/src/remaster_arch_iso b/ship/src/remaster_arch_iso
index 046b005b..66d5bc05 100755
--- a/ship/src/remaster_arch_iso
+++ b/ship/src/remaster_arch_iso
@@ -13,7 +13,7 @@ rootdir=$bdir/root
outdir=$bdir/out
auto_url=euer.krebsco.de/autoinstall
info "bdir is at $bdir"
-[ ! -e "$isofile" ] && die "$isofile does not exist,bailing out"
+[ ! -e "$isofile" ] && die "$isofile does not exist."
esudo "$@"
@@ -27,9 +27,7 @@ info "mounting isofile ($isofile)"
if is_root;then
mount -t iso9660 -o loop,ro $isofile $isomnt
else
- error "we are not root enough to mount the iso. Bailing Out"
- exit 1
-
+ die 'we are not root enough to mount the iso.'
fi
defer "info 'unmounting $isomnt';umount $isomnt"
diff --git a/ship/src/retiolum b/ship/src/retiolum
index d6e0efdc..ede1fd6a 100755
--- a/ship/src/retiolum
+++ b/ship/src/retiolum
@@ -38,33 +38,28 @@ main(){
if [ $IP4 -eq 0 ]; then
RAND4=1
elif ! check_ip_valid4 $IP4; then
- echo 'ip4 is invalid'
- exit 1
+ die 'ip4 is invalid'
fi
if [ $IP6 -eq 0 ]; then
RAND6=1
elif ! check_ip_valid6 $IP6; then
- echo 'ip6 is invalid'
- exit 1
+ die 'ip6 is invalid'
fi
#check if everything is installed
if ! exists awk ; then
- echo "Please install awk"
- exit 1
+ die 'Please install awk'
fi
if ! http_head $SURL >/dev/null 2>/dev/null ;then
- echo "Cannot find supernode package, check if your internet is working"
- exit 1
+ die 'Cannot find supernode package, check if your internet is working'
fi
#check if everything is installed
if [ $OS = 'android' ]; then
if ! test -e /data/data/org.poirsouille.tinc_gui/files/tincd; then
- echo "Please install tinc-gui"
- exit 1
+ die 'Please install tinc-gui'
else
TINCBIN=/data/data/org.poirsouille.tinc_gui/files/tincd
DEV="/dev/tun"
@@ -75,8 +70,7 @@ main(){
fi
elif [ $OS = 'osx' ]; then
if ! exists tincd >/dev/null; then
- echo "Please install tinc"
- exit 1
+ die 'Please install tinc'
else
TINCBIN=tincd
DEV="/dev/net/tun"
@@ -85,8 +79,7 @@ main(){
fi
else
if ! exists tincd >/dev/null; then
- echo "Please install tinc"
- exit 1
+ die 'Please install tinc'
else
TINCBIN=tincd
DEV="/dev/net/tun"
@@ -99,8 +92,7 @@ main(){
#test if tinc directory already exists
if test -e $TINCDIR/$NETNAME; then
- echo "tinc config directory $TINCDIR/$NETNAME does already exist. (backup and) delete config directory and restart"
- exit 1
+ die "tinc config directory $TINCDIR/$NETNAME does already exist. (backup and) delete config directory and restart"
fi
#get tinc-hostfiles
@@ -243,7 +235,7 @@ host2subnet()
2) FULLSUBNET=$SUBNET4.0.0 ;;
1) FULLSUBNET=$SUBNET4.0 ;;
0) FULLSUBNET=$SUBNET4 ;;
- *) echo "cannot read subnet" && exit 1;;
+ *) die 'cannot read subnet';;
esac
}