From 813fef38ec5696339419b80ef23e8fb0c311df3e Mon Sep 17 00:00:00 2001 From: W-Mark Kubacki Date: Wed, 15 Oct 2014 13:21:34 +0200 Subject: [PATCH 1/3] launcher: Remove hard-coded paths to ip and ifconfig. Either we are root and the tools are in our PATH, or they don't exist. --- launcher | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) mode change 100755 => 100644 launcher diff --git a/launcher b/launcher old mode 100755 new mode 100644 index c39d8a97f..bd6f7bc62 --- a/launcher +++ b/launcher @@ -24,12 +24,12 @@ else attach_on_run="-d" fi -if [ -x /sbin/ip ]; then - docker_ip=`/sbin/ip addr show docker0 | \ +if [ -x "$(which ip 2>/dev/null)" ]; then + docker_ip=`ip addr show docker0 | \ grep 'inet ' | \ awk '{ split($2,a,"/"); print a[1] }';` else - docker_ip=`/sbin/ifconfig | \ + docker_ip=`ifconfig | \ grep -B1 "inet addr" | \ awk '{ if ( $1 == "inet" ) { print $2 } else if ( $2 == "Link" ) { printf "%s:" ,$1 } }' | \ grep docker0 | \ From c76db1ea7cb73bbf0e3bde9ab1c2558920836822 Mon Sep 17 00:00:00 2001 From: W-Mark Kubacki Date: Wed, 15 Oct 2014 13:49:09 +0200 Subject: [PATCH 2/3] launcher: Loop over possible SSH authorized key file locations. That way we can easily add support for more key types or OS distributions. --- launcher | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/launcher b/launcher index bd6f7bc62..56742d28f 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 } From 841334d9dd1432b36f7ede2ea042ff5b3c9b19c8 Mon Sep 17 00:00:00 2001 From: W-Mark Kubacki Date: Wed, 15 Oct 2014 13:52:30 +0200 Subject: [PATCH 3/3] launcher: Check for ECDSA, ED25519 keys for SSH as well as CoreOS' location. --- launcher | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/launcher b/launcher index 56742d28f..3bf9f8d60 100644 --- a/launcher +++ b/launcher @@ -129,15 +129,18 @@ fi get_ssh_pub_key() { local ${ssh_key_locations} ssh_key_locations=( + ~/.ssh/id_ed25519.pub + ~/.ssh/id_ecdsa.pub ~/.ssh/id_rsa.pub ~/.ssh/id_dsa.pub + ~core/.ssh/authorized_keys ) local $keyfile for keyfile in "${ssh_key_locations[@]}"; do if [[ -e ${keyfile} ]] ; then ssh_pub_key="$(cat ${keyfile})" - return 1 + return 0 fi done @@ -154,11 +157,11 @@ get_ssh_pub_key() { mkdir -p ~/.ssh && ssh-keygen -f ~/.ssh/id_rsa -t rsa -N '' echo ssh_pub_key="$(cat ~/.ssh/id_rsa.pub)" - return 1 + return 0 fi fi - return 0 + return 1 }