PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/installers/php/profile_release.php

https://github.com/letolabs/DIY
PHP | 92 lines | 63 code | 8 blank | 21 comment | 26 complexity | e6b81466054621a0cf8c246754e94049 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /**
  3. * CASH Music Release Manifest Builder
  4. *
  5. * Creates oes the release profile / manifest for each release. Includes release info as well as
  6. * a file listing with MD5 hashes of each file included. Command line utility. And whatever.
  7. *
  8. * USAGE:
  9. * php installers/php/dev_installer.php
  10. * follow prompts.
  11. *
  12. *
  13. * @package diy.org.cashmusic
  14. * @author CASH Music
  15. * @link http://cashmusic.org/
  16. *
  17. * Copyright (c) 2011, CASH Music
  18. * Licensed under the Affero General Public License version 3.
  19. * See http://www.gnu.org/licenses/agpl-3.0.html
  20. */
  21. function readStdin($prompt, $valid_inputs = false, $default = '') {
  22. // Courtesy of http://us3.php.net/manual/en/features.commandline.io-streams.php#101307
  23. while(!isset($input) || (is_array($valid_inputs) && !in_array(strtolower($input), $valid_inputs))) {
  24. echo $prompt;
  25. $input = strtolower(trim(fgets(STDIN)));
  26. if(empty($input) && !empty($default)) {
  27. $input = $default;
  28. }
  29. }
  30. return $input;
  31. }
  32. // recursive rmdir:
  33. function profile_directory($dir,$trim_from_output,&$add_to) {
  34. if (is_dir($dir)) {
  35. $objects = scandir($dir);
  36. foreach ($objects as $object) {
  37. if ($object != "." && $object != ".." && $object != ".DS_Store") {
  38. if (filetype($dir."/".$object) == "dir") {
  39. profile_directory($dir."/".$object,$trim_from_output,$add_to);
  40. } else {
  41. $add_to .= "\t\t\"".ltrim(str_replace($trim_from_output,'',$dir),'/')."/".$object.'":"'.md5_file($dir."/".$object)."\",\n";
  42. }
  43. }
  44. }
  45. }
  46. }
  47. if(!defined('STDIN')) { // force CLI, the browser is *so* 2007...
  48. echo "Please run installer from the command line. usage:<br / >&gt; php installers/php/dev_installer.php";
  49. } else {
  50. if (count($argv) < 2) {
  51. echo "\nWrong. Usage: php manifest_builder.php <RELEASE FILES DIRECTORY>\n";
  52. } else {
  53. echo "\n\n /)-_-(/\n"
  54. . " (o o)\n"
  55. . " .-----__/\o/\n"
  56. . " / __ /\n"
  57. . " \__/\ / \_\ |/\n"
  58. . " \/\ ||\n"
  59. . " o // ||\n"
  60. . " xxx |\ |\ \n"
  61. . "\n\n"
  62. . " C A S H M U S I C\n"
  63. . " RELEASE PROFILER\n\n";
  64. $version = readStdin('Version number: ');
  65. $release_date = time();
  66. $schema_change = readStdin("\nSchema change for upgrades? (y/n): ", false, 'n');
  67. $script_needed = readStdin("\nScripting needed for upgrades? (y/n): ", false, 'n');
  68. if ($schema_change == 'y') {
  69. $schema_change = 'true';
  70. } else {
  71. $schema_change = 'false';
  72. }
  73. if ($script_needed == 'y') {
  74. $script_needed = 'true';
  75. } else {
  76. $script_needed = 'false';
  77. }
  78. $profile = "{\n\t\"version\":$version,\n\t\"releasedate\":$release_date,\n\t\"schemachange\":$schema_change,\n\t\"scriptneeded\":$script_needed,\n\t\"blobs\":{\n";
  79. profile_directory($argv[1],$argv[1],$profile);
  80. $profile = rtrim($profile,",\n");
  81. $profile .= "\n\t}\n}";
  82. file_put_contents($argv[1].'/release_profile.json', $profile);
  83. }
  84. }