/contrib/conf_merge/tc-conf-merger.pl

http://github.com/SingularityCore/Singularity · Perl · 43 lines · 30 code · 8 blank · 5 comment · 4 complexity · 1f23c29ab15b75419465ee36d8f56acf MD5 · raw file

  1. #!/usr/bin/perl -w
  2. # Copyright (C) 2008-2011 TrinityCore <http://www.trinitycore.org/>
  3. # Author: leak
  4. # Date: 2010-12-06
  5. # Note: Based on conf file format of rev 10507
  6. use strict;
  7. if (@ARGV != 3)
  8. {
  9. print("Usage:\ntc-conf-merger.pl <path to new .conf.dist> <path to old .conf> <path to output .conf>\n");
  10. exit(1);
  11. }
  12. if (! -e $ARGV[0])
  13. {
  14. print("No file found at: ".$ARGV[0]);
  15. exit(1);
  16. }
  17. elsif (! -e $ARGV[1])
  18. {
  19. print("No file found at: ".$ARGV[1]);
  20. exit(1);
  21. }
  22. open CONFDIST, "<", $ARGV[0] or die "Error: Could not open ".$ARGV[0]."\n";
  23. my $confdist = join "", <CONFDIST>;
  24. close CONFDIST;
  25. open CONFOLD, "<", $ARGV[1] or die "Error: Could not open ".$ARGV[1]."\n";
  26. my $confold = join "", <CONFOLD>;
  27. close CONFOLD;
  28. while ($confold =~ m/^(?!#)(.*?)\s+?=\s+?(.*?)$/mg) {
  29. my $key = $1, my $value = $2;
  30. $confdist =~ s/^(\Q$key\E)(\s+?=\s+?)(.*)/$1$2$value/mg;
  31. }
  32. open OUTPUT, ">", $ARGV[2] or die "Error: Could not open ".$ARGV[2]."\n";
  33. binmode(OUTPUT);
  34. print OUTPUT $confdist;
  35. close OUTPUT;