From fcc04c9c51f229aeaa70f8ccce9f26e2872a35b3 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Fri, 8 May 2009 19:03:30 +0000 Subject: Split out functions git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@388 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede --- zshfunc/fpr | 8 +++++++ zshfunc/md | 6 +++++ zshfunc/reinit-debian-samhain | 8 +++++++ zshfunc/reinit-debian-samhain-one | 33 +++++++++++++++++++++++++++ zshfunc/sd | 8 +++++++ zshfunc/upgrade-debian-hosts | 15 ++++++++++++ zshfunc/upgrade-debian-samhain | 48 +++++++++++++++++++++++++++++++++++++++ zshfunc/upgrade-porter-chroots | 11 +++++++++ zshfunc/upgrade-systems | 17 ++++++++++++++ 9 files changed, 154 insertions(+) create mode 100644 zshfunc/fpr create mode 100644 zshfunc/md create mode 100644 zshfunc/reinit-debian-samhain create mode 100644 zshfunc/reinit-debian-samhain-one create mode 100644 zshfunc/sd create mode 100644 zshfunc/upgrade-debian-hosts create mode 100644 zshfunc/upgrade-debian-samhain create mode 100644 zshfunc/upgrade-porter-chroots create mode 100644 zshfunc/upgrade-systems (limited to 'zshfunc') diff --git a/zshfunc/fpr b/zshfunc/fpr new file mode 100644 index 0000000..1d53d03 --- /dev/null +++ b/zshfunc/fpr @@ -0,0 +1,8 @@ +## vim:ft=zsh:foldmethod=marker + +fpr() { + ( + ssh-keygen -r '' -f =( ssh-keyscan -t rsa $1 2>/dev/null | sed -e 's/^[^ ]* //'); + ssh-keygen -r '' -f =( ssh-keyscan -t dsa $1 2>/dev/null | sed -e 's/^[^ ]* //'); + ) | sed -e 's/^[^ ]* //' +} diff --git a/zshfunc/md b/zshfunc/md new file mode 100644 index 0000000..1055e77 --- /dev/null +++ b/zshfunc/md @@ -0,0 +1,6 @@ +## vim:ft=zsh:foldmethod=marker + +md() { + DIR="$1" + mkdir "$1" && cd "$1" +} diff --git a/zshfunc/reinit-debian-samhain b/zshfunc/reinit-debian-samhain new file mode 100644 index 0000000..9880a1e --- /dev/null +++ b/zshfunc/reinit-debian-samhain @@ -0,0 +1,8 @@ +## vim:ft=zsh:foldmethod=marker + +reinit-debian-samhain() { + for i in $DEBHOSTS; do + mkdir hosts/$i 2> /dev/null || continue; + reinit-debian-samhain-one $i + done +} diff --git a/zshfunc/reinit-debian-samhain-one b/zshfunc/reinit-debian-samhain-one new file mode 100644 index 0000000..c4490bb --- /dev/null +++ b/zshfunc/reinit-debian-samhain-one @@ -0,0 +1,33 @@ +## vim:ft=zsh:foldmethod=marker + +reinit-debian-samhain-one() { + host=$1 + if [ "$host" = "${host%%.debian.org}" ]; then + host="$host.debian.org" + fi + echo $host + preexec $host; + ssh $host -t ' + check() { + sudo /usr/sbin/samhain -t check -i -p err -s none -l none -m none + }; + if [ -x /usr/sbin/samhain ]; then + t="`tempfile`"; + trap "rm -f $t" 0 1 2 5 15; + check > "$t" 2>&1; + if [ "`grep "^CRIT" "$t" | wc -l`" != 0 ]; then + echo "samhain db errors found:"; + sed -e "s/.*path=<\([^>]*\)>, .*/\1/" "$t"; + echo; + echo "Enter 'y' to continue upgrade and update samhaindb for `hostname`"; + read ans; + [ "$ans" = "y" ] || exit; + + echo Updating samhain db... + sudo samhain --foreground -t update + grep -q OK /var/cache/dsa/nagios/samhain || sudo dsa-update-samhain-status + echo done. + fi; + fi + '; +} diff --git a/zshfunc/sd b/zshfunc/sd new file mode 100644 index 0000000..8805b6f --- /dev/null +++ b/zshfunc/sd @@ -0,0 +1,8 @@ +## vim:ft=zsh:foldmethod=marker + +sd() { + fp=$( wget -q -O - http://tor.noreply.org:80/tor/status/authority | \ + awk '$1 == "r" && $2 == "'$1'" {printf "%s===", $3}' | \ + perl -MMIME::Base64 -e "print unpack(\"H*\", decode_base64(<>)),\"\n\"" ) + echo wget -q -O - http://tor.noreply.org:80/tor/server/fp/$fp +} diff --git a/zshfunc/upgrade-debian-hosts b/zshfunc/upgrade-debian-hosts new file mode 100644 index 0000000..b288b53 --- /dev/null +++ b/zshfunc/upgrade-debian-hosts @@ -0,0 +1,15 @@ +## vim:ft=zsh:foldmethod=marker + +upgrade-debian-hosts() { + cd + for i in $DEBHOSTS; do + mkdir hosts/$i 2>/dev/null || continue; + echo $i; + preexec $i; + ssh $i -t ' + sudo apt-get update && + sudo apt-get dist-upgrade && + sudo apt-get clean + '; + done +} diff --git a/zshfunc/upgrade-debian-samhain b/zshfunc/upgrade-debian-samhain new file mode 100644 index 0000000..be5dc7b --- /dev/null +++ b/zshfunc/upgrade-debian-samhain @@ -0,0 +1,48 @@ +## vim:ft=zsh:foldmethod=marker + +upgrade-debian-samhain() { + for i in $DEBHOSTS; do + mkdir hosts/$i 2> /dev/null || continue; + echo $i + preexec $i; + ssh $i -t ' + didsudo=0 + check() { + sudo /usr/sbin/samhain -t check -i -p err -s none -l none -m none + }; + reinit() { + if [ "`check 2>&1 | grep "^CRIT" | wc -l`" != 0 ]; then + echo Updating samhain db... + sudo samhain --foreground -t update + didsudo=1 + echo done. + fi + } + if [ -x /usr/sbin/samhain ]; then + t="`tempfile`"; + trap "rm -f $t" 0 1 2 5 15; + check > "$t" 2>&1; + if [ "`grep "^CRIT" "$t" | wc -l`" != 0 ]; then + echo "samhain db errors found:"; + sed -e "s/.*path=<\([^>]*\)>, .*/\1/" "$t"; + echo; + echo "Enter 'y' to continue upgrade and update samhaindb for `hostname`"; + read ans; + [ "$ans" = "y" ] || exit; + fi; + fi + sudo apt-get update && + sudo apt-get dist-upgrade && + sudo apt-get clean && + [ -x /usr/sbin/samhain ] && reinit + if [ "$didsudo" = 1 ]; then + echo Updating nagios status + echo "apt" + sudo /usr/sbin/dsa-update-apt-status + echo "samhain" + grep -q OK /var/cache/dsa/nagios/samhain || sudo dsa-update-samhain-status + echo done. + fi + '; + done +} diff --git a/zshfunc/upgrade-porter-chroots b/zshfunc/upgrade-porter-chroots new file mode 100644 index 0000000..7f22060 --- /dev/null +++ b/zshfunc/upgrade-porter-chroots @@ -0,0 +1,11 @@ +## vim:ft=zsh:foldmethod=marker + +upgrade-porter-chroots() { + cd + for i in $DEBPORTERHOSTS; do + mkdir hosts/chroot-$i 2>/dev/null || continue; + echo $i; + preexec $i; + ssh $i -t 'sudo /usr/sbin/upgrade-porter-chroots' + done +} diff --git a/zshfunc/upgrade-systems b/zshfunc/upgrade-systems new file mode 100644 index 0000000..071c8dc --- /dev/null +++ b/zshfunc/upgrade-systems @@ -0,0 +1,17 @@ +## vim:ft=zsh:foldmethod=marker + +upgrade-systems() { + cd + for i in $HOSTS; do + mkdir hosts/$i 2>/dev/null || continue; + echo $i; + preexec $i; + ssh $i -t 'apt-get update && + if [ -e /usr/bin/apt-get.distrib ]; then + aptitude dist-upgrade; + else + apt-get dist-upgrade; + fi && + apt-get clean'; + done +} -- cgit v1.2.3