Skip to content

Instantly share code, notes, and snippets.

@horsley
Last active December 27, 2015 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save horsley/7269392 to your computer and use it in GitHub Desktop.
Save horsley/7269392 to your computer and use it in GitHub Desktop.
一个简单的post hook用来自动部署
<?php
/**
* 简单自动部署
* bitbucket POST hook http://horsley:anypassword@your_host/autodeploy.php
*/
define('APP_PATH', dirname(__FILE__));
if (php_sapi_name() != 'cli') {
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
die('Restricted Area!');
} else {
if (($_SERVER['PHP_AUTH_USER'] != 'horsley') ||
($_SERVER['PHP_AUTH_PW'] != 'anypassword')
) {
die('Authentication Failed.');
}
}
}
if (file_exists(APP_PATH.'/_before_deploy.php')) {
echo "====== Tasks before update ======\n";
require(APP_PATH.'/_before_deploy.php');
}
echo "\n\n====== Now update the repo ======\n";
chdir();
system('git pull');
if (file_exists(APP_PATH.'/_after_deploy.php')) {
echo "\n\n====== Tasks after update ======\n";
require(APP_PATH.'/_after_deploy.php');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment