editspec 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/usr/bin/perl
  2. ##
  3. ## 00DEV/editspec -- Edit .spec files in OpenPKG CVS repository
  4. ## Copyright (c) 2000-2001 Cable & Wireless Deutschland GmbH
  5. ## Copyright (c) 2000-2001 Ralf S. Engelschall <rse@engelschall.com>
  6. ##
  7. ## Permission to use, copy, modify, and distribute this software for
  8. ## any purpose with or without fee is hereby granted, provided that
  9. ## the above copyright notice and this permission notice appear in all
  10. ## copies.
  11. ##
  12. ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  13. ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  14. ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  15. ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
  16. ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  17. ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  18. ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  19. ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  20. ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  21. ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  22. ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  23. ## SUCH DAMAGE.
  24. ##
  25. if ($#ARGV == -1) {
  26. print STDERR "Usage: $0 <cmd> [<cmd> ...] [-- <pkg> [<pkg> ...]]\n";
  27. exit(1);
  28. }
  29. my @cmd = ();
  30. my @pkg = ();
  31. my $iscmd = 1;
  32. foreach my $arg (@ARGV) {
  33. if ($iscmd and $arg eq '--') {
  34. $iscmd = 0;
  35. next;
  36. }
  37. if ($iscmd) {
  38. push(@cmd, $arg);
  39. }
  40. else {
  41. push(@pkg, $arg);
  42. }
  43. }
  44. if ($#pkg == -1) {
  45. foreach my $pkg (glob("*")) {
  46. next if (not -d $pkg or not -f "$pkg/$pkg.spec");
  47. push(@pkg, $pkg);
  48. }
  49. }
  50. my $all = 0;
  51. foreach my $p (@pkg) {
  52. print "Package $p:\n";
  53. next if (not -d $p or not -f "$p/$p.spec");
  54. open(SPEC, "<$p/$p.spec") || die;
  55. my $spec = '';
  56. $spec .= $_ while (<SPEC>);
  57. close(SPEC);
  58. $_ = $spec;
  59. foreach $cmd (@cmd) {
  60. eval $cmd;
  61. }
  62. if ($spec ne $_) {
  63. $spec = $_;
  64. open(SPEC, ">$p/$p.spec.new") || die;
  65. print SPEC $spec;
  66. close(SPEC);
  67. system("diff -u1 $p/$p.spec $p/$p.spec.new");
  68. my $ok;
  69. if ($all) {
  70. $ok = "yes";
  71. }
  72. else {
  73. print "Edit [a(ll)/Y(es)/n(o)]: ";
  74. $ok = <STDIN>;
  75. }
  76. if ($ok =~ m/^(?:A|a)(?:ll)?\n?$/s) {
  77. $ok = "yes";
  78. $all = 1;
  79. }
  80. if ($ok =~ m/^(?:Y|y)(?:es)?\n?$/s or $ok eq '') {
  81. $spec =~ s|(\nRelease:\s+)(\d+)|$1 . sprintf("%d", $2+1)|se;
  82. print "Ok: Edited $p/$p.spec\n";
  83. open(SPEC, ">$p/$p.spec") || die;
  84. print SPEC $spec;
  85. close(SPEC);
  86. }
  87. unlink("$p/$p.spec.new");
  88. }
  89. }