diff options
author | Christophe Lyon <christophe.lyon@linaro.org> | 2017-02-03 14:14:51 +0000 |
---|---|---|
committer | Christophe Lyon <christophe.lyon@linaro.org> | 2017-02-03 14:30:24 +0000 |
commit | f33002a6126f721fb5e55c0f83f0afe321bb3cb8 (patch) | |
tree | b100f39b405cd5bbc41401b09dab5806fc132aa4 /start-container-schroot.sh | |
parent | 7dc65c4426b7175b54ab472d57e62d68df8b574e (diff) |
start-container-*.sh: Parameters now require option flags.
This makes it easier/clearer to support optional parameters.
Improve diagnotics and consistency.
start-container-none.sh: exit with error if the requested
arch or distro do not match the host's.
Change-Id: I9c1d27db1ac679da217e7fae4a8cd15773ffec17
Diffstat (limited to 'start-container-schroot.sh')
-rwxr-xr-x | start-container-schroot.sh | 68 |
1 files changed, 58 insertions, 10 deletions
diff --git a/start-container-schroot.sh b/start-container-schroot.sh index 6f62e51d..3fdc5727 100755 --- a/start-container-schroot.sh +++ b/start-container-schroot.sh @@ -11,29 +11,77 @@ set -e # to run inside the container. # - definition of ${session_host} and ${session_port}, can be used for # a remote connexion to the container -if [ $# -ne 2 -a $# -ne 3 ]; then - echo Usage: $0 arch flavour [host] - echo " arch: architecture (eg: amd64, i386, arm64, armhf)" - echo " flavour: distribution (eg: trusty)" - echo " host: hostname where the container will run, defaults to localhost" + +usage() { + echo Usage: $0 --arch container-arch --distro flavour [--session-host host] [--session-name name] + echo + echo " container-arch: architecture (eg: amd64, i386, arm64, armhf)" + echo " distro: distribution (eg: trusty)" + echo " session-host: hostname where the container will run, defaults to localhost" + echo " useful if the name resolution does not work correctly" + echo " session-name: session, in case the default '$BUILD_NUMBER-$JOB_NAME' is not suitable" exit 1 -fi +} + +# Save stdout/stderr file descriptors +exec 3>&1 4>&2 + +# Make sure all output goes to stderr +exec 1>&2 + +container_arch= +distro= +session_host= +session_name= + +while [ $# -ge 1 ] +do + case $1 in + --arch) + container_arch=$2 + [ x${container_arch} = x ] && usage + shift 2 + ;; + --distro) + distro=$2 + [ x${distro} = x ] && usage + shift 2 + ;; + --session-host) + session_host=$2 + [ x${session_host} = x ] && usage + shift 2 + ;; + --session-name) + session_name=$2 + [ x${session_name} = x ] && usage + shift 2 + ;; + *) + echo "Unsupported option: $1" + usage + ;; + esac +done + +[ x${container_arch} = x ] && usage +[ x${distro} = x ] && usage -container_arch=$1 -distro=$2 -session_host=$3 [ x"$session_host" = x ] && session_host=localhost session_host=${session_host}.tcwglab session_port=22 schroot_image="tcwg-build-${container_arch}-${distro}" -SCHROOT="ssh ${session_host} schroot" +SCHROOT="ssh -p ${session_port} -A ${session_host} schroot" session_id=$(${SCHROOT} -b -c chroot:$schroot_image --preserve-environment) if [ x"$session_id" = x ]; then exit 1 fi +# Restore stdout/stderr +exec 1>&3 2>&4 + cat <<EOF ulimit -u 5000 # FIXME how to support this remotely? # Sometimes /dev/pts can't get unmounted on the first try. |