From d16f89c3016e8ff0da08a85e8d51b79b552a7c5c Mon Sep 17 00:00:00 2001 From: makefu Date: Fri, 27 Sep 2013 15:38:14 +0200 Subject: add core libs --- lib/core | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lib/core diff --git a/lib/core b/lib/core new file mode 100644 index 00000000..f6516b5e --- /dev/null +++ b/lib/core @@ -0,0 +1,32 @@ +#!/bin/sh + +# logging +msg() { printf "$@\n" >&2 ;} +info() { msg "** $@" ;} +error() { msg "!! $@" ;} +exists(){ type "$1" >/dev/null 2>/dev/null; } + +get_hostname(){ + # finds the current hostname + # if ENV HOSTN is set echo $HOSTN + # We try the following: + # $HOSTN + # $HOSTNAME + # hostname + # uci system.hostname + # /etc/hostname + # if everything fails, it returns 1 and prints 'unknown' + + if [ -n "${HOSTN:-}" ] ; then printf "${HOSTN:-}" + elif [ -n "${HOSTNAME:-}" ] ;then printf "$HOSTNAME" + elif exists hostname ; then printf "$(hostname)" + elif exists uci ; then printf "$(uci get system.@system[0].hostname)" + elif [ -e /etc/hostname ] ;then printf "$(cat /etc/hostname)" + else printf "unknown"; return 1 + fi + return 0 +} + +line_to_dot(){ + while read line; do printf .; done; +} -- cgit v1.2.3 From b4b735b6a1e14de84edd40ad2badcc1746235696 Mon Sep 17 00:00:00 2001 From: makefu Date: Fri, 27 Sep 2013 15:38:30 +0200 Subject: add network libs --- lib/network | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 lib/network diff --git a/lib/network b/lib/network new file mode 100644 index 00000000..9d7ea197 --- /dev/null +++ b/lib/network @@ -0,0 +1,49 @@ +#!/bin/sh +#include core + +anytelnet(){ + # find Telnet or similar and executes it at the end + # requires exist + # if env TELNET is set, will be trying to run this + # Tries the following things: + # telnet + # nc + # netcat + # busybox telnet + if [ -e "${TELNET:-does_not_exist}" ]; then + info"Will be using $TELNET as Telnet Client" + elif exists telnet ;then + TELNET="$(command -v telnet)" + elif exists nc ;then + TELNET="$(command -v nc)" + elif exists netcat;then + TELNET="$(command -v netcat)" + elif exists busybox;then + TELNET="$(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 + fi + $TELNET $@ +} + +send_irc(){ + ## reads from stdin, writes to IRC + ## + ## requires func: exists() anytelnet() + if [ -z "${HOSTN:-}" ]; then + HOSTN="$(get_hostname)" + info "no HOSTN given, using $HOSTN instead" + fi + IRCCHANNEL=${IRCCHANNEL:-"#krebs_incoming"} + IRCSERVER=${IRCSERVER:-"irc.freenode.net"} + IRCPORT=${IRCPORT:-6667} + NICK="${HOSTN}_$(head /dev/urandom | tr -dc "0123456789" | head -c3)" + info "starting irc connect as $NICK" + ( echo "NICK $NICK"; + echo "USER $NICK $IRCSERVER bla : $NICK"; + echo "JOIN $IRCCHANNEL"; + sleep 23; + while read line; do echo "PRIVMSG $IRCCHANNEL :$line";sleep 1;done + sleep 5; ) | anytelnet $IRCSERVER $IRCPORT 2>/dev/null | line_to_dot +} -- cgit v1.2.3 From 473981b112d89bf6401be7e164bca4b91b1cdb2b Mon Sep 17 00:00:00 2001 From: makefu Date: Fri, 27 Sep 2013 16:06:27 +0200 Subject: add is_root to core --- lib/core | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/core b/lib/core index f6516b5e..6d126142 100644 --- a/lib/core +++ b/lib/core @@ -5,7 +5,9 @@ msg() { printf "$@\n" >&2 ;} info() { msg "** $@" ;} error() { msg "!! $@" ;} exists(){ type "$1" >/dev/null 2>/dev/null; } - +is_root(){ + test $(id -u) -eq 0 +} get_hostname(){ # finds the current hostname # if ENV HOSTN is set echo $HOSTN -- cgit v1.2.3 From 95ded8a1f117b15ef246e1e3d86d25b561de5bcf Mon Sep 17 00:00:00 2001 From: makefu Date: Fri, 27 Sep 2013 16:06:38 +0200 Subject: add develop script the script exports source_all which sources all the files in the folder --- develop | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 develop diff --git a/develop b/develop new file mode 100644 index 00000000..a961f9c2 --- /dev/null +++ b/develop @@ -0,0 +1,5 @@ +#!/bin/sh +source_all(){ + LIBDIR=${1:-.} + for i in $LIBDIR/*; do . "$i"; done +} -- cgit v1.2.3 From e05fe8ad0b97776afc4c996c70b5c634b8f22456 Mon Sep 17 00:00:00 2001 From: makefu Date: Fri, 27 Sep 2013 16:07:45 +0200 Subject: porting punani to local_db from //punani/bin --- lib/punani | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 lib/punani diff --git a/lib/punani b/lib/punani new file mode 100644 index 00000000..d2bcbed2 --- /dev/null +++ b/lib/punani @@ -0,0 +1,93 @@ +#!/bin/sh +#include core + +## begin punani DB +punani_pacman_= +punani_yum_= +punani_aptget_= + +punani_pacman_git=git +punani_yum_git=git +punani_aptget_git=git-core + +punani_pacman_python2=python2 +punani_yum_python2=python +punani_aptget_python2=python + +punani_pacman_python3=python +punani_aptget_python3=python3 + +punani_pacman_hostname=inetutils +punani_aptget_hostname=hostname + +punani_pacman_hostname=inetutils +punani_aptget_hostname=hostname + +punani_pacman_make=make +punani_yum_make=make +punani_aptget_make=make + +punani_pacman_tinc=tinc +punani_yum_tinc=tinc +punani_aptget_tinc=tinc + +punani_pacman_nano=nano +punani_yum_nano=nano +punani_aptget_nano=nano +## end punani DB + +punani_resolve_package(){ + : ${PACKER_CMD?PACKER_CMD is not set,bailing out} + pkg=${1?please provide package name to resolve} + PACKER_DB=$(printf ${PACKER_CMD}| sed 's/-//g') + eval printf \"\${punani_${PACKER_DB}_${pkg}-}\" | grep . +} +punani(){ + ! is_root && error "punani requires super-user rights" && return 1 + ACTION="$1"; shift + PKGS="$*" + if ! :; then : # dummy case, so the rest has a common format + elif exists apt-get;then + PACKER_CMD='apt-get' + INSTALL_PARAM='-y install' + REMOVE_PARAM='-y remove' + elif exists pacman;then + PACKER_CMD='pacman' + INSTALL_PARAM='--noconfirm -S --needed' + REMOVE_PARAM='-Rcs' + elif exists yum;then + PACKER_CMD='yum' + INSTALL_PARAM='-y install' + REMOVE_PARAM='-y remove' + elif exists brew;then + PACKER_CMD='brew' + INSTALL_PARAM='install' + REMOVE_PARAM='remove' + else + error "Error 2: no known package manager found; no punani for you!" + return 1 + fi + info "using $PACKER_CMD for install" + RESOLVED="" + if test -n "$PKGS"; then + for PKG in $PKGS; do + RES="$(punani_resolve_package $PKG)" + test -z "$RES" && error "could not resolve '$PKG'; no punani for you!"&& return 23 + RESOLVED="${RESOLVED+$RESOLVED }$RES" + done + else + error "no PACKAGE specified." + ACTION="usage" + fi + case "$ACTION" in + install) + eval $PACKER_CMD $INSTALL_PARAM $RESOLVED || error "Cannot install $PKG!" + ;; + remove) + eval $PACKER_CMD $REMOVE_PARAM $RESOLVED || error "Cannot remove $PKG!" + ;; + *) + error "usage: punani (install|remove) PACKAGE..." + return 23 + esac +} -- cgit v1.2.3 From c88d66a0cbaa2baa258f212cb39fb940b86d2d30 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 2 Nov 2013 02:00:39 +0100 Subject: refactor punani --- lib/punani | 155 +++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 83 insertions(+), 72 deletions(-) diff --git a/lib/punani b/lib/punani index d2bcbed2..41c59a46 100644 --- a/lib/punani +++ b/lib/punani @@ -2,92 +2,103 @@ #include core ## begin punani DB -punani_pacman_= -punani_yum_= -punani_aptget_= +_punanidb_pacman_= +_punanidb_yum_= +_punanidb_aptget_= -punani_pacman_git=git -punani_yum_git=git -punani_aptget_git=git-core +_punanidb_pacman_git=git +_punanidb_yum_git=git +_punanidb_aptget_git=git-core -punani_pacman_python2=python2 -punani_yum_python2=python -punani_aptget_python2=python +_punanidb_pacman_python2=python2 +_punanidb_yum_python2=python +_punanidb_aptget_python2=python -punani_pacman_python3=python -punani_aptget_python3=python3 +_punanidb_pacman_python3=python +_punanidb_aptget_python3=python3 -punani_pacman_hostname=inetutils -punani_aptget_hostname=hostname +_punanidb_pacman_hostname=inetutils +_punanidb_aptget_hostname=hostname -punani_pacman_hostname=inetutils -punani_aptget_hostname=hostname +_punanidb_pacman_hostname=inetutils +_punanidb_aptget_hostname=hostname -punani_pacman_make=make -punani_yum_make=make -punani_aptget_make=make +_punanidb_pacman_make=make +_punanidb_yum_make=make +_punanidb_aptget_make=make -punani_pacman_tinc=tinc -punani_yum_tinc=tinc -punani_aptget_tinc=tinc +_punanidb_pacman_tinc=tinc +_punanidb_yum_tinc=tinc +_punanidb_aptget_tinc=tinc + +_punanidb_pacman_tor=tor +_punanidb_yum_tor=tor +_punanidb_aptget_tor=tor + +_punanidb_pacman_nano=nano +_punanidb_yum_nano=nano +_punanidb_aptget_nano=nano + +_punanidb_pacman_vim=vim +_punanidb_yum_vim=vim-enhanced +_punanidb_aptget_vim=vim -punani_pacman_nano=nano -punani_yum_nano=nano -punani_aptget_nano=nano ## end punani DB -punani_resolve_package(){ - : ${PACKER_CMD?PACKER_CMD is not set,bailing out} +_punani_resolve_package(){ + : ${PACKER?PACKER is not set,bailing out} pkg=${1?please provide package name to resolve} - PACKER_DB=$(printf ${PACKER_CMD}| sed 's/-//g') - eval printf \"\${punani_${PACKER_DB}_${pkg}-}\" | grep . + eval printf \"\${_punanidb_${PACKER_DB}_${pkg}-}\" | grep . } +_punani_aptget_install(){ apt-get -y install "$@" ;} +_punani_aptget_remove(){ apt-get -y remove "$@" ;} +_punani_aptget_has() { dpkg -s "$1" >/dev/null 2>/dev/null ;} +_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_brew_install(){ brew install "$@"; } +_punani_brew_remove(){ brew remove "$@";} +_punani_brew_has(){ error "not implemented"; return 1 ;} + punani(){ ! is_root && error "punani requires super-user rights" && return 1 ACTION="$1"; shift PKGS="$*" - if ! :; then : # dummy case, so the rest has a common format - elif exists apt-get;then - PACKER_CMD='apt-get' - INSTALL_PARAM='-y install' - REMOVE_PARAM='-y remove' - elif exists pacman;then - PACKER_CMD='pacman' - INSTALL_PARAM='--noconfirm -S --needed' - REMOVE_PARAM='-Rcs' - elif exists yum;then - PACKER_CMD='yum' - INSTALL_PARAM='-y install' - REMOVE_PARAM='-y remove' - elif exists brew;then - PACKER_CMD='brew' - INSTALL_PARAM='install' - REMOVE_PARAM='remove' - else - error "Error 2: no known package manager found; no punani for you!" - return 1 - fi - info "using $PACKER_CMD for install" - RESOLVED="" - if test -n "$PKGS"; then - for PKG in $PKGS; do - RES="$(punani_resolve_package $PKG)" - test -z "$RES" && error "could not resolve '$PKG'; no punani for you!"&& return 23 - RESOLVED="${RESOLVED+$RESOLVED }$RES" - done - else - error "no PACKAGE specified." - ACTION="usage" - fi - case "$ACTION" in - install) - eval $PACKER_CMD $INSTALL_PARAM $RESOLVED || error "Cannot install $PKG!" - ;; - remove) - eval $PACKER_CMD $REMOVE_PARAM $RESOLVED || error "Cannot remove $PKG!" - ;; - *) - error "usage: punani (install|remove) PACKAGE..." - return 23 - esac + PACKER_DB=$(printf ${PACKER}| sed 's/-//g') + for p in apt-get pacman yum brew;do + exists "$p" && PACKER=`printf $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 + eval _punani_${PACKER}_install $RES || error "cannot install $RES with $PACKER" + ;; + remove) + ! eval _punani_${PACKER}_has $RES && info "$RES not installed, skipping" && continue + 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 } -- cgit v1.2.3 From a1fc5b132349946dc9dc536de7a2f2812e407105 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 2 Nov 2013 02:06:53 +0100 Subject: require root for punani only when you actually do something --- lib/punani | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/punani b/lib/punani index 41c59a46..d0a16c51 100644 --- a/lib/punani +++ b/lib/punani @@ -48,7 +48,7 @@ _punanidb_aptget_vim=vim _punani_resolve_package(){ : ${PACKER?PACKER is not set,bailing out} pkg=${1?please provide package name to resolve} - eval printf \"\${_punanidb_${PACKER_DB}_${pkg}-}\" | grep . + eval printf "%s" \"\${_punanidb_${PACKER}_${pkg}-}\" | grep . } _punani_aptget_install(){ apt-get -y install "$@" ;} _punani_aptget_remove(){ apt-get -y remove "$@" ;} @@ -64,12 +64,10 @@ _punani_brew_remove(){ brew remove "$@";} _punani_brew_has(){ error "not implemented"; return 1 ;} punani(){ - ! is_root && error "punani requires super-user rights" && return 1 ACTION="$1"; shift PKGS="$*" - PACKER_DB=$(printf ${PACKER}| sed 's/-//g') for p in apt-get pacman yum brew;do - exists "$p" && PACKER=`printf $p | sed 's/-//g'` && break + 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 @@ -83,10 +81,12 @@ punani(){ 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) -- cgit v1.2.3 From 3060d3c4ce12fae2e8b754f13d0e227af2134ab5 Mon Sep 17 00:00:00 2001 From: makefu Date: Sat, 2 Nov 2013 02:43:11 +0100 Subject: add deploy script we are running hill billy style dependency resolution by cat-ing every lib into the resulting binary --- bin/punani | 4 ++++ deploy | 14 ++++++++++++++ lib/punani | 2 +- out/.placeholder | 0 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100755 bin/punani create mode 100755 deploy create mode 100644 out/.placeholder diff --git a/bin/punani b/bin/punani new file mode 100755 index 00000000..1e3fab87 --- /dev/null +++ b/bin/punani @@ -0,0 +1,4 @@ +#!/bin/sh +# include core +# include punani +punani "$@" diff --git a/deploy b/deploy new file mode 100755 index 00000000..5c282398 --- /dev/null +++ b/deploy @@ -0,0 +1,14 @@ +#!/bin/sh +set -x +cd $(dirname $0) +bindir=$PWD/bin/ +libdir=$PWD/lib/ +outdir=$PWD/out/ +# Hill-Billy style package builder +for file in `ls -1 $bindir`;do + # cat every lib and the file itself afterwards into outfile + find $libdir -type f -exec cat '{}' \; > $outdir/$file + cat $bindir/$file >> $outdir/$file + chmod 755 $outdir/$file +done + diff --git a/lib/punani b/lib/punani index d0a16c51..beaee27c 100644 --- a/lib/punani +++ b/lib/punani @@ -52,7 +52,7 @@ _punani_resolve_package(){ } _punani_aptget_install(){ apt-get -y install "$@" ;} _punani_aptget_remove(){ apt-get -y remove "$@" ;} -_punani_aptget_has() { dpkg -s "$1" >/dev/null 2>/dev/null ;} +_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 ;} diff --git a/out/.placeholder b/out/.placeholder new file mode 100644 index 00000000..e69de29b -- cgit v1.2.3