Hello community, here is the log from the commit of package licenses checked in at Wed Jan 31 02:06:00 CET 2007. -------- --- licenses/licenses.changes 2007-01-16 22:38:51.000000000 +0100 +++ /mounts/work_src_done/NOARCH/licenses/licenses.changes 2007-01-30 23:42:41.894931000 +0100 @@ -1,0 +2,5 @@ +Tue Jan 30 23:41:57 CET 2007 - jw@suse.de + +- collect_licenses.pl can now feed on rpm's directly. + +------------------------------------------------------------------- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ licenses.spec ++++++ --- /var/tmp/diff_new_pack.oH1218/_old 2007-01-31 02:05:50.000000000 +0100 +++ /var/tmp/diff_new_pack.oH1218/_new 2007-01-31 02:05:50.000000000 +0100 @@ -1,5 +1,5 @@ # -# spec file for package licenses (Version 20070116) +# spec file for package licenses (Version 20070130) # # Copyright (c) 2007 SUSE LINUX Products GmbH, Nuernberg, Germany. # This file and all modifications and additions to the pristine @@ -11,7 +11,7 @@ # norootforbuild Name: licenses -Version: 20070116 +Version: 20070130 Release: 1 Url: http://www.novell.com Group: System/Packages @@ -22,6 +22,7 @@ Autoreqprov: on BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildArchitectures: noarch +Requires: perl rpm cpio findutils grep %description Licenses is a collection of license texts found in the packages of a @@ -56,5 +57,7 @@ # %doc /usr/share/doc/licenses/* %changelog -n licenses +* Tue Jan 30 2007 - jw@suse.de +- collect_licenses.pl can now feed on rpm's directly. * Tue Jan 16 2007 - jw@suse.de - initial draft of a licenses collection. ++++++ collect_licenses.pl ++++++ --- licenses/collect_licenses.pl 2007-01-16 22:33:31.000000000 +0100 +++ /mounts/work_src_done/NOARCH/licenses/collect_licenses.pl 2007-01-30 23:40:59.837094000 +0100 @@ -27,27 +27,39 @@ # ##################################################################### # 2007-01-16, jw, V1.0 -- initial draft. +# 2007-01-30, jw, V1.1 -- rpm scanner added. use Data::Dumper; use Digest::MD5; +use Cwd; use strict; $ENV{PATH} = '/bin:/usr/bin'; delete $ENV{ENV}; -my $version = '1.0'; +my $version = '1.1'; my $verbose = 1; my $tarball = 'licenses.tar.gz'; my $dir = 'licenses'; my $logfile = 'licenses/meta/log.txt'; -my $collect = q{find /usr/share -type f | egrep -i '(license|copying|copyright)'}; + +my $blacklist_re = '(/usr/share/doc/licenses/|/usr/share/gnump3d/|\.png$|\.jpg$|\.svg$)'; + +my $collect_cmd_fmt = q{find '%s' -type f | egrep -i '%s'}; +my $collect = q{/usr/share:(license|copying|copyright)}; + +my $cpio = '/usr/bin/cpio --quiet'; +my $rpm = '/bin/rpm'; my $extract = 0; my $pack = 0; my $run_collect = 0; my $add = 0; my $keep_unpacked = 0; +my $rpmdir = undef; +my $tmpdir = $ENV{LICENSES_TMP_DIR} || "/tmp/licenses-$$/%s"; +my $noexec = 0; usage() unless @ARGV; @@ -57,8 +69,9 @@ elsif ($arg =~ m{^-q}) { $verbose = 0; } elsif ($arg =~ m{^--$}) { last; } elsif ($arg =~ m{^-a}) { $add++; } - elsif ($arg =~ m{^-c}) { $run_collect++; $collect = shift if $ARGV[0] } + elsif ($arg =~ m{^-c}) { $run_collect++; $collect = shift if $ARGV[0] and $ARGV[0] !~ m{^-}} elsif ($arg =~ m{^-x}) { $extract++; } + elsif ($arg =~ m{^-r}) { $rpmdir = shift; } elsif ($arg =~ m{^-p}) { $pack++; } elsif ($arg =~ m{^-t}) { $pack++; $extract++; } elsif ($arg =~ m{^-k}) { $keep_unpacked++; } @@ -68,7 +81,7 @@ } $keep_unpacked++ unless $pack; - +my ($prefix_string,$infix_pattern,$collect_cmd) = split_prefix_infix($collect); if ($extract && -f $tarball) { @@ -79,47 +92,38 @@ mkdir_pf($logfile); open L, ">>", $logfile; print L "$0 extract=$extract add=$add run_collect=$run_collect pack=$pack started " . scalar(localtime) . "\n"; +print L "collect=$collect\n" if $run_collect; +print L "rpmdir=$rpmdir\n" if defined $rpmdir; print L "$tarball extracted.\n" if $extract && -f $tarball; -if ($run_collect) +if (defined($rpmdir)) { - print L "running comand: $collect\n"; - open C, "$collect|" or die "'$collect' failed: $! $@\n"; - while (defined (my $line = <C>)) + $rpmdir = $1 if $rpmdir =~ m{^(.*)$}; # untaint. + if (-d $rpmdir) { - chomp $line; - my $file = ($line =~ m{^(.*)$})[0]; # force untaint - - if (open FILE, "<", $file) - { - my $md5 = Digest::MD5->new; - $md5->addfile(*FILE); - close(FILE); - my $digest = $md5->hexdigest; - my $dest = "$dir/md5/$digest"; - unless (-f $dest) - { - mkdir_pf($dest); - system "cp '$file' '$dest'" and die "cannot copy $file"; - print L "added $digest $file\n"; - print "added $file\n" if $verbose; - } - else - { - print L " have $digest $file\n"; - } - } - else + open FINDPKG, "find $rpmdir -name \*.rpm|" or die "open find $rpmdir failed: $! $@\n"; + while (defined(my $pkg = <FINDPKG>)) { - warn "cannot read $file: $!\n"; + $pkg = $1 if $pkg =~ m{(\S+)}; + die "find returned non-file: $pkg\n" unless -f $pkg; + print " $pkg\n" if $verbose; + collect_from_rpm($pkg); } - + close FINDPKG; + } + else + { + collect_from_rpm($rpmdir); } - close C; + } +else + { + collect_licenses('/'); } if ($pack && -d $dir) { + rename $tarball, "$tarball." . time() if -f $tarball; my $cmd = "tar zcvf '$tarball' '$dir'"; system $cmd and die "'$cmd' failed: $! $@\n"; print L "$tarball packed.\n"; @@ -128,7 +132,9 @@ print L "$0 done " . scalar(localtime) . "\n"; close L; rm_rf($dir) unless $keep_unpacked; + exit 0; +############################################################################ ## ## this version of mkdir_pf handles relative and absolute paths. @@ -219,6 +225,75 @@ } +sub rpm_header +{ + my ($file, $name) = @_; + my $cmd = "$rpm -qp --qf '%{$name}' '$file'"; + open RPM, "$cmd|" or die "cannot run $cmd: $!"; + my $r = join '', <RPM>; + close RPM or die "failed to run $cmd: $!"; + die "$cmd: failed\n" unless length $r; + return $r; +} + +sub rpm_filelist +{ + my ($file, $name) = @_; + my $cmd = "$rpm -qpl '$file'"; + open RPM, "$cmd|" or die "cannot run $cmd: $!"; + my @r = <RPM>; + chomp @r; + close RPM or die "failed to run $cmd: $!"; + die "$cmd: failed\n" unless scalar @r; + return @r; +} + + +# extract an RPM file, optionally limited to certain files. +# +sub unrpm +{ + my ($pkg, $dir, $files) = @_; + my $pattern = ''; + if ($files) + { + # we put leading dots in front of the file name list. + # This is how rpm2cpio exports the names. + # And we escape '?' and '*' because cpio reads shell globbing + # patterns, not files. + + $pattern = " '." . join("' '.", @$files) . "'" if $files; + $pattern =~ s{([\*\?])}{\\$1}g; + $pattern = $1 if $pattern =~ m{^(.*)$}; + } + run_cmd("rpm2cpio '$pkg' | (cd $dir && $cpio -uidm$pattern)"); +} + +sub collect_from_rpm +{ + my ($pkg) = @_; + my $name = rpm_header($pkg, 'name'); + $name = $1 if $name =~ m{^([^/]+)$}; # untaint, no slashes please. + my @l = rpm_filelist($pkg); + @l = grep { /$infix_pattern/i } grep { /^\Q$prefix_string\E/ } @l; + return unless scalar @l; + + my $root = sprintf $tmpdir, $name; # where created files go. + mkdir_pf("$root/."); + unrpm($pkg, $root, \@l); + collect_licenses($root, $name); + rm_rf($root); +} + +sub run_cmd +{ + my ($cmd) = @_; + print "\n$cmd\n" if $verbose > 1 or $noexec; + return if $noexec; + system "$cmd" and die "$cmd failed: $@ $!"; +} + + sub usage { my ($msg) = @_; @@ -236,16 +311,115 @@ -v Be more verbose. Default: $verbose -q Be quiet. - + -a Add files. - -c [cmd] Add files listed by cmd. Cmd defaults to - "$collect"'. + -c [prefix:infix] + Add files selected by pattern. + A case sensitive prefix string and a case insensitive + infix regexp-pattern can be specified seperated by a colon. + Defaults to "$collect". + -r rpmdir Add files found in the rpm's in rpmdir. -l logfile Append to logfile. Defaults to $logfile . -t First do -x, last do -p. -x Extract '$tarball' into ./$dir . -p Pack '$tarball' from ./$dir . + +Examples: + +Update from the current system: + $0 -t -c + +Make a fresh start for SLES10-SP1: + $0 -p -c -r /mounts/dist/install/SLP/SLES-10-SP1-Beta2/i386 + +add one file from one rpm: + $0 -t -r foobar.rpm -a /usr/lib/foobar/doc/Readme.txt + }; exit 0; } + +sub split_prefix_infix +{ + my ($colon_sep) = @_; + $colon_sep =~ m{^([^:]+):(.*)$} or + die "split_prefix_infix: pattern seperator colon(:) not found\n"; + my ($pre, $in) = ($1, $2); + $pre =~ s{^/+}{}; + my $cmd = sprintf $collect_cmd_fmt, $pre, $in; + return ("/$pre", $in, $cmd); +} + +sub collect_licenses +{ + my ($root, $pkg_name) = @_; + + if ($run_collect) + { + print L "running comand in $root: $collect_cmd\n"; + my $cwd = getcwd; + chdir($root) or die "collect_licenses: chdir($root) failed: $!"; + open C, "$collect_cmd|" or die "'$collect_cmd' failed: $! $@\n"; + + $cwd = $1 if $cwd =~ m{^(.*)$}; # untaint + chdir($cwd) or warn "collect_licenses: chdir($cwd) failed: $!"; + + while (defined (my $line = <C>)) + { + chomp $line; + my $file = ($line =~ m{^(.*)$})[0]; # force untaint + $file = "/$file" unless $file =~ m{^/}; + next if $file =~ m{$blacklist_re}; + + if (open FILE, "<", "$root$file") + { + my $md5 = Digest::MD5->new; + $md5->addfile(*FILE); + close(FILE); + my $digest = $md5->hexdigest; + my $dest = "$dir/md5/$digest"; + unless (-f $dest) + { + mkdir_pf($dest); + system "cp '$root$file' '$dest'" and die "cannot copy $root$file"; + print L "added $digest $file\n"; + print "added $file\n" if $verbose; + } + else + { + print L " have $digest $file\n"; + } + + if ($pkg_name) + { +# my $lname = ($file =~ m{([^/]+)$})[0]; + my $lname = $file; + $lname =~ s{^/+}{}; + $lname =~ s{/+}{,}g; + + $lname = "$dir/pkg/$pkg_name/$lname"; + unless (-e $lname) + { + my $rel = $dest; + $rel =~ s{^[^/]+/}{../../}; + mkdir_pf($lname); + symlink($rel, $lname); + } + } + } + else + { + warn "cannot read $root$file: $!\n"; + } + + } + close C; + } + else + { + warn "nothing done. try -c ?\n"; + } +} + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Remember to have fun... --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse-commit+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-commit+help@opensuse.org
participants (1)
-
root@Hilbert.suse.de