From 01a921db85eea358810b682a91374eb4eb94a8fa Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Mon, 8 Dec 2014 20:51:26 -0800 Subject: [PATCH] add_authorized_key_to_host --- dotfiles/lib/shellenv/functions.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/dotfiles/lib/shellenv/functions.sh b/dotfiles/lib/shellenv/functions.sh index ab21fe65..7bdd4306 100644 --- a/dotfiles/lib/shellenv/functions.sh +++ b/dotfiles/lib/shellenv/functions.sh @@ -292,3 +292,19 @@ function refresh_config { source ~/.zshenv source ~/.zshrc } + +function file_ends_with_newline { + [[ $(tail -c1 "$1" | wc -l) -gt 0 ]] +} + +function add_authorized_key_to_host { + local command='test -e ~/.ssh/authorized_keys && [[ $(tail -c1 ~/.ssh/authorized_keys | wc -l) -gt 0 ]] || echo "\n" >> ~/.ssh/authorized_keys;'"echo $(cat ~/.ssh/id_rsa.pub) >> ~/.ssh/authorized_keys" + echo "Running:" + echo $command + ssh $1 "$command" +} + +function add_ssh_key { + [[ $(tail -c1 ~/.ssh/authorized_keys | wc -l) -gt 0 ]] || echo "\n" >> ~/.ssh/authorized_keys; + echo $1 >> ~/.ssh/authorized_keys; +}