-
Notifications
You must be signed in to change notification settings - Fork 42
/
recreate
executable file
·72 lines (59 loc) · 1.38 KB
/
recreate
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
#!/usr/bin/env bash
# Recreates a Neohabitat developer environment.
set -euo pipefail
function usage() {
echo "Usage: ./$(basename $0) [-b] [-f]"
echo "Description: Recreates a Neohabitat developer environment."
echo "Options:"
echo " -b: Rebuilds all Docker containers upon recreation"
echo " -f: Forces rebuild (does not ask for permission)"
exit 1
}
function yes_or_no {
while true; do
read -p "$* [y/n]: " yn
case $yn in
[Yy]*)
return 0
;;
[Nn]*)
echo "OK, bailing out."
return 1
;;
esac
done
}
should_build=false
should_force=false
while getopts ':bfh' opt; do
case "$opt" in
b)
should_build=true
;;
f)
should_force=true
;;
?|h)
usage
;;
esac
done
if [ "${should_force}" == false ]; then
echo "! WARNING: this script will blow away your docker-compose environment and all databases."
yes_or_no "Is this OK?"
fi
echo " - Deleting all database data..."
rm -rf data/mariadb
rm -rf data/mongodb
mkdir -p data/mariadb
mkdir -p data/mongodb
echo " - Deleting all Docker Compose-created containers..."
docker compose down
docker compose rm -f
if [ "${should_build}" == true ]; then
echo " - Delegating control to docker-compose up --build..."
exec docker compose up --build
else
echo " - Delegating control to docker-compose up..."
exec docker compose up
fi