This repository has been archived by the owner on Mar 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-config.sh
executable file
·86 lines (67 loc) · 1.66 KB
/
setup-config.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
#!/bin/bash
echo "Welcome to Codename Meiling Configuration Utility"
echo
echo "Copyright (c) Stella IT Co, Ltd. and Meiling Project Contributors"
echo
input=""
get_input() {
echo -n "$1";
read -r input;
}
get_password_input() {
echo -n "$1";
read -rs input;
echo
}
if_no_exit() {
tmp_choice="$1"
test -n "$tmp_choice" || tmp_choice='Y'
tmp_choice=$(echo "$1" | awk '{print tolower($0)}')
test "$tmp_choice" == "n" && echo "Ending session..."
test "$tmp_choice" == "n" && exit 1
}
if [ -f ".env" ]; then
echo "Error: dotenv file already exists."
echo "If you want to reconfigure, please delete the dotenv file"
exit 1
fi
# === Database part ===
echo "Database Configuration:"
get_input " Database Host: "
db_host="$input"
get_input " Database User: "
db_user="$input"
get_password_input " Database Password: "
db_pass="$input"
get_input " Database name: "
db_name="$input"
echo
echo "Database Configuration:"
echo " Database Host: $db_host"
echo " Database User: $db_user"
echo " Database Password: [REDACTED]"
echo " Database name: $db_name"
echo
get_input "Are these correct? (Y/n): "
if_no_exit "$input"
echo
# === Webserver part ===
echo "WebServer Configuration:"
get_input " Bind Host: "
bind_host="$input"
get_input " Bind Port: "
bind_port="$input"
echo
echo "WebServer Configuration:"
echo " Bind Host: $bind_host"
echo " Bind Port: $bind_port"
echo
get_input "Are these correct? (Y/n): "
if_no_exit "$input"
echo
# === Writing Config ===
echo "Writing Config..."
touch .env
echo "DATABASE_URL=\"mysql://$db_user:$db_pass@$db_host/$db_name\"" >> .env
echo "BIND_ADDRESS=\"$bind_host:$bind_port\"" >> .env
echo "Configuration Complete!"