X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=scripts%2Fxds-docker-create-container.sh;h=7990c4592063e9aa45987d08542d805a2983689a;hb=be47274f79eb0843da4d805cfc417fbf7921379c;hp=71f4b03c2998b030a0e991983a22ca2482c56e9c;hpb=2a35ea64a1c3c616eb69d4d78e907fbdbae7529a;p=src%2Fxds%2Fxds-server.git diff --git a/scripts/xds-docker-create-container.sh b/scripts/xds-docker-create-container.sh index 71f4b03..7990c45 100755 --- a/scripts/xds-docker-create-container.sh +++ b/scripts/xds-docker-create-container.sh @@ -1,4 +1,22 @@ #!/bin/bash + ########################################################################### +# Copyright 2017 IoT.bzh +# +# author: Sebastien Douheret +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +########################################################################### + # shellcheck disable=SC2086 ########################################## @@ -171,11 +189,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 -L ~/.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 -n -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" @@ -221,7 +240,7 @@ if ($UPDATE_UID); then echo -n "." docker exec -t ${NAME} bash -c "systemctl start autologin" echo -n "." - ssh -p $SSH_PORT $DOCKER_USER@localhost "systemctl --user start xds-server" || exit 1 + ssh -n -p $SSH_PORT $DOCKER_USER@localhost "systemctl --user start xds-server" || exit 1 echo "." docker restart ${NAME} fi @@ -231,7 +250,7 @@ creation_done=true ### Force xds-server restart if ($FORCE_RESTART); then echo "Restart xds-server..." - ssh -p $SSH_PORT $DOCKER_USER@localhost "systemctl --user restart xds-server" || exit 1 + ssh -n -p $SSH_PORT $DOCKER_USER@localhost "systemctl --user restart xds-server" || exit 1 fi echo "Done, docker container $NAME is ready to be used."