This repository has been archived by the owner on Feb 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathentrypoint.sh
57 lines (49 loc) · 1.5 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
#!/bin/bash
set -xe
# Aliyun
if [ "$APT_MIRRORS" = "aliyun" ];then
sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
npm config set registry https://registry.npm.taobao.org --global
npm config set disturl https://npm.taobao.org/dist --global
yarn config set registry https://registry.npm.taobao.org --global
yarn config set disturl https://npm.taobao.org/dist --global
fi
# Init
if [ ! -f "/opt/hexo/_config.yml" ];then
hexo init .
yarn install
fi
# Deploy
if [ ! -f "/opt/hexo/deploy.sh" ];then
cp /var/lib/hexo/deploy.sh /opt/hexo
fi
if [ ! -f "/opt/hexo/index.js" ];then
cp /var/lib/hexo/index.js /opt/hexo/index.js
[ -z $WEBHOOK_SECRET ] && WEBHOOK_SECRET=123456
sed -i "s/WEBHOOK_SECRET/$WEBHOOK_SECRET/" /opt/hexo/index.js
# Github webhook
if [ ! -z $GITHUB ];then
yarn add github-webhook-handler
sed -i "s/WEBHOOK-HANDLER/github-webhook-handler/" /opt/hexo/index.js
rm -rf /opt/hexo/source/_posts
git clone $GITHUB /opt/hexo/source/_posts
pm2 start index.js --name hexo
/opt/hexo/deploy.sh
fi
# Gitlab webhook
if [ ! -z $GITLAB ];then
yarn add node-gitlab-webhook
sed -i "s/WEBHOOK-HANDLER/node-gitlab-webhook/" /opt/hexo/index.js
rm -rf /opt/hexo/source/_posts
git clone $GITLAB /opt/hexo/source/_posts
pm2 start index.js --name hexo
/opt/hexo/deploy.sh
fi
else
pm2 start index.js --name hexo
hexo clean && hexo g
fi
# Nginx
[ -z $IP_OR_DOMAIN ] && IP_OR_DOMAIN=$(hostname -i)
sed -i "s/IP_OR_DOMAIN/$IP_OR_DOMAIN/" /etc/nginx/conf.d/hexo.conf
exec "$@"