From: W-Mark Kubacki Date: Wed, 15 Oct 2014 11:49:09 +0000 (+0200) Subject: launcher: Loop over possible SSH authorized key file locations. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c76db1ea7cb73bbf0e3bde9ab1c2558920836822;p=discourse_docker.git launcher: Loop over possible SSH authorized key file locations. That way we can easily add support for more key types or OS distributions. --- diff --git a/launcher b/launcher index bd6f7bc..56742d2 100644 --- a/launcher +++ b/launcher @@ -127,24 +127,38 @@ if [ "$opt" != "--skip-prereqs" ] ; then fi get_ssh_pub_key() { + local ${ssh_key_locations} + ssh_key_locations=( + ~/.ssh/id_rsa.pub + ~/.ssh/id_dsa.pub + ) + + local $keyfile + for keyfile in "${ssh_key_locations[@]}"; do + if [[ -e ${keyfile} ]] ; then + ssh_pub_key="$(cat ${keyfile})" + return 1 + fi + done + if tty -s ; then - if [[ ! -e ~/.ssh/id_rsa.pub && ! -e ~/.ssh/id_dsa.pub ]] ; then - echo "This user has no SSH key, but a SSH key is required to access the Discourse Docker container." - read -p "Generate a SSH key? (Y/n) " -n 1 -r - if [[ $REPLY =~ ^[Nn]$ ]] ; then - echo - echo WARNING: You may not be able to log in to your container. - echo - else - echo - echo Generating SSH key - mkdir -p ~/.ssh && ssh-keygen -f ~/.ssh/id_rsa -t rsa -N '' - echo - fi + echo "This user has no SSH key, but a SSH key is required to access the Discourse Docker container." + read -p "Generate a SSH key? (Y/n) " -n 1 -r + if [[ $REPLY =~ ^[Nn]$ ]] ; then + echo + echo WARNING: You may not be able to log in to your container. + echo + else + echo + echo Generating SSH key + mkdir -p ~/.ssh && ssh-keygen -f ~/.ssh/id_rsa -t rsa -N '' + echo + ssh_pub_key="$(cat ~/.ssh/id_rsa.pub)" + return 1 fi fi - ssh_pub_key="$(cat ~/.ssh/id_rsa.pub 2>/dev/null || cat ~/.ssh/id_dsa.pub)" + return 0 }