-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·57 lines (52 loc) · 1.5 KB
/
run.sh
File metadata and controls
executable file
·57 lines (52 loc) · 1.5 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
#!/bin/sh -x
chown_dir() {
if [ -d "$3" ]; then
echo "Directory $3 already exists, skipping"
else
mkdir -p "$3"
sudo chown -R "$1":"$2" "$3"
fi
}
rand() {
pwgen=$(which pwgen)
openssl=$(which openssl)
if [ -x "$pwgen" ]; then
$pwgen -s1 "$1" | tr -d '\n'
elif [ -x "$openssl" ]; then
$openssl rand -hex "$1" | tr -d '\n'
else
head /dev/urandom | tr -dc 'A-Za-z0-9' | head -c "$1"
fi
}
IP_ADDR=$(ip -o -4 addr list | awk '$2 != "lo" && $2 != "docker0" {print $4; exit}' | cut -d/ -f1)
SEED_USER_PASSWORD=$(rand 18)
CONSOLE_TOKEN=$(rand 18)
BULKER_TOKEN=$(rand 18)
SYNCCTL_TOKEN=$(rand 18)
PG_PASSWD=$(rand 18)
MONGO_PASSWD=$(rand 18)
CLICKHOUSE_PASSWD=$(rand 18)
REDIS_PASSWD=$(rand 18)
JWT_SECRET=$(rand 64)
if [ -r "./template.env" ] && [ ! -f ".env" ]; then
echo "Generating .env from template.env"
sed -r \
-e "s!%%IP_ADDR%%!$IP_ADDR!g" \
-e "s!%%SEED_USER_PASSWORD%%!$SEED_USER_PASSWORD!g" \
-e "s!%%CONSOLE_TOKEN%%!$CONSOLE_TOKEN!g" \
-e "s!%%BULKER_TOKEN%%!$BULKER_TOKEN!g" \
-e "s!%%SYNCCTL_TOKEN%%!$SYNCCTL_TOKEN!g" \
-e "s!%%PG_PASSWD%%!$PG_PASSWD!g" \
-e "s!%%MONGO_PASSWD%%!$MONGO_PASSWD!g" \
-e "s!%%CLICKHOUSE_PASSWD%%!$CLICKHOUSE_PASSWD!g" \
-e "s!%%REDIS_PASSWD%%!$REDIS_PASSWD!g" \
-e "s!%%JWT_SECRET%%!$JWT_SECRET!g" \
"./template.env" >".env"
fi
if [ -r "./docker-compose.yml" ]; then
chown_dir 1001 1001 ./data/kafka
chown_dir 10000 10000 ./data/redis
docker compose up -d
else
echo "Missing docker-compose.yml"
fi