Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit 71ccc9c

Browse files
committed
#9: Updates scmi defaults for readability/consisitency.
1 parent c9e22b5 commit 71ccc9c

File tree

1 file changed

+58
-10
lines changed

1 file changed

+58
-10
lines changed

src/opt/scmi/default.sh

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,39 @@
11

22
# Handle incrementing the docker host port for instances unless a port range is defined.
33
DOCKER_PUBLISH=
4-
if [[ ${DOCKER_PORT_MAP_TCP_6379} != NULL ]]; then
5-
if grep -qE '^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}:)?[0-9]*$' <<< "${DOCKER_PORT_MAP_TCP_6379}" \
6-
&& grep -qE '^.+\.([0-9]+)\.([0-9]+)$' <<< "${DOCKER_NAME}"; then
4+
if [[ ${DOCKER_PORT_MAP_TCP_6379} != NULL ]]
5+
then
6+
if grep -qE \
7+
'^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}:)?[1-9][0-9]*$' \
8+
<<< "${DOCKER_PORT_MAP_TCP_6379}" \
9+
&& grep -qE \
10+
'^.+\.[0-9]+(\.[0-9]+)?$' \
11+
<<< "${DOCKER_NAME}"
12+
then
713
printf -v \
814
DOCKER_PUBLISH \
915
-- '%s --publish %s%s:6379/tcp' \
1016
"${DOCKER_PUBLISH}" \
11-
"$(grep -o '^[0-9\.]*:' <<< "${DOCKER_PORT_MAP_TCP_6379}")" \
12-
"$(( $(grep -o '[0-9]*$' <<< "${DOCKER_PORT_MAP_TCP_6379}") + $(sed 's~\.[0-9]*$~~' <<< "${DOCKER_NAME}" | awk -F. '{ print $NF; }') - 1 ))"
17+
"$(
18+
grep -o \
19+
'^[0-9\.]*:' \
20+
<<< "${DOCKER_PORT_MAP_TCP_6379}"
21+
)" \
22+
"$((
23+
$(
24+
grep -oE \
25+
'[0-9]+$' \
26+
<<< "${DOCKER_PORT_MAP_TCP_6379}"
27+
) \
28+
+ $(
29+
grep -oE \
30+
'([0-9]+)(\.[0-9]+)?$' \
31+
<<< "${DOCKER_NAME}" \
32+
| awk -F. \
33+
'{ print $1; }'
34+
) \
35+
- 1
36+
))"
1337
else
1438
printf -v \
1539
DOCKER_PUBLISH \
@@ -19,15 +43,39 @@ if [[ ${DOCKER_PORT_MAP_TCP_6379} != NULL ]]; then
1943
fi
2044
fi
2145

22-
if [[ ${DOCKER_PORT_MAP_UDP_6379} != NULL ]]; then
23-
if grep -qE '^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}:)?[0-9]*$' <<< "${DOCKER_PORT_MAP_UDP_6379}" \
24-
&& grep -qE '^.+\.([0-9]+)\.([0-9]+)$' <<< "${DOCKER_NAME}"; then
46+
if [[ ${DOCKER_PORT_MAP_UDP_6379} != NULL ]]
47+
then
48+
if grep -qE \
49+
'^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}:)?[1-9][0-9]*$' \
50+
<<< "${DOCKER_PORT_MAP_UDP_6379}" \
51+
&& grep -qE \
52+
'^.+\.[0-9]+(\.[0-9]+)?$' \
53+
<<< "${DOCKER_NAME}"
54+
then
2555
printf -v \
2656
DOCKER_PUBLISH \
2757
-- '%s --publish %s%s:6379/udp' \
2858
"${DOCKER_PUBLISH}" \
29-
"$(grep -o '^[0-9\.]*:' <<< "${DOCKER_PORT_MAP_UDP_6379}")" \
30-
"$(( $(grep -o '[0-9]*$' <<< "${DOCKER_PORT_MAP_UDP_6379}") + $(sed 's~\.[0-9]*$~~' <<< "${DOCKER_NAME}" | awk -F. '{ print $NF; }') - 1 ))"
59+
"$(
60+
grep -o \
61+
'^[0-9\.]*:' \
62+
<<< "${DOCKER_PORT_MAP_UDP_6379}"
63+
)" \
64+
"$((
65+
$(
66+
grep -oE \
67+
'[0-9]+$' \
68+
<<< "${DOCKER_PORT_MAP_UDP_6379}"
69+
) \
70+
+ $(
71+
grep -oE \
72+
'([0-9]+)(\.[0-9]+)?$' \
73+
<<< "${DOCKER_NAME}" \
74+
| awk -F. \
75+
'{ print $1; }'
76+
) \
77+
- 1
78+
))"
3179
else
3280
printf -v \
3381
DOCKER_PUBLISH \

0 commit comments

Comments
 (0)