forked from lorrainea/CNEFinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_parse_bed.sh
executable file
·86 lines (67 loc) · 1.74 KB
/
run_parse_bed.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
83
84
85
86
#!/bin/bash
# Rough source:
#https://gist.github.com/clcollins/68cd6b5a67a6124cafbf
# Set to true to just see what command
# would be run
DRY_RUN=false
IMAGE='parse_bed'
# Local volume to be mapped into the container any time you run it
# usually with config files or whatnot
MYCONFDIR=""
# An array of envvars
ENVVARS=('APPENV=docker')
# Array of ports like (80:80 443:443 3000 8080)
# Can be mapped or unmapped
PORTS=()
# Array of volumes
VOLUMES=("/cnefinder/input:/input" "/cnefinder/output:/output")
ENTRYPOINT="" #"/bin/bash"
CMD=""
RESTART=""
DAEMON=false
# The Docker command to use.
# Could be different if including --tlsverify -H "hostname:hostport", etc
DOCKERCMD="docker"
NAME=${IMAGE}
declare -a ENVVAR_STRING
for envvar in ${ENVVARS[@]} ; do
ENVVAR_STRING+=("-e ${envvar}")
done
declare -a PORT_STRING
for port in ${PORTS[@]} ; do
PORT_STRING+=("-p ${port}")
done
declare -a VOLUME_STRING
for volume in ${VOLUMES[@]} ; do
VOLUME_STRING+=("-v ${volume}")
done
if [[ ! -z $NAME ]] ; then
NAME_STRING="--name ${NAME}"
fi
if [[ ! -z $RESTART ]] ; then
RESTART_STRING="--restart ${RESTART}"
fi
if [[ ! -z $ENTRYPOINT ]] ; then
ENTRYPOINT_STRING="--entrypoint ${ENTRYPOINT}"
fi
if [[ ! -z $CMD ]] ; then
CMD_STRING="${CMD}"
fi
if $DAEMON ; then
DAEMON_STRING='-d'
else
DAEMON_STRING='-it'
fi
if $DOCKERCMD ps -a | awk "/${NAME}/ {print $NF}" | grep $NAME &>/dev/null ; then
$DOCKERCMD stop $NAME 1>/dev/null \
&& $DOCKERCMD rm $NAME 1>/dev/null
fi
OPTS="${ENVVAR_STRING[@]} ${PORT_STRING[@]} ${VOLUME_STRING[@]} $NAME_STRING $RESTART_STRING $ENTRYPOINT_STRING"
THE_COMMAND="$DOCKERCMD run $OPTS $DAEMON_STRING $IMAGE $CMD_STRING"
if $DRY_RUN ; then
echo "$THE_COMMAND"
exit 0
else
echo "$THE_COMMAND"
exec $THE_COMMAND
fi