#!/bin/bash# sm: server manager# Released into the public domain by Teran McKinney on 2011-01-04.# Thanks to sente on #bash@freenode for help with ${!var}.HOMIES=$HOME# So freedesktop don' be hatin'# Meme background: http://knowyourmeme.com/memes/haters-gonna-hate[ $XDG_CONFIG_HOME != "" ]&&HOMIES=$XDG_CONFIG_HOMEif [ "$EDITOR" == "" ]; then # Progressive awesomeness which vi &> /dev/null && EDITOR=vi which vim &> /dev/null && EDITOR=vimfiSMFILE=$HOMIES/.smKEYFILE=$HOME/.ssh/id_rsa[ -r $SMFILE ] && . "$SMFILE"function help { # ## == comment/help text combo sed '/^ ##/!d' "$0" exit}# Using these mostly in part for if the case gets functionized some day.arg1=$1arg2=$2arg3=$3argcount=$#function ac { # Check for total number of args [ $argcount != $1 ] && help}function populate { ssh-copy-id -i $KEYFILE $2 || help # Abort if this fails. echo "$1"="$2" >> $SMFILE}function smavh { # sudo make me a valid host echo $1 | cut -d '@' -f 2}case $1 in ## c: for SSH to host (c shortcut to user/host combo) c) ac 2 ssh ${!arg2} ;; ## a: to add a new IP/host with ssh-copy-id and add it to our chain ## (a shortcut hatersgonnahate@dnsresolvablehost) a) ac 3 populate $arg2 $arg3 ;; ## 6: for ping6 6) ac 2 ping6 `smavh ${!arg2}` ;; ## 4: for ping 4) ac 2 ping `smavh ${!arg2}` ;; ## m: for mtr --curses m) ac 2 mtr --curses `smavh ${!arg2}` ;; ## ls: to list servers ls) ac 1 cat "$SMFILE" ;; d) ## d: to delete entry (d shortcut user@host) ac 3 sed "/^$arg2=$arg3$/d" "$SMFILE" ;; e) ## e: to edit sm host listings by hand using $EDITOR, just be sure to ## use a shortcut=user@host format in the file $EDITOR "$SMFILE" ;; *) help ;;esac