-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
executable file
·168 lines (140 loc) · 3.76 KB
/
install.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
__usage="
Usage: ./install.sh -d DOMAIN -c CERT_PATH -k KEY_PATH
Options:
-d, --domain User Domain. Required.
-c, --cert SSL Certificate PATH. Required.
-k, --key SSL Certificate Key PATH. Required.
"
help()
{
echo "$__usage"
}
if [ "$#" -eq 0 ] ; then
help
exit 1
fi
parseargs()
{
while [ "x$#" != "x0" ] ;
do
if [ "x$1" == "x-h" -o "x$1" == "x--help" ] ; then
help
return 1
elif [ "x$1" == "x" ] ; then
shift
elif [ "x$1" == "x-d" -o "x$1" == "x--domain" ] ; then
USER_DOMAIN=$2
shift
shift
elif [ "x$1" == "x-c" -o "x$1" == "x--cert" ] ; then
SSL_CERT_PATH=$2
shift
shift
elif [ "x$1" == "x-k" -o "x$1" == "x--key" ] ; then
SSL_CERT_KEY_PATH=$2
shift
shift
else
echo Error: UNKNOWN params "$@"
help
shift
fi
done
}
parseargs "$@" || exit 1
if [ -z "$USER_DOMAIN" ] || [ -z "$SSL_CERT_PATH" ] || [ -z "$SSL_CERT_KEY_PATH" ] ; then
echo "Error: Missing required arguments."
help
exit 1
fi
echo $USER_DOMAIN
check_certificate()
{
if [ "$#" -ne 1 ] ; then
echo "Error: missing argument."
return 1
fi
openssl x509 -in "$1" -text -noout
}
check_key()
{
if [ "$#" -ne 1 ] ; then
echo "Error: missing argument."
return 1
fi
openssl rsa -in "$1" -check
}
generate_password()
{
local password=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
echo "$password"
}
check_env_file()
{
if test -f .env ; then
sed -i "s/^USER_DOMAIN=.*/USER_DOMAIN=$USER_DOMAIN/" .env
else
echo "USER_DOMAIN=$USER_DOMAIN" >> .env
MYSQL_ROOT_PASSWORD=$(generate_password)
echo "MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD" >> .env
MYSQL_PASSWORD=$(generate_password)
echo "MYSQL_PASSWORD=$MYSQL_PASSWORD" >> .env
REDIS_PASSWORD=$(generate_password)
echo "REDIS_PASSWORD=$REDIS_PASSWORD" >> .env
echo "MYSQL_DATABASE=aoplatform" >> .env
echo "MYSQL_USER=aoplatform" >> .env
echo "HEALTHCHECK_INTERVAL=10s" >> .env
echo "HEALTHCHECK_TIMEOUT=5s" >> .env
echo "HEALTHCHECK_RETRIES=5" >> .env
echo "NGINX_BIND_HTTP=80" >> .env
echo "NGINX_BIND_HTTPS=443" >> .env
echo "PROXY_LOCAL_BIND=61011" >> .env
echo "NETWORK_BIND=61012" >> .env
echo "SERVICES_LOCAL_BIND=61013" >> .env
echo "LOGGING_MAX_SIZE=500m" >> .env
echo "LOGGING_MAX_FILE=3" >> .env
echo "CONTAINER_RESTART_POLICY=always" >> .env
echo "TZ=Asia/Shanghai" >> .env
fi
}
if ! check_certificate "$SSL_CERT_PATH" ; then
echo "Error: Invalid SSL certificate."
exit 1
fi
if ! check_key "$SSL_CERT_KEY_PATH" ; then
echo "Error: Invalid SSL key."
exit 1
fi
if ! [[ $USER_DOMAIN =~ ^[a-zA-Z0-9][a-zA-Z0-9-]*(\.[a-zA-Z0-9][a-zA-Z0-9-]*)+$ ]] ; then
echo "Error: Invalid domain name."
exit 1
fi
update_ssl()
{
cat "$SSL_CERT_PATH" > "data/ssl/tls.crt"
cat "$SSL_CERT_KEY_PATH" > "data/ssl/tls.key"
}
check_dir()
{
dirs=("./data/ssl" "./data/aoplatform-services/data" "./data/aoplatform-redis/data" "./data/aoplatform-mysql/data")
for dir in "${dirs[@]}" ; do
if [ -d "$dir" ] ; then
echo "$dir exists."
else
mkdir -p $dir
fi
done
dir="./data/aoplatform-services/data"
if stat -c "%u" "$dir" | grep -q "1001" ; then
echo "$dir has correct permissions."
else
chown -R 1001:1001 "$dir"
echo "$dir permissions have been changed."
fi
}
check_env_file
check_dir
update_ssl
docker-compose down
docker-compose up -d