#!/bin/zsh function ssh_login () { # This function will get a passwordless authentication session setup for you. # It is a resuble function in that you can use it at the top of any script # prior to any ssh'ing to ensure you can do it passwordless. The goal was to # simply have the user enter his password once. if [ ! $1 ] ; then print "Dork, I need an destination argument" return 255 else if [ ! -e ~/.ssh/id_rsa -o ! -e ~/.ssh/id_rsa.pub ] ; then print "Dork, You need to make your keys.." print "ssh-keygen -t rsa -b 1024 -f ~/.ssh/id_rsa -C \"My comment\"" return 254 fi # print "Running with comments" ssh -o RSAAuthentication=yes -o PasswordAuthentication=no \ -o kbdinteractiveauthentication=no -o challengeresponseauthentication=no \ -o StrictHostKeyChecking=no -o CheckHostIP=no $1 date 2>&1 > /dev/null if [ $? -ne 0 ] ; then # So we can't get there - let's fix the problem.. # print "Unable to use pawwordless authentication - pushing key now" cat ${HOME}/.ssh/id_rsa.pub | ssh $1 \ 'if [ ! -d ~/.ssh ] ; then mkdir ~/.ssh/ fi chmod 700 ~/.ssh touch ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys cat >> ~/.ssh/authorized_keys' if [ $? -ne 0 ] ; then print "Fatal error - must do this manually.." return 1 else # print "Pushed key successfull - testing function" $0 $1 $2 fi else # We are good to go.. # print "Success" return 0 fi fi } function push_dotfiles(){ rsync -avz --recursive -e ssh ~/.profile $1:~/ rsync -avz --recursive -e ssh ~/.zshenv $1:~/ rsync -avz --recursive -e ssh ~/.zshrc $1:~/ rsync -avz --recursive -e ssh ~/.zsh/ $1:~/.zsh rsync -avz --recursive -e ssh ~/.vimrc $1:~/ rsync -avz --recursive -e ssh ~/.vimfavourites $1:~/ rsync -avz --recursive -e ssh ~/.vim/ $1:~/.vim rsync -avz --recursive -e ssh ~/.ssh/config $1:~/.ssh/ rsync -avz --recursive -e ssh ~/.cdsinit $1:~/ rsync -avz --recursive -e ssh ~/.cds/ $1:~/.cds/ }