1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#!/usr/bin/perl -w
# cleans and repackages the upstream source
# (c) 2004, Eduard Bloch <blade@debian.org>
# License: GPL
use Cwd 'abs_path';
use File::Basename;
use strict;
die "
uclean -- remove suspicious/redundant files from upstream source
tarball, convert bz2 -> gz and/or recompress better
Usage:
uclean FILE
fix the source in tarball FILE, recompress, store in the same file
uclean FILE NEW
fix the source in tarball FILE, recompress, store in a new file
" unless (@ARGV == 1 || @ARGV == 2);
my $in = abs_path($ARGV[0]);
my $out= ($ARGV[1]) ? abs_path($ARGV[1]) : $in ;
chomp(my $wd=`mktemp -d`);
chdir $wd || die "Could not create the temp directory!\n";
die "Problems creating the temporary directory..." if (!$wd);
system("unp \"$in\" || tar zxvf \"$in\" || tar jcvf \"$in\" || unzip \"$in\"");
if(<*>) {
chdir <*>;
}
else {
die "No file contents? Check $wd\n";
}
system "make clean distclean";
open(LIST, "find $wd |") or die ("Failed to run `find $wd`: $!");
my @files=<LIST>;
close(LIST) or die "Problems scanning the package contents!\n";
# run two times to not forget directories
for(@files) {
chomp;
if(/(\.o$)|(\.svn)|(CVS)|(\.cvsignore)|(config\.status)|(config\.log)/ && -e $_) {
if(-d $_) {
print STDOUT "rm"," -rf ",$_,"\n";
system("rm","-rf",$_);
}
else
{
unlink $_;
}
}
}
system "rm -rf $wd/*/debian";
chdir $wd;
if($in eq $out) {
my $old=dirname($out)."/upstream-".basename($out);
rename($out,$old) || die "Could not rename $out to $old";
}
system("tar c * | gzip -9 > \"$out\"") && die "Could not create $out!\n";
system "rm -rf $wd";
|