diff --git a/init.sh b/init.sh index 74af309..41dc5a2 100755 --- a/init.sh +++ b/init.sh @@ -2,6 +2,9 @@ WA_REPO=$HOME/wa_repos + + + echo "################################################" echo " basic init of wiseadvice node " echo "################################################" @@ -34,6 +37,37 @@ function clone_repo_with_retry(){ fi } + + +function start_ssh_agent(){ + SHORT_HOST="${HOSTNAME/.*/}" + ssh_env_cache="$HOME/.ssh/environment-$SHORT_HOST" + + # Oh-my-zsh compatible bash ssh-agent start script + function _start_agent() { + if [[ -f "$ssh_env_cache" ]]; then + . "$ssh_env_cache" > /dev/null + fi + + if [[ -S "$SSH_AUTH_SOCK" ]]; then + return 0 + fi + + echo "Starting ssh-agent ..." + ssh-agent -s | sed '/^echo/d' > "$ssh_env_cache" + chmod 600 "$ssh_env_cache" + . "$ssh_env_cache" > /dev/null + } + _start_agent + + unset ssh_env_cache + unset -f _start_agent + + ssh-add ~/.ssh/deploy_key +} + + + if [ -d "$WA_REPO" ]; then echo "$WA_REPO does exist, skipping cloning" source $WA_REPO/export_client_name.sh @@ -69,18 +103,23 @@ else cat $HOME/.ssh/deploy_key.pub fi + + echo " " echo -n "ready to pull? type yes: " read -r ready_to_pull + if [ "$ready_to_pull" = "yes" ]; then + start_ssh_agent + echo "preparing" - - if grep -Fxq "git.service.wiseadvice.eu" $HOME/.ssh/config + if grep "git.service.wiseadvice.eu" $HOME/.ssh/config > /dev/null then echo "ssh configuration already set" else + echo "set ssh configuration" cat <> $HOME/.ssh/config Host git.service.wiseadvice.eu HostName git.service.wiseadvice.eu