diff options
Diffstat (limited to 'services/bin')
| -rwxr-xr-x | services/bin/services | 40 | ||||
| -rwxr-xr-x | services/bin/show-services | 31 | ||||
| -rwxr-xr-x | services/bin/update-services-pubkeys | 3 |
3 files changed, 74 insertions, 0 deletions
diff --git a/services/bin/services b/services/bin/services new file mode 100755 index 00000000..aa65e81e --- /dev/null +++ b/services/bin/services @@ -0,0 +1,40 @@ +#! /bin/sh +# usage: services [user@]hostname[:port] +# environment: +# services_identity_file path to ssh(1) identity_file +set -euf + +user=services +hostname=${1-localhost} +port=1337 + +options="${options+$options }-o ControlMaster=no" + +if test -n "${services_identity_file-}"; then + options="${options+$options }-i $services_identity_file" +fi + +if echo $hostname | grep -q @; then + user=`echo $hostname | cut -d@ -f1` + hostname=`echo $hostname | cut -d@ -f2` +fi +if echo $hostname | grep -q :; then + port=`echo $hostname | cut -d: -f2` + hostname=`echo $hostname | cut -d: -f1` +fi + +exec 3>&1 +{ + set +e + ssh -T $options $user@$hostname -p $port + echo "# Exit:$?" >&2 +} 2>&1 1>&3 | { + err="`cat`" + code=`echo "$err" | sed -n 's/^# Exit:\([0-9]\+\)/\1/p'` + echo "$err" | sed ' + /^Connection to '$hostname' closed/d + /^Shared connection to '$hostname' closed/d + /^# Exit:/d + ' >&2 + exit $code +} diff --git a/services/bin/show-services b/services/bin/show-services new file mode 100755 index 00000000..e94eb7c8 --- /dev/null +++ b/services/bin/show-services @@ -0,0 +1,31 @@ +#!/bin/bash + +set -euf +cd $(dirname $(readlink -f $0)) +usage(){ + cat <<EOF +usage: $0 [pubkey-file] [bootstrap-file] + if pubkey-file is "" it will be skipped. + + e.g.: + $0 "" ../path/to/other/bootstrap +EOF + +} +pubfile=${1:-} +bootfile=${2:-../etc/services/bootstrap} + +for i in `cat $bootfile`; do + # retard uriparsing but good enough for our use case + netloc=${i##*//} + host=${netloc%%:*} + port=${netloc##*:} + [ "$port" == "$host" ] && port=1337 + echo $netloc + pubarg="${pubfile:+-i $pubfile}" + printf "[32m" + ssh ${pubarg} "services@$host" -p "$port" \ + -o PasswordAuthentication=no 2>/dev/null||: + printf "[0m" +done + diff --git a/services/bin/update-services-pubkeys b/services/bin/update-services-pubkeys new file mode 100755 index 00000000..9936c402 --- /dev/null +++ b/services/bin/update-services-pubkeys @@ -0,0 +1,3 @@ +#!/bin/sh +KREBS_ROOT="${KREBS_ROOT:-/krebs}" +ssh $1 -t "cd ${KREBS_ROOT};git pull origin master;sudo -u services make -C $KREBS_ROOT/services ssh_authorized_keys" |
