File: uclean

package info (click to toggle)
svn-buildpackage 0.8.5%2Bnmu1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,308 kB
  • ctags: 98
  • sloc: xml: 2,420; perl: 2,161; sh: 209; makefile: 126
file content (87 lines) | stat: -rwxr-xr-x 2,551 bytes parent folder | download | duplicates (6)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/perl

# cleans and repackages the upstream source

#  Copyright 2004 Eduard Bloch <blade@debian.org>
#
#  This package is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.


use Cwd 'abs_path';
use File::Basename;
use POSIX qw(locale_h);
use Locale::gettext;
use warnings;
use strict;

setlocale(LC_MESSAGES, "");
textdomain("svn-buildpackage");

die _g("
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 _g("Could not create the temp directory!\n");

die _g("Problems creating the temporary directory...") if (!$wd);

system("unp \"$in\" || tar zxvf \"$in\" || tar jcvf \"$in\" || unzip \"$in\"");
if(<*>) {
   chdir <*>;
}
else {
   die sprintf(_g("No file contents? Check %s\n"),$wd);
}
system "make clean distclean";
open(LIST, "find $wd |") or die (sprintf(_g("Failed to run `find %s`: %s"), $wd, $!));
my @files=<LIST>;
close(LIST) or die _g("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 sprintf(_g("Could not rename %s to %s"),$out, $old);
}
system("tar c * | gzip -9 > \"$out\"") && die sprintf(_g("Could not create %s!\n"),$out);
system "rm -rf $wd";

sub _g {
	return gettext(shift);
}