-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathsetup.sh
executable file
·114 lines (101 loc) · 3.25 KB
/
setup.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
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
#!/usr/bin/env bash
HULY_VERSION="v0.6.411"
DOCKER_NAME="huly"
CONFIG_FILE="huly.conf"
if [ -f "$CONFIG_FILE" ]; then
source "$CONFIG_FILE"
fi
while true; do
if [[ -n "$HOST_ADDRESS" ]]; then
prompt_type="current"
prompt_value="${HOST_ADDRESS}"
else
prompt_type="default"
prompt_value="localhost"
fi
read -p "Enter the host address (domain name or IP) [${prompt_type}: ${prompt_value}]: " input
_HOST_ADDRESS="${input:-${HOST_ADDRESS:-localhost}}"
break
done
while true; do
if [[ -n "$HTTP_PORT" ]]; then
prompt_type="current"
prompt_value="${HTTP_PORT}"
else
prompt_type="default"
prompt_value="80"
fi
read -p "Enter the port for HTTP [${prompt_type}: ${prompt_value}]: " input
_HTTP_PORT="${input:-${HTTP_PORT:-80}}"
if [[ "$_HTTP_PORT" =~ ^[0-9]+$ && "$_HTTP_PORT" -ge 1 && "$_HTTP_PORT" -le 65535 ]]; then
break
else
echo "Invalid port. Please enter a number between 1 and 65535."
fi
done
echo "$_HOST_ADDRESS $HOST_ADDRESS $_HTTP_PORT $HTTP_PORT"
if [[ "$_HOST_ADDRESS" == "localhost" || "$_HOST_ADDRESS" == "127.0.0.1" || "$_HOST_ADDRESS" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}:?$ ]]; then
_HOST_ADDRESS="${_HOST_ADDRESS%:}:${_HTTP_PORT}"
SECURE=""
else
while true; do
if [[ -n "$SECURE" ]]; then
prompt_type="current"
prompt_value="Yes"
else
prompt_type="default"
prompt_value="No"
fi
read -p "Will you serve Huly over SSL? (y/n) [${prompt_type}: ${prompt_value}]: " input
case "${input}" in
[Yy]* )
_SECURE="true"; break;;
[Nn]* )
_SECURE=""; break;;
"" )
_SECURE="${SECURE:+true}"; break;;
* )
echo "Invalid input. Please enter Y or N.";;
esac
done
fi
SECRET=false
if [ "$1" == "--secret" ]; then
SECRET=true
fi
if [ ! -f .huly.secret ] || [ "$SECRET" == true ]; then
openssl rand -hex 32 > .huly.secret
echo "Secret generated and stored in .huly.secret"
else
echo -e "\033[33m.huly.secret already exists, not overwriting."
echo "Run this script with --secret to generate a new secret."
fi
export HOST_ADDRESS=$_HOST_ADDRESS
export SECURE=$_SECURE
export HTTP_PORT=$_HTTP_PORT
export HTTP_BIND=$HTTP_BIND
export TITLE=${TITLE:-Huly}
export DEFAULT_LANGUAGE=${DEFAULT_LANGUAGE:-en}
export LAST_NAME_FIRST=${LAST_NAME_FIRST:-true}
export HULY_SECRET=$(cat .huly.secret)
envsubst < .template.huly.conf > $CONFIG_FILE
echo -e "\n\033[1;34mConfiguration Summary:\033[0m"
echo -e "Host Address: \033[1;32m$_HOST_ADDRESS\033[0m"
echo -e "HTTP Port: \033[1;32m$_HTTP_PORT\033[0m"
if [[ -n "$SECURE" ]]; then
echo -e "SSL Enabled: \033[1;32mYes\033[0m"
else
echo -e "SSL Enabled: \033[1;31mNo\033[0m"
fi
read -p "Do you want to run 'docker compose up -d' now to start Huly? (Y/n): " RUN_DOCKER
case "${RUN_DOCKER:-Y}" in
[Yy]* )
echo -e "\033[1;32mRunning 'docker compose up -d' now...\033[0m"
sudo docker compose up -d
;;
[Nn]* )
echo "You can run 'docker compose up -d' later to start Huly."
;;
esac
echo -e "\033[1;32mSetup is complete!\n Generating nginx.conf...\033[0m"
./nginx.sh