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
33 docker images |grep $DEFIMAGE 2>&1 > /dev/null
34 if [ "$?" = "1" ]; then
35 VERSION=`docker images $REGISTRY/$REPO/$NAME-$FLAVOUR:* --format "{{.Tag}}"`
36 if [ "$VERSION" = "" ]; then
37 echo "ERROR: cannot automatically retrieve image tag for $REGISTRY/$REPO/$NAME-$FLAVOUR"
40 DEFIMAGE=$REGISTRY/$REPO/$NAME-$FLAVOUR:$VERSION
45 echo "Usage: $(basename $0) <instance ID> [image name]" >&2
46 echo "Instance ID must be 0 or a positive integer (1,2,...)" >&2
47 echo "Image name is optional: 'make show-image' is used by default to get image" >&2
48 echo "Default image: $DEFIMAGE" >&2
55 while [ $# -ne 0 ]; do
64 if [[ "$1" =~ ^[0-9]+$ ]]; then
74 [ "$ID" = "" ] && ID=0
77 echo "Using instance ID #$ID (user $(id -un))"
79 NAME=agl-xds-$(hostname|cut -f1 -d'.')-$ID-$USER
81 docker ps -a |grep "$NAME" > /dev/null
82 [ "$?" = "0" ] && { echo "Image name already exist ! (use -h option to read help)"; exit 1; }
84 MIRRORDIR=$HOME/ssd/localmirror_$ID
85 XDTDIR=$HOME/ssd/xdt_$ID
86 SHAREDDIR=$HOME/$DOCKER_USER/docker/share
88 SSH_PORT=$((2222 + ID))
89 WWW_PORT=$((8000 + ID))
90 BOOT_PORT=$((69 + ID))
91 NBD_PORT=$((10809 + ID))
93 mkdir -p $MIRRORDIR $XDTDIR $SHAREDDIR || exit 1
95 --publish=${SSH_PORT}:22 \
96 --publish=${WWW_PORT}:8000 \
97 --publish=${BOOT_PORT}:69/udp \
98 --publish=${NBD_PORT}:10809 \
100 --hostname=$NAME --name=$NAME \
101 --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro \
102 -v $MIRRORDIR:/home/$DOCKER_USER/mirror \
103 -v $SHAREDDIR:/home/$DOCKER_USER/share \
106 if [ "$?" != "0" ]; then
107 echo "An error was encountered while creating docker container."
112 echo "Stopping xds-server..."
113 docker exec -t ${NAME} bash -c "systemctl stop xds-server" || exit 1
115 echo "Starting xds-server..."
116 docker exec -t ${NAME} bash -c "systemctl start xds-server" || exit 1
119 echo "Copying your identity to container $NAME"
121 echo -n wait ssh service .
125 while [ $res -ne 0 ] && [ $count -le $max ]; do
127 docker exec ${NAME} bash -c "systemctl status ssh" 2>/dev/null 1>&2
130 count=$(expr $count + 1);
134 ssh-keygen -R [$(hostname)]:$SSH_PORT -f ~/.ssh/known_hosts
135 docker exec ${NAME} bash -c "mkdir -p /home/devel/.ssh"
136 docker cp ~/.ssh/id_rsa.pub ${NAME}:/home/devel/.ssh/authorized_keys
137 docker exec ${NAME} bash -c "chown devel:devel -R /home/devel/.ssh ;chmod 0700 /home/devel/.ssh;chmod 0600 /home/devel/.ssh/*"
138 ssh -o StrictHostKeyChecking=no -p $SSH_PORT devel@$(hostname) exit
140 echo "You can now login using:"
141 echo " ssh -p $SSH_PORT $DOCKER_USER@$(hostname)"