forked from quericy/surgio-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-entrypoint.sh
39 lines (33 loc) · 1.08 KB
/
docker-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
#!/bin/bash
# timezone
ln -sf /usr/share/zoneinfo/${TZ:-"Asia/Shanghai"} /etc/localtime
echo ${TZ:-"Asia/Shanghai"} > /etc/timezone
# create gateway
\cp -rf /gateway.js /surgio/
# custom config
config_dir="/var/config"
if [ -d $config_dir ]&&[ "$(ls -A $config_dir)" ];then
rm -rf /surgio/provider/* /surgio/template/*
\cp -rf /var/config/* /surgio/
fi
if [ -f /surgio/package.json ];then
sed -i '/"scripts": {/a "generage": "surgio generate",' /surgio/package.json
fi
# add cron job
cat /dev/null > /etc/crontabs/root # clear cron job
if [ $AUTOGEN_INTERVAL ];then
hour=$(echo "$AUTOGEN_INTERVAL" | grep -oP '\d+(?=h)')
minute=$(echo "$AUTOGEN_INTERVAL" | grep -oP '\d+(?=m)')
if [[ -n $hour ]] && [[ -n $minute ]]; then
cron_time="*/$minute */$hour * * *"
elif [[ -n $hour ]]; then
cron_time="0 */$hour * * *"
elif [[ -n $minute ]]; then
cron_time="*/$minute * * * *"
fi
echo "$cron_time cd /surgio && npx surgio generate" >> /etc/crontabs/root
crond
fi
# generate rules and run gateway
cd /surgio
npm run generage && node gateway.js