forked from tryretool/retool-onpremise
-
Notifications
You must be signed in to change notification settings - Fork 2
/
stop-local-trial
executable file
·79 lines (67 loc) · 1.78 KB
/
stop-local-trial
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
#!/usr/bin/env bash
# NB: local trial script has to be self-contained
# See https://sipb.mit.edu/doc/safe-shell/
set -euf -o pipefail
if [[ "$OSTYPE" == "linux-gnu" ]]; then
export MAYBE_SUDO="sudo"
else
export MAYBE_SUDO=""
fi
if [ -t 1 ]; then
export NORMAL="$(tput sgr0)"
export RED="$(tput setaf 1)"
export GREEN="$(tput setaf 2)"
export MAGENTA="$(tput setaf 5)"
export CYAN="$(tput setaf 6)"
export WHITE="$(tput setaf 7)"
export BOLD="$(tput bold)"
else
export NORMAL=""
export RED=""
export GREEN=""
export MAGENTA=""
export CYAN=""
export WHITE=""
export BOLD=""
fi
error_exit() {
echo "${RED}${BOLD}ERROR${NORMAL}${BOLD}: $1${NORMAL}"
shift
while [ "$#" -gt "0" ]; do
echo " - $1"
shift
done
exit 1
}
log_step() {
echo ''
echo "${GREEN}${BOLD}INFO${NORMAL}${BOLD}: $1${NORMAL}"
shift
while [ "$#" -gt "0" ]; do
echo " - $1"
shift
done
}
command_present() {
type "$1" >/dev/null 2>&1
}
retool_containers_present() {
# NB: awk is to remove whitespace from `wc`
RETOOL_IMAGES="$($MAYBE_SUDO docker image ls | grep 'retool-onpremise' | wc -l | awk '{print $1}')"
test "$RETOOL_IMAGES" -gt '0'
}
number_of_trial_containers() {
# NB: awk is to remove whitespace from `wc`
cd "$DOCKER_CONTEXT"
$MAYBE_SUDO docker-compose ps -q | wc -l | awk '{print $1}'
}
# NB: trim trailing slash on $TMPDIR as different OS's do it differently
INSTALL_DIRECTORY="$HOME/retool"
DOCKER_CONTEXT="$INSTALL_DIRECTORY/retool-onpremise"
if [ -d "$DOCKER_CONTEXT" ] && [ "$(number_of_trial_containers)" -gt 0 ]; then
cd "$DOCKER_CONTEXT" || error_exit "could not stop Retool. use \`docker\` commands to manage from $DOCKER_CONTEXT"
log_step 'stopping Retool...'
$MAYBE_SUDO docker-compose down
else
log_step 'trial is not running. all done!'
fi