97 lines
2.7 KiB
Bash
Executable file
97 lines
2.7 KiB
Bash
Executable file
#!/bin/bash
|
||
|
||
version=0.20
|
||
program=${0##*/}
|
||
progdir=${0%/*}
|
||
if [ "$progdir" = "$program" ]; then progdir="."; fi
|
||
if [ "$progdir" = "." ]; then progdir="$PWD"; fi
|
||
parent=$(dirname "$progdir")
|
||
if [ "$parent" = "." ]; then parent="$PWD"; fi
|
||
if [[ $(uname) =~ CYGWIN.* ]]; then parent=$(echo "$parent" | sed -e 's/^\/cygdrive\/\(.\)/\1:/'); fi
|
||
|
||
|
||
function usage() {
|
||
cat <<EOF
|
||
NAME
|
||
$program - Run a docker datatracker container with suitable settings
|
||
|
||
SYNOPSIS
|
||
$program [OPTIONS] ARGS
|
||
|
||
DESCRIPTION
|
||
This is a wrapper which runs an Ubuntu-based docker image which
|
||
has been set up with the dependencies needed to easily run the
|
||
IETF datatracker in development mode.
|
||
|
||
MySQL database files at data/mysql will be used; if they do not exist,
|
||
a database dump will be retrieved and restored on first run.
|
||
|
||
OPTIONS
|
||
EOF
|
||
sed -n -E "s|(^\s+-[A-Za-z])\).*#(.*)|\1 \2|p" "$0"
|
||
cat <<EOF
|
||
|
||
AUTHOR
|
||
Written by:
|
||
Henrik Levkowetz, <henrik@levkowetz.com>
|
||
Lars Eggert, <lars@eggert.org>
|
||
|
||
COPYRIGHT
|
||
Copyright (c) 2016 IETF Trust and the persons identified as authors of
|
||
the code. All rights reserved. Redistribution and use in source and
|
||
binary forms, with or without modification, is permitted pursuant to,
|
||
and subject to the license terms contained in, the Revised BSD
|
||
License set forth in Section 4.c of the IETF Trust’s Legal Provisions
|
||
Relating to IETF Documents(https://trustee.ietf.org/license-info).
|
||
EOF
|
||
}
|
||
|
||
|
||
function die() {
|
||
echo -e "\n$program: error: $*" >&2
|
||
exit 1
|
||
}
|
||
|
||
|
||
function version() {
|
||
echo -e "$program $version"
|
||
}
|
||
|
||
|
||
trap 'echo "$program($LINENO): Command failed with error code $? ([$$] $0 $*)"; exit 1' ERR
|
||
|
||
# Default values
|
||
MYSQLDIR=$parent/data/mysql
|
||
PORT=8000
|
||
REPO="ietf/datatracker-environment"
|
||
CACHED=':cached'
|
||
|
||
# Option parsing
|
||
shortopts=cChp:V
|
||
args=$(getopt -o$shortopts $*)
|
||
if [ $? != 0 ] ; then die "Terminating..." >&2 ; exit 1 ; fi
|
||
set -- $args
|
||
|
||
while true ; do
|
||
case "$1" in
|
||
-c) CACHED=':cached';; # Use cached disk access to reduce system load
|
||
-C) CACHED=':consistent';; # Use fully synchronized disk access
|
||
-h) usage; exit;; # Show this help, then exit
|
||
-p) PORT=$2; shift;; # Bind the container's port 8000 to external port PORT
|
||
-V) version; exit;; # Show program version, then exit
|
||
--) shift; break;;
|
||
*) die "Internal error, inconsistent option specification: '$1'";;
|
||
esac
|
||
shift
|
||
done
|
||
|
||
if [ -z "$TAG" ]; then
|
||
TAG=$(basename "$(svn info "$parent" | grep ^URL | awk '{print $2}')")
|
||
fi
|
||
|
||
echo "Starting a docker container for '$REPO:$TAG'."
|
||
mkdir -p "$MYSQLDIR"
|
||
docker run -ti -p "$PORT":8000 -p 33306:3306 \
|
||
-v "$parent:/root/src$CACHED" \
|
||
-v "$MYSQLDIR:/var/lib/mysql:delegated" \
|
||
"$REPO:$TAG" "$@" |