-
Notifications
You must be signed in to change notification settings - Fork 6
/
run.sh
executable file
·82 lines (70 loc) · 2.2 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
#DEVELOPER's startup script - only used for container development
#Created by chaplocal on Mon Aug 17 23:41:27 UTC 2015
IMAGE="garywiz/docker-keybox"
INTERACTIVE_SHELL="/bin/bash"
# Uncomment to include port settings
#PORTOPT="-p x:y"
EXT_HOSTNAME=localhost
usage() {
echo "Usage: run.sh [-d] [-p port#] [-h] [extra-chaperone-options]"
echo " Run $IMAGE as a daemon or interactively (the default)."
echo " First available port will be remapped to $EXT_HOSTNAME if possible."
exit
}
if [ "$CHAP_SERVICE_NAME" != "" ]; then
echo run.sh should be executed on your docker host, not inside a container.
exit
fi
cd ${0%/*} # go to directory of this file
APPS=$PWD
cd ..
options="-t -i -e TERM=$TERM --rm=true"
shellopt="/bin/bash --rcfile $APPS/bash.bashrc"
while getopts ":-dp:" o; do
case "$o" in
d)
options="-d"
shellopt=""
;;
p)
PORTOPT="-p $OPTARG"
;;
-) # first long option terminates
break
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
# remap ports according to the image, and tell the container about the lowest numbered
# port used.
if [ "$PORTOPT" == "" ]; then
exposed=`docker inspect $IMAGE | sed -ne 's/^ *"\([0-9]*\)\/tcp".*$/\1/p' | sort -u`
ncprog=`which nc`
if [ "$exposed" != "" -a "$ncprog" != "" ]; then
PORTOPT=""
for PORT in $exposed; do
if ! $ncprog -z $EXT_HOSTNAME $PORT; then
[ "$PORTOPT" == "" ] && PORTOPT="--env CONFIG_EXT_PORT=$PORT"
PORTOPT="$PORTOPT -p $PORT:$PORT"
echo "Port $PORT available at $EXT_HOSTNAME:$PORT ..."
fi
done
else
if [ "$exposed" != "" ]; then
echo "Note: '/bin/nc' not installed, so cannot detect port usage on this system."
echo " Use '$0 -p x:y' to expose ports."
fi
fi
fi
# Run the image with this directory as our local apps dir.
# Create a user with a uid/gid based upon the file permissions of the chaperone.d
# directory.
MOUNT=${PWD#/}; MOUNT=/${MOUNT%%/*} # extract user mountpoint
docker run $options -v $MOUNT:$MOUNT $PORTOPT -e CONFIG_EXT_HOSTNAME=$EXT_HOSTNAME -e CONFIG_LOGGING=file \
-e EMACS=$EMACS \
$IMAGE \
--create $USER:$APPS/chaperone.d --config $APPS/chaperone.d $* $shellopt