-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·58 lines (48 loc) · 1.44 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·58 lines (48 loc) · 1.44 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
#!/bin/bash
set -e
MODE="${1:-}"
log_info() { echo -e "\033[0;32m[INFO]\033[0m $1"; }
log_warn() { echo -e "\033[1;33m[WARN]\033[0m $1"; }
log_error() { echo -e "\033[0;31m[ERROR]\033[0m $1"; }
setup_env() {
for file in .env frontend/.env backend/.env; do
example="${file}.example"
if [ -f "$example" ] && [ ! -f "$file" ]; then
cp "$example" "$file"
log_info "Created $file"
fi
done
}
MONGO_HOST="127.0.0.1"
MONGO_PORT="27017"
mongo_is_reachable() {
(exec 3<>"/dev/tcp/${MONGO_HOST}/${MONGO_PORT}") >/dev/null 2>&1
}
check_mongo() {
if mongo_is_reachable; then
log_info "MongoDB is already reachable on ${MONGO_PORT}"
return
fi
log_warn "MongoDB is not reachable; starting it"
if [ -f /etc/mongod.conf ]; then
mongod --config /etc/mongod.conf --fork >/dev/null 2>&1 || true
else
mkdir -p .mongodb
mongod --dbpath .mongodb --bind_ip "$MONGO_HOST" --port "$MONGO_PORT" --fork --logpath .mongodb/mongod.log >/dev/null 2>&1 || true
fi
mongo_is_reachable || {
log_error "MongoDB is required on ${MONGO_HOST}:${MONGO_PORT}. Start it, then run this again."
exit 1
}
}
seed_database() {
log_info "Seeding Calendar database"
bun run seed
}
setup_env
check_mongo
case "$MODE" in
--start|--seed|"") seed_database ;;
*) log_error "Unknown setup mode: $MODE"; exit 1 ;;
esac
log_info "Calendar setup complete"