aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-10-19 16:13:53 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-10-19 16:13:53 +0200
commit93ec90a0347a7554e4abea36de8aa70b5b954c3d (patch)
tree66f624d61436e1e83d2c81cb4a15ed786bff58e4 /scripts
parent2a35ea64a1c3c616eb69d4d78e907fbdbae7529a (diff)
Support case when .ssh and default key dont exist.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/xds-docker-create-container.sh11
1 files changed, 6 insertions, 5 deletions
diff --git a/scripts/xds-docker-create-container.sh b/scripts/xds-docker-create-container.sh
index 71f4b03..c3c951d 100755
--- a/scripts/xds-docker-create-container.sh
+++ b/scripts/xds-docker-create-container.sh
@@ -171,11 +171,12 @@ while [ $res -ne 0 ] && [ $count -le $max ]; do
done
echo
-ssh-keygen -R "[localhost]:$SSH_PORT" -f ~/.ssh/known_hosts
-docker exec ${NAME} bash -c "mkdir -p /home/$DOCKER_USER/.ssh"
-docker cp ~/.ssh/id_rsa.pub ${NAME}:/home/$DOCKER_USER/.ssh/authorized_keys
-docker exec ${NAME} bash -c "chown $DOCKER_USER:$DOCKER_USER -R /home/$DOCKER_USER/.ssh ;chmod 0700 /home/$DOCKER_USER/.ssh; chmod 0600 /home/$DOCKER_USER/.ssh/*"
-ssh -o StrictHostKeyChecking=no -p $SSH_PORT $DOCKER_USER@localhost exit
+[ -f ~/.ssh/known_hosts ] && { ssh-keygen -R "[localhost]:$SSH_PORT" -f ~/.ssh/known_hosts || exit 1; }
+[ ! -f ~/.ssh/id_rsa.pub ] && { ssh-keygen -t rsa -f ~/.ssh/id_rsa -P "" > /dev/null || exit 1; }
+docker exec ${NAME} bash -c "mkdir -p /home/$DOCKER_USER/.ssh" || exit 1
+docker cp ~/.ssh/id_rsa.pub ${NAME}:/home/$DOCKER_USER/.ssh/authorized_keys || exit 1
+docker exec ${NAME} bash -c "chown $DOCKER_USER:$DOCKER_USER -R /home/$DOCKER_USER/.ssh ;chmod 0700 /home/$DOCKER_USER/.ssh; chmod 0600 /home/$DOCKER_USER/.ssh/*" || exit 1
+ssh -o StrictHostKeyChecking=no -p $SSH_PORT $DOCKER_USER@localhost exit || exit 1
echo "You can now login using:"
echo " ssh -p $SSH_PORT $DOCKER_USER@localhost"