generate_filecheck_xml.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/usr/bin/env php
  2. <?php
  3. /* Copyright (C) 2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file build/generate_filecheck_xml.php
  20. * \ingroup dev
  21. * \brief This script create a xml checksum file
  22. */
  23. $sapi_type = php_sapi_name();
  24. $script_file = basename(__FILE__);
  25. $path=dirname(__FILE__).'/';
  26. // Test if batch mode
  27. if (substr($sapi_type, 0, 3) == 'cgi') {
  28. echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
  29. exit;
  30. }
  31. // Main
  32. parse_str($argv[1]);
  33. //$outputfile=dirname(__FILE__).'/../htdocs/install/filelist-'.$release.'.xml';
  34. $outputfile=dirname(__FILE__).'/../htdocs/install/filelist.xml';
  35. $fp = fopen($outputfile,'w');
  36. fputs($fp, '<?xml version="1.0" encoding="UTF-8" ?>'."\n");
  37. fputs($fp, '<checksum_list version="'.$release.'">'."\n");
  38. fputs($fp, '<dolibarr_htdocs_dir>'."\n");
  39. $dir_iterator1 = new RecursiveDirectoryIterator(dirname(__FILE__).'/../htdocs/');
  40. $iterator1 = new RecursiveIteratorIterator($dir_iterator1);
  41. // need to ignore document custom etc
  42. $files = new RegexIterator($iterator1, '#^(?:[A-Z]:)?(?:/(?!(?:custom|documents|conf|install|nltechno))[^/]+)+/[^/]+\.(?:php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$#i');
  43. $dir='';
  44. $needtoclose=0;
  45. foreach ($files as $file) {
  46. $newdir = str_replace(dirname(__FILE__).'/../htdocs', '', dirname($file));
  47. if ($newdir!=$dir) {
  48. if ($needtoclose)
  49. fputs($fp, '</dir>'."\n");
  50. fputs($fp, '<dir name="'.$newdir.'" >'."\n");
  51. $dir = $newdir;
  52. $needtoclose=1;
  53. }
  54. if (filetype($file)=="file") {
  55. fputs($fp, '<md5file name="'.basename($file).'">'.md5_file($file).'</md5file>'."\n");
  56. }
  57. }
  58. fputs($fp, '</dir>'."\n");
  59. fputs($fp, '</dolibarr_htdocs_dir>'."\n");
  60. fputs($fp, '<dolibarr_script_dir version="'.$release.'">'."\n");
  61. $dir_iterator2 = new RecursiveDirectoryIterator(dirname(__FILE__).'/../scripts/');
  62. $iterator2 = new RecursiveIteratorIterator($dir_iterator2);
  63. // need to ignore document custom etc
  64. $files = new RegexIterator($iterator2, '#^(?:[A-Z]:)?(?:/(?!(?:custom|documents|conf|install|nltechno))[^/]+)+/[^/]+\.(?:php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$#i');
  65. $dir='';
  66. $needtoclose=0;
  67. foreach ($files as $file) {
  68. $newdir = str_replace(dirname(__FILE__).'/../scripts', '', dirname($file));
  69. if ($newdir!=$dir) {
  70. if ($needtoclose)
  71. fputs($fp, '</dir>'."\n");
  72. fputs($fp, '<dir name="'.$newdir.'" >'."\n");
  73. $dir = $newdir;
  74. $needtoclose=1;
  75. }
  76. if (filetype($file)=="file") {
  77. fputs($fp, '<md5file name="'.basename($file).'">'.md5_file($file).'</md5file>'."\n");
  78. }
  79. }
  80. fputs($fp, '</dir>'."\n");
  81. fputs($fp, '</dolibarr_script_dir>'."\n");
  82. fputs($fp, '</checksum_list>'."\n");
  83. fclose($fp);
  84. print "File ".$outputfile." generated\n";
  85. exit(0);