Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //
- // Start with: sudo php deploy.php file_to_deploy.zip
- //
- $version = substr(sha1_file(__FILE__), 0, 7);
- echo "Deployment script version: " . $version . "\n";
- if (posix_getuid() == 0) {
- echo "Check if root: OK\n";
- } else {
- echo "Check if root: ERROR - Run: sudo php " . basename(__FILE__) . " file.zip\n";
- exit;
- }
- if(empty($argv[1])) {
- echo "Parameter required\n";
- echo "Run: sudo php " . basename(__FILE__) . " file.zip\n";
- exit;
- }
- $zipFile = $argv[1];
- $liveDir = __DIR__ . '/htdocs';
- $liveBackupDir = __DIR__ . '/htdocs_' . date('Y-m-d H-i-s');
- $liveDirApp = __DIR__ . '/htdocs/app';
- $releaseDir = __DIR__ . '/release/';
- // Remove existing release directory
- if(file_exists($releaseDir)) {
- echo "Remove $releaseDir\n";
- system('rm -R ' . $releaseDir);
- }
- // Extract artifact (Zip file) to release directory
- $zip = new ZipArchive();
- if ($zip->open($zipFile) === TRUE) {
- echo "Extract ZIP file to: $releaseDir\n";
- $zip->extractTo(__DIR__ . '/release/');
- $zip->close();
- echo "Extract ZIP file: OK\n";
- } else {
- echo "Extract ZIP file: ERROR\n";
- }
- if (file_exists($releaseDir)) {
- // Backup current live version
- echo "Rename $liveDir to $liveBackupDir\n";
- rename($liveDir, $liveBackupDir);
- // Install new live version
- echo "Rename $releaseDir to $liveDir\n";
- rename($releaseDir, $liveDir);
- }
- echo "Change to app directory: $liveDirApp\n";
- chdir($liveDirApp);
- echo "Set permissions...\n";
- //system('php Console/Cronjobs/30min/permission.php');
- echo "Run migrations...\n";
- //system('php Console/cake.php Migrations.migration status');
- //system('php Console/cake.php Migrations.migration run all');
- echo "Finished\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement