-
Notifications
You must be signed in to change notification settings - Fork 0
/
dc-stop.sh
executable file
·81 lines (65 loc) · 1.95 KB
/
dc-stop.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
#!/bin/bash
#
# by TS, May 2019
#
# @param string $1 Path
# @param int $2 Recursion level
#
# @return string Absolute path
function realpath_osx() {
local TMP_RP_OSX_RES=
[[ $1 = /* ]] && TMP_RP_OSX_RES="$1" || TMP_RP_OSX_RES="$PWD/${1#./}"
if [ -h "$TMP_RP_OSX_RES" ]; then
TMP_RP_OSX_RES="$(readlink "$TMP_RP_OSX_RES")"
# possible infinite loop...
local TMP_RP_OSX_RECLEV=$2
[ -z "$TMP_RP_OSX_RECLEV" ] && TMP_RP_OSX_RECLEV=0
TMP_RP_OSX_RECLEV=$(( TMP_RP_OSX_RECLEV + 1 ))
if [ $TMP_RP_OSX_RECLEV -gt 20 ]; then
# too much recursion
TMP_RP_OSX_RES="--error--"
else
TMP_RP_OSX_RES="$(realpath_osx "$TMP_RP_OSX_RES" $TMP_RP_OSX_RECLEV)"
fi
fi
echo "$TMP_RP_OSX_RES"
}
# @param string $1 Path
#
# @return string Absolute path
function realpath_poly() {
case "$OSTYPE" in
linux*) realpath "$1" ;;
darwin*) realpath_osx "$1" ;;
*) echo "$VAR_MYNAME: Error: Unknown OSTYPE '$OSTYPE'" >/dev/stderr; echo -n "$1" ;;
esac
}
VAR_MYNAME="$(basename "$0")"
VAR_MYDIR="$(realpath_poly "$0")"
VAR_MYDIR="$(dirname "$VAR_MYDIR")"
# ----------------------------------------------------------
function printUsageAndExit() {
echo "Usage: $VAR_MYNAME <VERSION>" >/dev/stderr
echo "Examples: $VAR_MYNAME 5.0" >/dev/stderr
echo " $VAR_MYNAME 6.0" >/dev/stderr
exit 1
}
if [ $# -eq 1 ] && [ "$1" = "-h" -o "$1" = "--help" ]; then
printUsageAndExit
fi
if [ $# -lt 1 ]; then
echo -e "Missing argument. Aborting.\n" >/dev/stderr
printUsageAndExit
fi
OPT_IMG_VER="$1"
shift
cd "$VAR_MYDIR" || exit 1
# ----------------------------------------------------------
TMP_IMG_VER_SHORT="$(echo -n "$OPT_IMG_VER" | cut -f1-2 -d.)"
TMP_IMGVER_STR="$(echo -n "$TMP_IMG_VER_SHORT" | tr -d .)"
echo -n "$TMP_IMG_VER_SHORT" | grep -q -E "[0-9]{1,2}[\.][0-9]{1,2}" || {
echo "Invalid version. Must have format 'xx.xx'." >/dev/stderr
exit 1
}
# ----------------------------------------------------------
docker container stop indexing-redis${TMP_IMGVER_STR}-cont