sync-repos.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. echo "Doing this on Windows can actually BREAK scripts!\n\n";
  36. $fileName = "{$buildDir}/{$target}.tar.gz";
  37. $infoData = json_decode(file_get_contents("{$srcDir}/{$target}/module.info"));
  38. $module = [
  39. 'name' => $target,
  40. 'title' => $infoData->title,
  41. 'version' => $infoData->version,
  42. 'description' => $infoData->description,
  43. 'author' => $infoData->author,
  44. 'size' => filesize($fileName),
  45. 'checksum' => hash_file('sha256', $fileName),
  46. 'num_downloads' => '0',
  47. ];
  48. if (isset($infoData->system)) {
  49. $module['type'] = 'System';
  50. } elseif (isset($infoData->cliOnly)) {
  51. $module['type'] = 'CLI';
  52. } else {
  53. $module['type'] = 'GUI';
  54. }
  55. echo "module info:\n";
  56. var_dump($module);
  57. $moduleData[ $target ] = $module;
  58. }
  59. asort($moduleData);
  60. @unlink("{$buildDir}/modules.json");
  61. file_put_contents("{$buildDir}/modules.json", json_encode($moduleData));
  62. echo "\n\n";
  63. echo "Complete!";