| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Publishes a Bitten build to the public build server. |
|---|
| 4 | * |
|---|
| 5 | * @author Joel Low <lowjoel@users.sourceforge.net> |
|---|
| 6 | * @version $Id$ |
|---|
| 7 | */ |
|---|
| 8 | |
|---|
| 9 | if (count($argv) < 4) |
|---|
| 10 | { |
|---|
| 11 | echo 'There are insufficient arguments for BuildPublish.php.' . "\n\n" . |
|---|
| 12 | 'Usage: BuildPublish.php <branch name> <revision> <installer>'; |
|---|
| 13 | exit(1); |
|---|
| 14 | } |
|---|
| 15 | |
|---|
| 16 | require_once('Credentials.php'); |
|---|
| 17 | require_once('Database.php'); |
|---|
| 18 | require_once('Build.php'); |
|---|
| 19 | |
|---|
| 20 | $file = fopen($argv[3], 'rb'); |
|---|
| 21 | if (!$file) |
|---|
| 22 | { |
|---|
| 23 | echo 'The file ' . $argv[3] . ' could not be opened for reading.'; |
|---|
| 24 | exit(1); |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | try |
|---|
| 28 | { |
|---|
| 29 | //Generate a filename for the installer. |
|---|
| 30 | $branches = BuildBranch::Get(); |
|---|
| 31 | if (!array_key_exists($argv[1], $branches)) |
|---|
| 32 | throw new Exception('The branch ' . $argv[1] . ' does not exist.'); |
|---|
| 33 | |
|---|
| 34 | define('SHELL_WEB_ROOT', 'sftp://web.sourceforge.net/home/groups/e/er/eraser/htdocs'); |
|---|
| 35 | define('HTTP_WEB_ROOT', 'http://eraser.sourceforge.net'); |
|---|
| 36 | |
|---|
| 37 | $branch = $branches[$argv[1]]; |
|---|
| 38 | $pathInfo = pathinfo($argv[3]); |
|---|
| 39 | $fileName = sprintf('Eraser %s.%d.%s', $branch->Version, $argv[2], $pathInfo['extension']); |
|---|
| 40 | $installerPath = sprintf('/builds/%s/%s', $branch->ID, $fileName); |
|---|
| 41 | |
|---|
| 42 | //Then upload the installer to the URL. |
|---|
| 43 | Upload(SHELL_WEB_ROOT . $installerPath, $file, $sftp_username, $sftp_password); |
|---|
| 44 | |
|---|
| 45 | //Insert the build to the database. |
|---|
| 46 | printf('Inserting build into database... '); |
|---|
| 47 | Build::CreateBuild($branch->ID, intval($argv[2]), filesize($argv[3]), HTTP_WEB_ROOT . $installerPath); |
|---|
| 48 | printf("Inserted.\n"); |
|---|
| 49 | |
|---|
| 50 | //Remove old builds |
|---|
| 51 | printf('Removing old builds from database...' . "\n"); |
|---|
| 52 | |
|---|
| 53 | $pdo = new Database(); |
|---|
| 54 | $statement = $pdo->prepare('UPDATE downloads SET Superseded=1 WHERE DownloadID=?'); |
|---|
| 55 | |
|---|
| 56 | $builds = Build::GetActive($branch->ID); |
|---|
| 57 | for ($i = 0, $j = count($builds) - 3; $i < $j; ++$i) |
|---|
| 58 | { |
|---|
| 59 | printf("\n\t" . 'Removing build %s' . "\n\t\t", $builds[$i]->Name); |
|---|
| 60 | |
|---|
| 61 | //Delete the copy on the SourceForge web server. |
|---|
| 62 | Delete(SHELL_WEB_ROOT . parse_url($builds[$i]->Link, PHP_URL_PATH), $sftp_username, |
|---|
| 63 | $sftp_password); |
|---|
| 64 | |
|---|
| 65 | //Remove from the database |
|---|
| 66 | $statement->execute(array($builds[$i]->ID)); |
|---|
| 67 | } |
|---|
| 68 | } |
|---|
| 69 | catch (Exception $e) |
|---|
| 70 | { |
|---|
| 71 | echo $e->getMessage(); |
|---|
| 72 | exit(1); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | fclose($file); |
|---|
| 76 | ?> |
|---|