sync-repos.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. error_reporting(E_ALL);
  3. if (!isset($_SERVER['argv']) && !isset($argv)) {
  4. echo "Please enable the register_argc_argv directive in your php.ini\n";
  5. exit(1);
  6. } elseif (!isset($argv)) {
  7. $argv = $_SERVER['argv'];
  8. }
  9. if (!isset($argv[1])) {
  10. echo "Run with \"php sync-repos.php [TARGET] [REMOTE_SYNC]\"\n";
  11. echo " TARGET -> Module name. For remote sync set this with 'nano' or 'tetra'\n";
  12. echo " REMOTE_SYNC -> Enable sync with original pineapple modules repo\n";
  13. exit(1);
  14. }
  15. echo "\nsync mk6 packages - by DSR!\n\n";
  16. $target = $argv[1];
  17. $remoteSync = (isset($argv[2]) && filter_var($argv[2], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
  18. $buildDir = getcwd() . '/build';
  19. $srcDir = getcwd() . '/src';
  20. // scripts
  21. function processRemoteSync($target, $buildDir) {
  22. $moduleData = json_decode(file_get_contents("https://www.wifipineapple.com/{$target}/modules"), true);
  23. echo "======== Packages (" . count($moduleData) . ") ========\n";
  24. foreach ($moduleData as $key => $value) {
  25. if ($value["type"] !== 'Sys') {
  26. echo " [+] {$key}\n";
  27. $file = file_get_contents("https://www.wifipineapple.com/{$target}/modules/{$key}");
  28. @unlink("{$buildDir}/{$key}.tar.gz");
  29. file_put_contents("{$buildDir}/{$key}.tar.gz", $file);
  30. }
  31. }
  32. return $moduleData;
  33. }
  34. function updateSinglePackage($target, $srcDir, $buildDir) {
  35. echo "======== Update Package: {$target} ========\n";
  36. echo "Remember compress first!: tar czf {$target}.tar.gz {$target} && mv {$target}.tar.gz ../build\n";
  37. echo "Doing this on Windows can actually BREAK scripts!\n\n";
  38. $fileName = "{$buildDir}/{$target}.tar.gz";
  39. $infoData = json_decode(file_get_contents("{$srcDir}/{$target}/module.info"));
  40. $module = [
  41. 'name' => $target,
  42. 'title' => $infoData->title,
  43. 'version' => $infoData->version,
  44. 'description' => $infoData->description,
  45. 'author' => $infoData->author,
  46. 'size' => filesize($fileName),
  47. 'checksum' => hash_file('sha256', $fileName),
  48. 'num_downloads' => '0',
  49. ];
  50. if (isset($infoData->system)) {
  51. $module['type'] = 'System';
  52. } elseif (isset($infoData->cliOnly)) {
  53. $module['type'] = 'CLI';
  54. } else {
  55. $module['type'] = 'GUI';
  56. }
  57. echo "module info:\n";
  58. var_dump($module);
  59. $moduleData[ $target ] = $module;
  60. return $moduleData;
  61. }
  62. function processAllTargets($srcDir, $buildDir) {
  63. $moduleData = [];
  64. $files = scandir($buildDir);
  65. foreach ($files as $fileName) {
  66. if (in_array($fileName, ['.', '..', 'modules.json'])) {
  67. continue;
  68. }
  69. echo " [+] {$fileName}\n";
  70. $target = str_replace('.tar.gz', '', $fileName);
  71. $fileName = "{$buildDir}/{$fileName}";
  72. $infoData = json_decode(file_get_contents("{$srcDir}/{$target}/module.info"));
  73. $module = [
  74. 'name' => $target,
  75. 'title' => $infoData->title,
  76. 'version' => $infoData->version,
  77. 'description' => $infoData->description,
  78. 'author' => $infoData->author,
  79. 'size' => filesize($fileName),
  80. 'checksum' => hash_file('sha256', $fileName),
  81. 'num_downloads' => '0',
  82. ];
  83. if (isset($infoData->system)) {
  84. $module['type'] = 'System';
  85. } elseif (isset($infoData->cliOnly)) {
  86. $module['type'] = 'CLI';
  87. } else {
  88. $module['type'] = 'GUI';
  89. }
  90. $moduleData[ $target ] = $module;
  91. }
  92. return $moduleData;
  93. }
  94. // implement...
  95. if ($target === 'all') {
  96. $moduleData = processAllTargets($srcDir, $buildDir);
  97. } elseif ($remoteSync) {
  98. $moduleData = processRemoteSync($target, $buildDir);
  99. } else {
  100. $moduleData = updateSinglePackage($target, $srcDir, $buildDir);
  101. }
  102. asort($moduleData);
  103. @unlink("{$buildDir}/modules.json");
  104. file_put_contents("{$buildDir}/modules.json", json_encode($moduleData));
  105. echo "\n\n";
  106. echo "Complete!";