diff --git a/bin/setup-server b/bin/setup-server index bdf71f1..9872269 100755 --- a/bin/setup-server +++ b/bin/setup-server @@ -8,40 +8,59 @@ function red() { echo -e "$RED$*$NORMAL"; } function green() { echo -e "$GREEN$*$NORMAL"; } function yellow() { echo -e "$YELLOW$*$NORMAL"; } -if [ ! $# == 2 ]; then - echo "Usage: $0 " +if [ $# -lt 1 ]; then + echo "Usage: $0 [friendly-name] [user]" + echo "Example: $0 127.0.0.1 server-name $USER" + echo + echo "Afterwards you can login with: ssh server-name" exit 1; fi -USER=$1 -HOST=$2 +HOST=$1 +NAME=$2 +USERNAME=$3 + IP=`dig +short $HOST` +if [ -z "$USERNAME" ]; then + USERNAME=$USER +fi + if [ -z "$IP" ]; then IP=$HOST fi -grep "Host $HOST" ~/.ssh/config 2>&1 > /dev/null +if [ -z "$NAME" ]; then + NAME=$HOST +fi + +yellow "Setting up server $USERNAME@$HOST with name '$NAME'" + +grep "Host $NAME" ~/.ssh/config 2>&1 > /dev/null if [ 0 -eq $? ]; then - echo $HOST is already in .ssh/config + echo $NAME is already in .ssh/config else echo Adding server to .ssh/config... cat >> ~/.ssh/config <