-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinfdb.sh
More file actions
140 lines (120 loc) · 3.21 KB
/
infdb.sh
File metadata and controls
140 lines (120 loc) · 3.21 KB
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
#!/usr/bin/env bash
set -e
# ----------------------------------------------------------------------
# infDB command script
# Usage:
# ./infdb.sh start [docker compose args]
# ./infdb.sh import [docker compose args]
# ./infdb.sh stop
# ./infdb.sh remove
# ----------------------------------------------------------------------
# Ensure relative path works
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
print_usage() {
cat <<'EOF'
Usage:
./infdb.sh start [docker compose args]
./infdb.sh import [docker compose args]
./infdb.sh stop
./infdb.sh remove
Examples:
./infdb.sh start -d
./infdb.sh import --build
./infdb.sh stop
./infdb.sh remove
EOF
}
ensure_from_template() {
local target_file="$1"
local template_file="$2"
if [ ! -f "$target_file" ]; then
echo "=== Creating $target_file from template ==="
cp "$template_file" "$target_file"
echo "=== $target_file file created. Please review and customize it as needed. ==="
fi
}
cmd_start() {
configure_lizmap
echo "=== Pull latest docker images ==="
docker compose pull --ignore-buildable
echo "=== Starting infDB ==="
if [ $# -eq 0 ]; then
docker compose up --pull never -d
elif [ "$1" = "" ]; then
docker compose up --pull never
else
docker compose up --pull never "$@"
fi
echo "=== Successfully started InfDB. ==="
}
cmd_import() {
ensure_from_template "configs/config-infdb-import.yml" "configs/config-infdb-import.yml.template"
echo "=== Importing data ==="
docker compose --profile "import" up "$@"
}
cmd_stop() {
echo "=== Stopping infDB ==="
docker compose --profile "*" down
echo "Successfully stopped all InfDB services."
}
cmd_remove() {
echo "=== Removing service $1 including data ==="
docker compose --profile "$1" down -v --remove-orphans
if { [[ "$1" == *"lizmap"* ]] || [[ "$1" == *"*"* ]]; }; then
cd services/infdb-lizmap
./configure.sh clean
cd "$SCRIPT_DIR"
fi
}
configure_lizmap() {
echo ${COMPOSE_PROFILES}
if [[ ":${COMPOSE_PROFILES}:" == *"lizmap"* ]] && [ ! -d "services/infdb-lizmap/lizmap" ]; then
echo "=== Configuring lizmap ==="
cd services/infdb-lizmap
./configure.sh configure
chmod +x lizmap/etc/postgres.init.d/init-lizmap-db.sh
cd "$SCRIPT_DIR"
fi
}
if [ $# -lt 1 ]; then
print_usage
exit 1
fi
ensure_from_template ".env" ".env.template"
# Load environment variables from .env if it exists
if [ -f "$SCRIPT_DIR/.env" ]; then
set -o allexport
source "$SCRIPT_DIR/.env"
set +o allexport
fi
export UID GID="$(id -g)"
# Set default platform for Docker to linux/amd64 only on Apple Silicon
if [[ "$(uname -s)" == "Darwin" ]] && [[ "$(uname -m)" == "arm64" ]]; then
export DOCKER_DEFAULT_PLATFORM=linux/amd64
fi
COMMAND="$1"
shift
case "$COMMAND" in
start)
cmd_start "$@"
;;
import)
cmd_import "$@"
;;
stop)
cmd_stop "$@"
;;
remove)
cmd_remove "$@"
;;
-h|--help|help)
print_usage
;;
*)
echo "Unknown command: $COMMAND"
echo
print_usage
exit 1
;;
esac