<?php

require_once realpath(dirname(__FILE__)) . '/../common.php';
require_once FRAMEWORK_PATH . 'protected/bin/common_script.php';

if (!singleProcess(getCurrentCommand(), '/data/webapps/gitbook.duowan.com/duowan_wiki/index.pid')) {
    exit("Sorry, this script file has already been running ...\n");
}

error_reporting(E_ERROR);


$cmdType =  $_GET["cmd_type"]);

function gitPull()
{
    shell_exec("cd /data/webapps/gitbook.duowan.com/duowan_wiki && git pull");
}

function gitbookBuild()
{
	shell_exec("cd /data/webapps/gitbook.duowan.com/duowan_wiki && gitbook build");
}

function gitbookInstall()
{
	shell_exec("cd /data/webapps/gitbook.duowan.com/duowan_wiki && gitbook install");
}


if ("pull_rebuild" === $cmdType) {
	gitPull();
	gitbookBuild();
} 

if ("install" === $cmdType) {
	gitPull();
	gitbookInstall()
	gitbookBuild();
}



header("HTTP/1.1 200 OK");
echo("hook finish");