-
Notifications
You must be signed in to change notification settings - Fork 36
/
setPorts.sh
executable file
·78 lines (54 loc) · 1.58 KB
/
setPorts.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
#!/bin/bash
# Mapping ports
DEFAULT_PORTS=( "httpPort:8080"
"httpsPort:8443"
"ajp13Port:8009"
"pgPort:5432"
"debugPort:8044"
"disPort:9001"
)
NAMES=()
DEFAULTS=()
USED=()
PORTS=("${DEFAULT_PORTS[@]}" "${PROJ_PORTS[@]}")
n=-1
for port in "${PORTS[@]}" ; do
((n++))
portName=${port%%:*}
portValue=${port#*:}
# Check if the port is already been used
#opened=$(lsof -i :$portValue)
opened=$(netstat -na | grep -i -E "^tcp.*[\.|:]$portValue\s+")
if [ "$portName" == "debugPort" ]
then
# If the port is used, look for the next one free
while ! [ -z "$opened" ]; do
((portValue++))
#opened=$(lsof -i :$portValue)
opened=$(netstat -na | grep -i -E "^tcp.*[\.|:]$portValue\s+")
done
read $portName <<<$portValue
else
NAMES[$n]=$portName
DEFAULTS[$n]=$portValue
# If the port is used, look for the next one free
while ! [ -z "$opened" ]; do
((portValue++))
#opened=$(lsof -i :$portValue)
opened=$(netstat -na | grep -i -E "^tcp.*[\.|:]$portValue\s+")
done
USED[$n]=$portValue
fi
done
CBF2_BINDING_INTERFACE_OPT=""
if [ ! -z ${CBF2_BINDING_INTERFACE+x} ]
then
CBF2_BINDING_INTERFACE_OPT="${CBF2_BINDING_INTERFACE}:"
fi
exposePorts=""
for index in ${!NAMES[*]}
do
exposePorts+=" -p ${CBF2_BINDING_INTERFACE_OPT}${USED[$index]}:${DEFAULTS[$index]}"
done
#echo $exposePorts
#echo $debugPort