Created
September 8, 2012 23:26
-
-
Save thinkstylestudio/3680991 to your computer and use it in GitHub Desktop.
bitbucket deploy script for shared hosting.from http://www.stephenradford.me/blog/tutorials/deploy-via-bitbucket-or-github-service-hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Set these dependant on your BB credentials | |
$username = 'username'; | |
$password = 'password'; | |
// Grab the data from BB's POST service and decode | |
$json = stripslashes($_POST['payload']); | |
$data = json_decode($json); | |
// Set some parameters to fetch the correct files | |
$uri = $data->repository->absolute_url; | |
$node = $data->commits[0]->node; | |
$files = $data->commits[0]->files; | |
// Foreach through the files and curl them over | |
foreach ($files as $file) { | |
if ($file->type == "removed") { | |
unlink($file->file); | |
} else { | |
$url = "https://api.bitbucket.org/1.0/repositories".$uri."raw/".$node."/".$file->file; | |
$path = $file->file; | |
$dirname = dirname($path); | |
if (!is_dir($dirname)){ | |
mkdir($dirname, 0775, true); | |
} | |
$fp = fopen($path, 'w'); | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ch, CURLOPT_FILE, $fp); | |
$data = curl_exec($ch); | |
curl_close($ch); | |
fclose($fp); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment