uprev-spec revision 709
10139N/A#!/usr/bin/perl -w
10139N/A#
10139N/A# uprev-spec - increments by 1 the value of the Release field in spec files
10139N/A#
10139N/A# Dermot McCluskey 22-July-2003 Initial Version
10139N/A
10139N/A
17185N/Ause strict;
10139N/Ause warnings;
17177N/Ause Getopt::Long qw(:config gnu_getopt no_auto_abbrev);
17177N/A
17177N/Amy $exit_val = 0;
10139N/Amy $verbose = 1;
10139N/Amy $build = "";
10139N/Amy @spec_files = ();
10139N/A
10139N/A
10139N/A&main ();
18615N/Aexit $exit_val;
10139N/A
20872N/A
10139N/A
10139N/Asub print_msg ($)
10139N/A{
10139N/A ($verbose) && print shift;
10139N/A}
10139N/A
10139N/A
10139N/Asub set_quiet
10139N/A{
10139N/A $verbose = 0;
10139N/A}
10139N/A
10139N/A
10139N/Asub process_args ($)
10139N/A{
10139N/A push @spec_files, shift;
10139N/A}
10139N/A
10139N/A
10139N/Asub process_options
10139N/A{
10139N/A Getopt::Long::Configure ("bundling");
10139N/A
10139N/A GetOptions ('q|quiet' => \&set_quiet,
10139N/A 'h|help' => \&usage,
10139N/A 'build=n' => \$build,
10139N/A '<>' => \&process_args);
10139N/A}
10139N/A
10139N/A
10139N/Asub usage (;$)
10139N/A{
10139N/A print << "EOF";
10139N/A
10139N/Auprev-spec - increments by 1 the value of the Release field in spec files
10139N/A
10139N/AUsage: uprev-spec [options] specs...
10139N/A
10139N/Aoptions:
10139N/A -q|--quiet: Silent operation.
10139N/A -h|--help: Print this help message.
10139N/A --build=n: If specified, Release will be incremented to at least n
10139N/A
10139N/Aspecs...
10139N/A path(s) to spec file(s)
10139N/AEOF
10139N/A
10139N/A exit 0;
10139N/A}
10139N/A
10139N/A
10139N/Asub up_rev ($)
10139N/A{
10139N/A my $spec_file = shift;
10139N/A my $spec_file_base = $spec_file;
10139N/A my $temp_file;
10139N/A my $found = 0;
10139N/A my $out;
10139N/A
10139N/A # if spec_file contains a leading dir, then split it out
10139N/A if ($spec_file =~ /.+\/(.+)/) {
10139N/A $spec_file_base = $1;
10139N/A }
10139N/A
$temp_file = "/tmp/$spec_file_base.tmp";
&print_msg (sprintf ("%-31s ", $spec_file_base));
if (! -e $spec_file) {
&print_msg ("ERROR: no such spec file: $spec_file\n");
return 0;
}
if (! -w $spec_file) {
&print_msg ("ERROR: unable to write to spec file: $spec_file\n");
return 0;
}
if (-e $temp_file) {
if (unlink ($temp_file) != 1) {
&print_msg ("ERROR: Cannot delete old temp file $temp_file: $!\n");
return 0;
}
}
if (! open (SPECFILE, $spec_file)) {
&print_msg ("ERROR: Cannot read $spec_file: $!\n");
return 0;
}
if (! open (TEMPFILE, ">$temp_file")) {
&print_msg ("ERROR: Cannot create $temp_file: $!\n");
return 0;
}
while (<SPECFILE>) {
/^(release\s*:\s*)(\S*)(\s*)$/i && do {
my $label = $1;
my $rel = $2;
my $tail = $3;
my $lead = "";
my $newrel;
$found = 1;
# if Release value does not consist entirely of digits,
# then check for leading chars ending with digits
if ($rel !~ /^\d+$/) {
if ($rel =~ /^(.*\D+)(\d+)$/) {
$lead = $1;
$rel = $2;
} else {
&print_msg ("ERROR: non-numeric Release: $rel\n");
close (SPECFILE);
close (TEMPFILE);
return 0;
}
}
&print_msg (sprintf ("%7s ", "$lead$rel"));
$newrel = $rel + 1;
if (length ($build) && ($newrel < $build)) {
$newrel = $build;
}
&print_msg (sprintf ("%7s ", "$lead$newrel"));
print TEMPFILE "$label$lead$newrel$tail";
next;
};
# print all other lines unmodified
print TEMPFILE $_;
}
close (TEMPFILE);
close (SPECFILE);
if (! $found) {
&print_msg ("ERROR: no Release value in spec file\n");
return 0;
}
$out = `cp $temp_file $spec_file`;
if ($?) {
&print_msg ("ERROR: \"cp $temp_file $spec_file\": $out");
return 0;
}
unlink ($temp_file);
&print_msg ("OK\n");
return 1;
}
sub main
{
&process_options ();
if (! @spec_files) {
&print_msg ("Nothing to do.\n");
return;
}
&print_msg ("Spec file Release New Rel Status\n");
&print_msg ("=============================== ======= ======= =======\n");
foreach (@spec_files) {
&up_rev ($_) || $exit_val++;
}
}