安装软件
1
$ apt-get install git git-core gem ruby jekyll ruby-bundler
配置 Git
1
2
$ git config --global user.name "FoamValue"
$ git config --global user.email "foamvalue@live.cn"
生成 SSH
1
2
3
4
5
6
$ cd ~
$ mkdir .ssh
$ cd .ssh
$ ssh-keygen -t rsa
$ cat id_rsa.pub # 查看 SSH
创建 hooks 目录
1
2
3
4
5
6
$ mkdir /root/gitHooks
$ cd /root/gitHooks/foamvalue.git
$ git init --bare
$ mkdir /root/gitHooks/tmp
$ mkdir /root/gitHooks/www
编辑 hooks/post-receive
1
2
3
4
5
6
7
#!/bin/bash
GIT_REPO=https://github.com/FoamValue/foamvalue.github.com.git #git 仓库
TMP_GIT_CLONE=/root/gitHooks/tmp # 源码目录
PUBLIC_WWW=/root/gitHooks/www #网站目录
rm -rf ${TMP_GIT_CLONE}
git clone ${GIT_REPO} ${TMP_GIT_CLONE}
exit
执行权限
1
$ chmod +x hooks/post-receive
安装 Jekyll && 插件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ gem install jekyll
$ gem install bundle
$ gem install 'jekyll-feed'
$ gem install 'jekyll-paginate'
$ gem install 'jekyll-watch'
$ gem install 'jekyll-assets'
$ gem install 'jekyll-tagging'
$ gem install 'pygments.rb'
$ gem install 'jekyll-seo-tag'
$ gem install 'jekyll-sitemap'
$ cd /root/gitHooks/foamvalue.git
$ bunder install
修改 hooks/post-receive
1
2
3
4
5
6
7
8
9
10
11
12
13
14
root@iZuf6ha54l79m3yqzo8x2lZ:~/gitHooks# ./foamvalue.git/hooks/post-receive
#!/bin/bash
GIT_REPO=https://github.com/FoamValue/foamvalue.github.com.git #git 仓库
TMP_GIT_CLONE=/root/gitHooks/tmp # 源码目录
PUBLIC_WWW=/root/gitHooks/www #网站目录
#rm -rf ${TMP_GIT_CLONE}
rm -rf ${PUBLIC_WWW}/*
cd ${TMP_GIT_CLONE}
git pull
#git clone ${GIT_REPO} ${TMP_GIT_CLONE}
bundle exec jekyll build --source ${TMP_GIT_CLONE} --destination ${PUBLIC_WWW}
exit
最后,就能将 /root/gitHooks/www/*,cp -R 覆盖到 nginx 的 www 目录下了。