-
Notifications
You must be signed in to change notification settings - Fork 44
/
entrypoint.sh
executable file
·89 lines (68 loc) · 2.07 KB
/
entrypoint.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
#!/bin/zmicro
help() {
echo "Usage:"
echo " chatgpt-for-chatbot-feishu"
}
core() {
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
help
exit 0
fi
dotenv::try_load
local PORT=${PORT:-8080}
local API_PATH=${API_PATH:-"/"}
log::info "[$(timestamp)] run chatgpt for chatbot feishu with zmicro ..."
if [ "$TUNNEL_ENABLE" = "true" ]; then
runtunnel
fi
log::info "[$(timestamp)] starting chatgpt for chatbot feishu ..."
chatgpt-for-chatbot-feishu
}
runtunnel() {
local tunnel_type="$TUNNEL_TYPE"
local tunnel_auth_token="$TUNNEL_AUTH_TOKEN"
local tunnel_subdomain="$TUNNEL_SUBDOMAIN"
local tunnel_log=$(os::tmp_file)
echo
log::info "[$(timestamp)] enable tunnel $tunnel_type (logfile: $tunnel_log)..."
# TUNNEL NGROK
if [ "$tunnel_type" = "ngrok" ]; then
if [ -n "$tunnel_subdomain" ] && [ -z "$tunnel_auth_token" ]; then
log::error "[$(timestamp)] tunnel_auth_token is required when use tunnel_subdomain"
return 1
fi
if [ -n "$tunnel_auth_token" ]; then
zmicro ngrok config add-authtoken $tunnel_auth_token >>/dev/null
fi
if [ -n "$tunnel_subdomain" ]; then
zmicro ngrok http --subdomain "$tunnel_subdomain" ${PORT} --log $tunnel_log >>$tunnel_log 2>&1 &
else
zmicro ngrok http ${PORT} --log $tunnel_log >>$tunnel_log 2>&1 &
fi
log::info "[$(timestamp)] starting ngrok ..."
# sleep 3
local url=""
while [ -z "$url" ]; do
sleep 1
log::info "[$(timestamp)] checking whether ngrok connected ..."
url=$(cat $tunnel_log | grep "url=" | head -n 1 | awk -F '=' '{print $8}')
if [ -n "$url" ]; then
break
fi
if [ "$DEBUG" = "true" ]; then
log::info "[$(timestamp)] show ngrok connection info start ..."
cat $tunnel_log
log::info "[$(timestamp)] show ngrok connection info end ..."
fi
done
log::info "[$(timestamp)] ngrok url: $(color::green $url)"
export SITE_URL=$url
else
log::error "[$(timestamp)] unsupport TUNNEL_TYPE: $TUNNEL_TYPE"
return 1
fi
}
run() {
core "$@"
}
run "$@"