sync-repos.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. $moduleData = json_decode(file_get_contents("{$buildDir}/modules.json"), true);
  21. if ($remoteSync) {
  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. } else {
  33. echo "======== Update Package: {$target} ========\n";
  34. echo "Remember compress first! tar czf {$target}.tar.gz {$target} && mv {$target}.tar.gz ../build\n";
  35. $fileName = "{$buildDir}/{$target}.tar.gz";
  36. $infoData = json_decode(file_get_contents("{$srcDir}/{$target}/module.info"));
  37. $module = [
  38. 'name' => $target,
  39. 'title' => $infoData->title,
  40. 'version' => $infoData->version,
  41. 'description' => $infoData->description,
  42. 'author' => $infoData->author,
  43. 'size' => filesize($fileName),
  44. 'checksum' => hash_file('sha256', $fileName),
  45. 'num_downloads' => '0',
  46. ];
  47. if (isset($infoData->system)) {
  48. $module['type'] = 'System';
  49. } elseif (isset($infoData->cliOnly)) {
  50. $module['type'] = 'CLI';
  51. } else {
  52. $module['type'] = 'GUI';
  53. }
  54. echo "module info:\n";
  55. var_dump($module);
  56. $moduleData[ $target ] = $module;
  57. }
  58. asort($moduleData);
  59. @unlink("{$buildDir}/modules.json");
  60. file_put_contents("{$buildDir}/modules.json", json_encode($moduleData));
  61. echo "\n\n";
  62. echo "Complete!";