3 ##########################################
4 # WARNING WARNING WARNING WARNING
6 # This script is an example to start a new AGL XDS container
8 # You should customize it to fit your environment and in particular
9 # adjust the paths and permissions where needed.
11 # Note that sharing volumes with host system is not mandatory: it
12 # was just added for performances reasons: building from a SSD is
13 # just faster than using the container filesystem: that's why /xdt is
14 # mounted from there. Same applies to ~/mirror and ~/share, which are
15 # just 2 convenient folders to store reference build caches (used in prepare_meta script)
17 ##########################################
19 CURDIR=$(cd $(dirname $0) && pwd -P)
21 REGISTRY=docker.automotivelinux.org
27 # ---------------------------------------------------
28 # --- computed - don't touch !
29 # ---------------------------------------------------
32 DEFIMAGE=$REGISTRY/$REPO/$NAME-$FLAVOUR:$VERSION
35 echo "Usage: $(basename $0) <instance ID> [image name]" >&2
36 echo "Instance ID must be 0 or a positive integer (1,2,...)" >&2
37 echo "Image name is optional: 'make show-image' is used by default to get image" >&2
38 echo "Default image: $DEFIMAGE" >&2
46 while [ $# -ne 0 ]; do
58 if [[ "$1" =~ ^[0-9]+$ ]]; then
68 [ "$ID" = "" ] && ID=0
70 # Dynamically retrieve image name
71 if [ "$IMAGE" = "" ]; then
73 VER_NUM=`docker images $REGISTRY/$REPO/$NAME-$FLAVOUR:* --format {{.Tag}} | wc -l`
74 if [ $VER_NUM -gt 1 ]; then
75 echo "ERROR: more than one xds image found, please set explicitly the image to use !"
77 elif [ $VER_NUM -lt 1 ]; then
78 echo "ERROR: cannot automatically retrieve image tag for $REGISTRY/$REPO/$NAME-$FLAVOUR"
82 VERSION=`docker images $REGISTRY/$REPO/$NAME-$FLAVOUR:* --format {{.Tag}}`
83 if [ "$VERSION" = "" ]; then
84 echo "ERROR: cannot automatically retrieve image tag for $REGISTRY/$REPO/$NAME-$FLAVOUR"
89 IMAGE=$REGISTRY/$REPO/$NAME-$FLAVOUR:$VERSION
93 echo "Using instance ID #$ID (user $(id -un))"
95 NAME=agl-xds-$(hostname|cut -f1 -d'.')-$ID-$USER
97 docker ps -a |grep "$NAME" > /dev/null
98 [ "$?" = "0" ] && { echo "Image name already exist ! (use -h option to read help)"; exit 1; }
100 MIRRORDIR=$HOME/ssd/localmirror_$ID
101 XDTDIR=$HOME/ssd/xdt_$ID
102 SHAREDDIR=$HOME/$DOCKER_USER/docker/share
103 XDS_WKS=$HOME/xds-workspace
105 SSH_PORT=$((2222 + ID))
106 WWW_PORT=$((8000 + ID))
107 BOOT_PORT=$((69 + ID))
108 NBD_PORT=$((10809 + ID))
110 ### Create the new container
111 mkdir -p $MIRRORDIR $XDTDIR $SHAREDDIR $XDS_WKS || exit 1
113 --publish=${SSH_PORT}:22 \
114 --publish=${WWW_PORT}:8000 \
115 --publish=${BOOT_PORT}:69/udp \
116 --publish=${NBD_PORT}:10809 \
118 --hostname=$NAME --name=$NAME \
119 --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro \
120 -v $MIRRORDIR:/home/$DOCKER_USER/mirror \
121 -v $SHAREDDIR:/home/$DOCKER_USER/share \
122 -v $XDS_WKS:/home/$DOCKER_USER/xds-workspace \
125 if [ "$?" != "0" ]; then
126 echo "An error was encountered while creating docker container."
131 echo "Copying your identity to container $NAME"
132 echo -n wait ssh service .
136 while [ $res -ne 0 ] && [ $count -le $max ]; do
138 docker exec ${NAME} bash -c "systemctl status ssh" 2>/dev/null 1>&2
141 count=$(expr $count + 1);
145 ssh-keygen -R [localhost]:$SSH_PORT -f ~/.ssh/known_hosts
146 docker exec ${NAME} bash -c "mkdir -p /home/$DOCKER_USER/.ssh"
147 docker cp ~/.ssh/id_rsa.pub ${NAME}:/home/$DOCKER_USER/.ssh/authorized_keys
148 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/*"
149 ssh -o StrictHostKeyChecking=no -p $SSH_PORT $DOCKER_USER@localhost exit
151 echo "You can now login using:"
152 echo " ssh -p $SSH_PORT $DOCKER_USER@localhost"
155 if ($UPDATE_UID); then
156 echo "Setup docker user and group id to match yours"
157 docker exec -t ${NAME} bash -c "systemctl stop xds-server" || exit 1
158 docker exec -t ${NAME} bash -c "usermod -u $(id -u) $DOCKER_USER && groupmod -g $(id -g) $DOCKER_USER" || exit 1
159 docker exec -t ${NAME} bash -c "chown -R $DOCKER_USER:$DOCKER_USER /home/$DOCKER_USER /tmp/xds*" || exit 1
160 docker exec -t ${NAME} bash -c "systemctl start xds-server" || exit 1
161 docker exec -t ${NAME} bash -c "systemctl start xds-server" || exit 1
164 ### Force xds-server restart
165 if ($FORCE_RESTART); then
166 echo "Stopping xds-server..."
167 docker exec -t ${NAME} bash -c "systemctl stop xds-server" || exit 1
169 echo "Starting xds-server..."
170 docker exec -t ${NAME} bash -c "systemctl start xds-server" || exit 1