Skip to content

Instantly share code, notes, and snippets.

@cwage
Created July 14, 2014 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwage/8320281f527656b39793 to your computer and use it in GitHub Desktop.
Save cwage/8320281f527656b39793 to your computer and use it in GitHub Desktop.
#!/bin/sh
if [ $# -ne 2 ]
then
echo "Usage: $0 <server> <key>"
exit 1
fi
WHERE=$1
KEY=$2
# If we have an ssh public key, let's make sure our remote host has it.
if [ -f ~/.ssh/$KEY.pub ]; then
cat ~/.ssh/$KEY.pub | ssh $WHERE '
WHERE=`mktemp /tmp/key.XXXXXXXX`;
cat > $WHERE;
if [ ! -d ~/.ssh/ ]; then
mkdir ~/.ssh/;
fi
if [ ! -f ~/.ssh/authorized_keys ]; then
cp $WHERE ~/.ssh/authorized_keys;
else
cat $WHERE ~/.ssh/authorized_keys | sort | uniq > ~/.ssh/authorized_keys;
fi
chmod -R og-rwx ~/.ssh;
rm -rf $WHERE;'
fi
# Copy over our files, as well as this script
ssh $WHERE '
if [ ! -d ~/bin ]; then
mkdir ~/bin
fi'
scp ~/bin/assimilate.sh $WHERE:~/bin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment