forked from team19hackathon2021/ChRIS_ultron_backEnd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unmake.sh
executable file
·155 lines (145 loc) · 4.32 KB
/
unmake.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
#
# NAME
#
# unmake.sh
#
# SYNPOSIS
#
# unmake.sh [-h]
# [-O <swarm|kubernetes>]
# [-S <storeBase>]
#
#
# DESC
#
# 'unmake.sh' destroys a chris development instance with remote ancillary services
# pfcon/pman running on Swarm or Kubernetes.
#
# TYPICAL CASES:
#
# Destroy chris_dev instance with remote ancillary services running on Swarm:
#
# unmake.sh
#
# Destroy chris_dev instance with remote ancillary services running on Kubernetes:
#
# unmake.sh -O kubernetes
#
# ARGS
#
#
# -h
#
# Optional print usage help.
#
# -O <swarm|kubernetes>
#
# Explicitly set the orchestrator. Default is swarm.
#
# -S <storeBase>
#
# Explicitly set the STOREBASE dir to <storeBase>. This is the remote ChRIS
# filesystem where pfcon and plugins share data.
#
#
source ./decorate.sh
declare -i STEP=0
ORCHESTRATOR=swarm
dc_check () {
STATUS=$1
if [[ $STATUS != "0" ]] ; then
echo -en "\033[2A\033[2K"
cat dc.out | sed -E 's/(.{80})/\1\n/g' | ./boxes.sh LightRed
else
echo -en "\033[2A\033[2K"
cat dc.out | ./boxes.sh White
fi
}
print_usage () {
echo "Usage: ./unmake.sh [-h] [-O <swarm|kubernetes>] [-S <storeBase>]"
exit 1
}
while getopts ":hO:S:" opt; do
case $opt in
h) print_usage
;;
O) ORCHESTRATOR=$OPTARG
if ! [[ "$ORCHESTRATOR" =~ ^(swarm|kubernetes)$ ]]; then
echo "Invalid value for option -- O"
print_usage
fi
;;
S) STOREBASE=$OPTARG
;;
\?) echo "Invalid option -- $OPTARG"
print_usage
;;
:) echo "Option requires an argument -- $OPTARG"
print_usage
;;
esac
done
shift $(($OPTIND - 1))
title -d 1 "Setting global exports"
boxcenter "-= ORCHESTRATOR =-"
boxcenter "$ORCHESTRATOR" LightCyan
boxcenter ""
if [ -z ${STOREBASE+x} ]; then
STOREBASE=$(pwd)/CHRIS_REMOTE_FS
fi
boxcenter "-= STOREBASE =-"
echo "$STOREBASE" | ./boxes.sh LightCyan
export STOREBASE=$STOREBASE
if [[ $ORCHESTRATOR == kubernetes ]]; then
echo -e "exporting REMOTENETWORK=false " | ./boxes.sh
export REMOTENETWORK=false
windowBottom
fi
windowBottom
title -d 1 "Destroying remote pfcon containerized environment on " \
"-= $ORCHESTRATOR =-"
if [[ $ORCHESTRATOR == swarm ]]; then
echo "$ docker stack rm pfcon_stack" | ./boxes.sh LightCyan
windowBottom
docker stack rm pfcon_stack &> dc.out
elif [[ $ORCHESTRATOR == kubernetes ]]; then
echo "$ kubectl delete -f kubernetes/remote.yaml" | ./boxes.sh LightCyan
windowBottom
kubectl delete -f kubernetes/remote.yaml &> dc.out
fi
dc_check $?
echo "$ rm -fr \$STOREBASE" | ./boxes.sh LightCyan
rm -fr $STOREBASE
windowBottom
title -d 1 "Destroying CUBE containerized development environment" \
"from ./docker-compose_dev.yml"
echo "Do you want to also remove persistent volumes? [y/n]" | ./boxes.sh White
windowBottom
old_stty_cfg=$(stty -g)
stty raw -echo ; REPLY=$(head -c 1) ; stty $old_stty_cfg
echo -en "\033[2A\033[2K"
# read -p " " -n 1 -r REPLY
if [[ $REPLY =~ ^[Yy]$ ]] ; then
boxcenter ""
echo "Removing persistent volumes... please be patient." | ./boxes.sh Yellow
boxcenter ""
echo "$ docker-compose -f docker-compose_dev.yml down -v" | ./boxes.sh LightCyan
windowBottom
docker-compose -f docker-compose_dev.yml down -v >& dc.out
dc_check $?
else
echo "Keeping persistent volumes... please be patient." | ./boxes.sh Yellow
windowBottom
docker-compose -f docker-compose_dev.yml down >& dc.out
dc_check $?
fi
windowBottom
if [[ $ORCHESTRATOR == swarm ]]; then
title -d 1 "Removing overlay network: remote"
windowBottom
sleep 2
docker network rm remote &> dc.out
dc_check $?
windowBottom
fi