@@ -21,6 +21,10 @@ LANGUAGE="en_US"
21
21
# Determine the source URL to download files
22
22
SOURCE_URL=" https://raw.githubusercontent.com/lobehub/lobe-chat/main"
23
23
24
+ # Arg: --host
25
+ # Determine the server host
26
+ HOST=" "
27
+
24
28
# 2. Parse script arguments
25
29
while getopts " fl:-:" opt; do
26
30
case $opt in
@@ -40,8 +44,12 @@ while getopts "fl:-:" opt; do
40
44
SOURCE_URL=" ${! OPTIND} "
41
45
OPTIND=$(( $OPTIND + 1 ))
42
46
;;
47
+ host)
48
+ HOST=" ${! OPTIND} "
49
+ OPTIND=$(( $OPTIND + 1 ))
50
+ ;;
43
51
* )
44
- echo " Usage: $0 [-f] [-l language|--lang language] [--url source]" >&2
52
+ echo " Usage: $0 [-f] [-l language|--lang language] [--url source] [--host serverhost] " >&2
45
53
exit 1
46
54
;;
47
55
esac
@@ -122,13 +130,43 @@ show_message() {
122
130
;;
123
131
esac
124
132
;;
133
+ security_secrect_regenerate)
134
+ case $LANGUAGE in
135
+ zh_CN)
136
+ echo " éę°ēęå®å
ØåÆé„..."
137
+ ;;
138
+ * )
139
+ echo " Regenerate security secrets..."
140
+ ;;
141
+ esac
142
+ ;;
143
+ security_secrect_regenerate_failed)
144
+ case $LANGUAGE in
145
+ zh_CN)
146
+ echo " ę ę³éę°ēęå®å
ØåÆé„ļ¼"
147
+ ;;
148
+ * )
149
+ echo " Failed to regenerate security secrets: "
150
+ ;;
151
+ esac
152
+ ;;
153
+ security_secrect_regenerate_report)
154
+ case $LANGUAGE in
155
+ zh_CN)
156
+ echo " å®å
ØåÆé„ēęē»ęå¦äøļ¼"
157
+ ;;
158
+ * )
159
+ echo " Security secret generation results are as follows:"
160
+ ;;
161
+ esac
162
+ ;;
125
163
tips_run_command)
126
164
case $LANGUAGE in
127
165
zh_CN)
128
- echo " ęØå·²ē»å®ęäŗęęé
ē½®ę件ēäøč½½ ćčÆ·čæč”仄äøå½ä»¤åÆåØLobeChatļ¼"
166
+ echo " ęØå·²ē»å®ęäŗęęé
ē½® ćčÆ·čæč”仄äøå½ä»¤åÆåØLobeChatļ¼"
129
167
;;
130
168
* )
131
- echo " You have completed downloading all configuration files . Please run this command to start LobeChat:"
169
+ echo " You have completed all configurations . Please run this command to start LobeChat:"
132
170
;;
133
171
esac
134
172
;;
@@ -155,10 +193,10 @@ show_message() {
155
193
tips_warning)
156
194
case $LANGUAGE in
157
195
zh_CN)
158
- echo " č¦åļ¼äøč¦åØēäŗ§ēÆå¢äøä½æēØę¤ę¼ē¤ŗåŗēØēØåŗ ļ¼ļ¼ļ¼"
196
+ echo " č¦åļ¼å¦ęä½ ę£åØēäŗ§ēÆå¢äøä½æēØļ¼čÆ·åØę„åæäøę£ę„åÆé„ęÆå¦å·²ē»ēę ļ¼ļ¼ļ¼"
159
197
;;
160
198
* )
161
- echo " Warning: do not use this demo application in production!!!"
199
+ echo " Warning: If you are using it in a production environment, please check if the keys have been generated in the logs !!!"
162
200
;;
163
201
esac
164
202
;;
@@ -235,7 +273,91 @@ download_file "$SOURCE_URL/${FILES[3]}" "s3_data.tar.gz"
235
273
extract_file " s3_data.tar.gz" " ."
236
274
rm s3_data.tar.gz
237
275
238
- # Display final message
276
+ # ==========================
277
+ # === Regenerate Secrets ===
278
+ # ==========================
279
+
280
+ generate_key () {
281
+ if [[ -z " $1 " ]]; then
282
+ echo " Usage: generate_key <length>"
283
+ return 1
284
+ fi
285
+ echo $( openssl rand -hex $1 | tr -d ' \n' | fold -w $1 | head -n 1)
286
+ }
287
+
288
+ echo $( show_message " security_secrect_regenerate" )
289
+
290
+ # Generate CASDOOR_SECRET
291
+ CASDOOR_SECRET=$( generate_key 32)
292
+ if [ $? -ne 0 ]; then
293
+ echo $( show_message " security_secrect_regenerate_failed" ) " CASDOOR_SECRET"
294
+ else
295
+ # Search and replace the value of CASDOOR_SECRET in .env
296
+ sed -i " s#^AUTH_CASDOOR_SECRET=.*#AUTH_CASDOOR_SECRET=${CASDOOR_SECRET} #" .env
297
+ if [ $? -ne 0 ]; then
298
+ echo $( show_message " security_secrect_regenerate_failed" ) " AUTH_CASDOOR_SECRET in \` .env\` "
299
+ fi
300
+ # replace `clientSecrect` in init_data.json
301
+ sed -i " s#dbf205949d704de81b0b5b3603174e23fbecc354#${CASDOOR_SECRET} #" init_data.json
302
+ if [ $? -ne 0 ]; then
303
+ echo $( show_message " security_secrect_regenerate_failed" ) " AUTH_CASDOOR_SECRET in \` init_data.json\` "
304
+ fi
305
+ fi
306
+
307
+ # Generate Casdoor User
308
+ CASDOOR_USER=" admin"
309
+ CASDOOR_PASSWORD=$( generate_key 6)
310
+ if [ $? -ne 0 ]; then
311
+ echo $( show_message " security_secrect_regenerate_failed" ) " CASDOOR_PASSWORD"
312
+ else
313
+ # replace `password` in init_data.json
314
+ sed -i " s/" 123" /${CASDOOR_PASSWORD} /" init_data.json
315
+ if [ $? -ne 0 ]; then
316
+ echo $( show_message " security_secrect_regenerate_failed" ) " CASDOOR_PASSWORD in \` init_data.json\` "
317
+ fi
318
+ fi
319
+
320
+ # Generate Minio S3 access key
321
+ # Temporarily disable key gen for minio because
322
+ # minio can not start with a access key in envs
323
+ # S3_SECRET_ACCESS_KEY=$(generate_key 32)
324
+ # if [ $? -ne 0 ]; then
325
+ # echo $(show_message "security_secrect_regenerate_failed") "S3_SECRET_ACCESS_KEY"
326
+ # else
327
+ # # Search and replace the value of S3_SECRET_ACCESS_KEY in .env
328
+ # sed -i "s#^S3_SECRET_ACCESS_KEY=.*#S3_SECRET_ACCESS_KEY=${S3_SECRET_ACCESS_KEY}#" .env
329
+ # if [ $? -ne 0 ]; then
330
+ # echo $(show_message "security_secrect_regenerate_failed") "S3_SECRET_ACCESS_KEY in \`.env\`"
331
+ # fi
332
+ # fi
333
+
334
+ # Modify the .env file if the host is specified
335
+ if [ -n " $HOST " ]; then
336
+ # Modify env
337
+ sed -i " s/localhost/$HOST /g" .env
338
+ if [ $? -ne 0 ]; then
339
+ echo $( show_message " security_secrect_regenerate_failed" ) " HOST in \` .env\` "
340
+ fi
341
+ # Modify casdoor init data
342
+ sed -i " s/localhost/$HOST /g" init_data.json
343
+ if [ $? -ne 0 ]; then
344
+ echo $( show_message " security_secrect_regenerate_failed" ) " HOST in \` init_data.json\` "
345
+ fi
346
+ fi
347
+
348
+ # Display configuration reports
349
+
350
+ echo $( show_message " security_secrect_regenerate_report" )
351
+
352
+ if [ -n " $HOST " ]; then
353
+ echo -e " Server Host: $HOST "
354
+ fi
355
+ echo -e " Casdoor: \n - Username: admin\n - Password: ${CASDOOR_PASSWORD} \n - Client Secret: ${CASDOOR_SECRET} "
356
+
357
+ # ===========================
358
+ # == Display final message ==
359
+ # ===========================
360
+
239
361
printf " \n%s\n\n" " $( show_message " tips_run_command" ) "
240
362
print_centered " docker compose up -d" " green"
241
363
printf " \n%s" " $( show_message " tips_show_documentation" ) "
0 commit comments