Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. <?php
  2.  
  3. //
  4. // Start with: sudo php deploy.php file_to_deploy.zip
  5. //
  6. $version = substr(sha1_file(__FILE__), 0, 7);
  7. echo "Deployment script version: " . $version . "\n";
  8.  
  9. if (posix_getuid() == 0) {
  10. echo "Check if root: OK\n";
  11. } else {
  12. echo "Check if root: ERROR - Run: sudo php " . basename(__FILE__) . " file.zip\n";
  13. exit;
  14. }
  15.  
  16. if(empty($argv[1])) {
  17. echo "Parameter required\n";
  18. echo "Run: sudo php " . basename(__FILE__) . " file.zip\n";
  19. exit;
  20. }
  21.  
  22. $zipFile = $argv[1];
  23. $liveDir = __DIR__ . '/htdocs';
  24. $liveBackupDir = __DIR__ . '/htdocs_' . date('Y-m-d H-i-s');
  25. $liveDirApp = __DIR__ . '/htdocs/app';
  26. $releaseDir = __DIR__ . '/release/';
  27.  
  28. // Remove existing release directory
  29. if(file_exists($releaseDir)) {
  30. echo "Remove $releaseDir\n";
  31. system('rm -R ' . $releaseDir);
  32. }
  33.  
  34. // Extract artifact (Zip file) to release directory
  35. $zip = new ZipArchive();
  36. if ($zip->open($zipFile) === TRUE) {
  37. echo "Extract ZIP file to: $releaseDir\n";
  38. $zip->extractTo(__DIR__ . '/release/');
  39. $zip->close();
  40. echo "Extract ZIP file: OK\n";
  41. } else {
  42. echo "Extract ZIP file: ERROR\n";
  43. }
  44.  
  45. if (file_exists($releaseDir)) {
  46. // Backup current live version
  47. echo "Rename $liveDir to $liveBackupDir\n";
  48. rename($liveDir, $liveBackupDir);
  49.  
  50. // Install new live version
  51. echo "Rename $releaseDir to $liveDir\n";
  52. rename($releaseDir, $liveDir);
  53. }
  54.  
  55. echo "Change to app directory: $liveDirApp\n";
  56. chdir($liveDirApp);
  57.  
  58. echo "Set permissions...\n";
  59. //system('php Console/Cronjobs/30min/permission.php');
  60.  
  61. echo "Run migrations...\n";
  62. //system('php Console/cake.php Migrations.migration status');
  63. //system('php Console/cake.php Migrations.migration run all');
  64.  
  65. echo "Finished\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement