diff options
| author | B. Watson <urchlay@slackware.uk> | 2022-07-05 03:07:43 -0400 | 
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2022-07-05 03:07:43 -0400 | 
| commit | fe4080bcbd182c9c8068d4524b205926c31353b6 (patch) | |
| tree | 84840363248a0cd4ed02d4e7b1cee2070cff0853 | |
| parent | 558aa4063051f7a2dbc90a208305d898408038c5 (diff) | |
| download | sbo-maintainer-tools-fe4080bcbd182c9c8068d4524b205926c31353b6.tar.gz | |
sbofixinfo: WIP
| -rwxr-xr-x | sbofixinfo | 85 | 
1 files changed, 51 insertions, 34 deletions
| @@ -1,14 +1,10 @@  #!/usr/bin/perl -w -# reorder the keys in a SBo .info file. -# assumes the file is otherwise valid. +# sbofixinfo - fix common errors in SBo .info files.  # companion piece to sbolint.  $VERSION="0.1"; -# generate man page with: -# pod2man --stderr -r0.1 -s1 -c"SBo Maintainer Tools" sbofixinfo > sbofixinfo.1 -  =pod  =head1 NAME @@ -17,10 +13,15 @@ sbofixinfo - fix common errors in a SlackBuilds.org .info file  =head1 SYNOPSIS -sbofixinfo [-b] infofile [infofile ...] +B<sbofixinfo> I<file-or-dir> [I<file-or-dir> I<...>]  =head1 DESCRIPTION +B<sbofixinfo> attempts to fix common errors in a SlackBuilds.org .info +file. Each argument must be an .info file or a directory containing +an .info file. With no arguments, the .info file in the current +directory is checked. +  B<sbofixinfo> attempts to fix the following errors in SBo .info files:  =over 4 @@ -69,9 +70,7 @@ comprehensive checking.  The file is modified 'in-place', in the same way as the B<-i> option  to B<sed>(1). -=head1 OPTIONS - -B<-b> causes B<sbofixinfo> to keep a backup of the original file with the +B<sbofixinfo> keeps a backup of the original file with the  extension I<.bak> appended to the filename. If the backup file already  exists, it will be silently overwritten. After the new file is generated,  B<diff>(1) (with its B<-u> option) is run on the backup and modified @@ -107,23 +106,36 @@ B<sbolint>(1), B<sbopkglint>(1)  ($SELF = $0) =~ s,.*/,,; -@keyorder = qw/ -PRGNAM VERSION HOMEPAGE DOWNLOAD MD5SUM DOWNLOAD_x86_64 MD5SUM_x86_64 REQUIRES MAINTAINER EMAIL -/; - -die "$SELF v$VERSION\nUsage: $SELF [--help] [-b] infofile <infofile ...>\n" unless @ARGV; - -if($ARGV[0] eq '--help') { -	no warnings; -	require FindBin; -	system("perldoc $FindBin::RealScript"); -	exit 0; +@keyorder = qw{ +	PRGNAM +	VERSION +	HOMEPAGE +	DOWNLOAD +	MD5SUM +	DOWNLOAD_x86_64 +	MD5SUM_x86_64 +	REQUIRES +	MAINTAINER +	EMAIL +}; + +$arg0 = @ARGV ? $ARGV[0] : undef; +for($arg0) { +	defined || last; +	/^--?(?:v|ver)$/ && do { +		print "$SELF $VERSION\n"; +		exit 0; +	}; +	/^--?(?:h|help|doc)$/ && do { +		exec("perldoc $0") || die "$SELF: can't exec perldoc\n"; +	}; +	/^--?(?:m|man)$/ && do { +		exec("pod2man --stderr -s1 -csbo-maintainer-tools -r$VERSION $0") || +			die "$SELF: can't exec pod2man\n"; +	};  } -if($ARGV[0] eq '-b') { -	$backup = 1; -	shift; -} +push @ARGV, "." unless @ARGV;  $errcnt = 0;  fix_info($_) for @ARGV; @@ -131,6 +143,12 @@ exit $errcnt;  sub fix_info {  	my $file = shift; +	if(-d $file) { +		my $dir = `realpath $file`; +		chomp $dir; +		(my $name = $dir) =~ s,.*/,,; +		$file = "$dir/$name.info"; +	}  	open my $fh, "<$file" or do {  		warn "$SELF: can't read $file: $!\n";  		$errcnt++; @@ -150,7 +168,7 @@ sub fix_info {  		next if /^\s*$/; # ignore blank lines entirely  		s/(?:^\s+|\s+$)//g; # remove leading/trailing spaces -		s/^(\w+)\s+=\s+/$1=/; # remove spaces around = +		s/^(\w+)\s*=\s*/$1=/; # remove spaces around =  		if(/^(\w+)=(.*)$/) {  			$key = $1; @@ -158,9 +176,9 @@ sub fix_info {  			$val =~ s,(?:^['"]|['"]$),,g; # remove quotes around value  			$val =~ s,[\s\\]*$,,; # remove any line-continuation backslash -         # multiple valued keys all on the same line get split up into -         # multi-line values. This only applies to download and md5sum -			# URLs (which can't contain spaces anyway). +			# multiple valued keys all on the same line get split up into +			# multi-line values. This only applies to download and md5sum +			# values (which can't contain spaces anyway).  			if($key =~ /^(?:DOWNLOAD|MD5SUM)/) {  				$val =~ s/\s+/\r/g;  			} @@ -173,7 +191,7 @@ sub fix_info {  	}  	close $fh; -	system("mv $file $file.bak") if $backup; +	system("mv $file $file.bak");  	open $fh, ">$file" or do {  		warn "$SELF: can't write $file: $!\n"; @@ -200,10 +218,9 @@ sub fix_info {  		}  	} -	if($backup) { -		my $result = system("diff $file.bak $file"); -		if($result == 0) { -			system("rm $file.bak"); -		} +	my $result = system("diff $file.bak $file"); +	if($result == 0) { +		system("rm $file.bak"); +		warn "$SELF: no changes to $file\n";  	}  } | 
