-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.sh
executable file
·57 lines (56 loc) · 1.42 KB
/
debug.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
#!/bin/bash
NAME=`basename $( dirname ${BASH_SOURCE[0]} )`
if [ "${NAME}" == "." ]; then
NAME=`basename $(pwd)`
fi
DIRNAME=`dirname ${BASH_SOURCE[0]}`
DIRNAME=`readlink -f ${DIRNAME}`
if [ "${DIRNAME}" == "." ]; then
DIRNAME=`pwd`
fi
INSTANCECOUNT=0
for i in ${DIRNAME}/print-instance-args_*.sh ; do
INSTANCE=`basename $i ` #Just the file
INSTANCE=${INSTANCE:20} #Remove the first 20 chars (print-instance-args_)
INSTANCE="_"${INSTANCE:0:-3} #Remove the last 3 chars (.sh)
if [ "${1}" == "main" ]; then
set -- "" "${@:2}"
fi
if [ "${INSTANCE:1}" == "main" ]; then
INSTANCE=""
fi
if [ "${INSTANCE:1}" == "*" ]; then
break;
else
INSTANCECOUNT=` expr ${INSTANCECOUNT} + 1 `
fi
if [ "${1}" == "${INSTANCE:1}" -o "${1}" == "" ]; then
if [ "${MATCHED}" == "1" ]; then
break
fi
if [ "${1}" == "${INSTANCE:1}" ]; then
MATCHED=1
shift;
fi
#Do this for each of them (or the match)
#echo Name: ${NAME}, DirName: ${DIRNAME}, Instance: ${INSTANCE:1}, Counter: ${INSTANCECOUNT}.
if [ -t 1 ]; then
PARAMS="-i -t --user root"
else
PARAMS=""
fi
if [ "$*" == "" ]; then
exec docker exec ${PARAMS} ${NAME}${INSTANCE} bash
break
else
exec docker exec ${PARAMS} ${NAME}${INSTANCE} $*
break
fi
fi
done
if [ "${MATCHED}" != "1" ]; then
echo ERR: $0: You need to specify an instance name >&2
fi
if [ "${INSTANCECOUNT}" == "0" ]; then
echo ERR: $0: No instances found, nothing was done. >&2
fi