jekyll post-receive 例

Posted by 韩同学的笔记本 on May 28, 2020
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
#!/bin/bash

export GEM_HOME=$HOME/gems
export PATH=$GEM_HOME/bin:$PATH
export GEMFILE_LOCKER_DIR=$HOME/Gemfile_lock_backup/jblog
export GEMFILE_LOCKER=$GEMFILE_LOCKER_DIR/Gemfile.lock

GIT_REPO=$HOME/jblog.git
TMP_GIT_CLONE=$HOME/jblog
GEMFILE=$TMP_GIT_CLONE/Gemfile
PUBLIC_WWW=/var/www/jblog

if [ ! -d $GEMFILE_LOCKER_DIR ]; then
  mkdir -p $GEMFILE_LOCKER_DIR;
fi

rm -Rf $TMP_GIT_CLONE
git clone $GIT_REPO $TMP_GIT_CLONE
sed -i "/^.*京ICP备.*$/d" $TMP_GIT_CLONE/_includes/footer.html
# sed -i "/^.*disqus.*$/d" $TMP_GIT_CLONE/_config.yml

if [ -f $GEMFILE_LOCKER ]; then
  cp $GEMFILE_LOCKER $TMP_GIT_CLONE/Gemfile.lock;
else
  BUNDLE_GEMFILE=$GEMFILE bundle install;
  cp $TMP_GIT_CLONE/Gemfile.lock $GEMFILE_LOCKER ;
fi

BUNDLE_GEMFILE=$GEMFILE bundle exec jekyll build -s $TMP_GIT_CLONE -d $PUBLIC_WWW
chown -R git:www $PUBLIC_WWW
chmod -R g+rwx $PUBLIC_WWW
rm -Rf $TMP_GIT_CLONE
exit