#!/usr/bin/perl -w use strict ; use Getopt::Long ; use File::Basename ; use Slackware::Package 0.02 ; use POSIX ; my $VERSION = '0.3' ; my $currenttime = strftime '%F %R', localtime ; my $use_stdout ; Getopt::Long::Configure('bundling_override') ; GetOptions( 'help|h|?' => sub { pod2usage(1) }, 'version|V' => sub { print "mergepkg v $VERSION\n" and exit(0) }, 'p' => \$use_stdout ) ; die "Usage: mergepkg destination [ package ... ]\n" unless @ARGV ; my $destination = $use_stdout ? $ARGV[0] : shift ; if (!$use_stdout and -e $destination) { unshift @ARGV, $destination ; } die "No packages!\n" unless @ARGV ; my $packagename = basename $destination ; my $output = $use_stdout ? \*STDOUT : $destination ; my $destinationdescription = "Packages merged by mergepkg at $currenttime: " ; my $destinationsize = 0 ; my %filelist ; # The main loop. # Collects the files and size from several packages. foreach my $packagefile (@ARGV) { my $package = Slackware::Package->new_from_file($packagefile) ; $destinationdescription .= ' '.$package->name() ; $destinationsize += $package->uncompressed_size() ; my @morefiles = @{$package->filelistref()} ; foreach my $file (@morefiles) { $filelist{$file} ++ ; } } die "No files!\n" unless %filelist ; # Creates the destination package my $destinationpackage = Slackware::Package->new($packagename, sort keys %filelist) ; $destinationpackage->uncompressed_size($destinationsize) ; $destinationpackage->description($destinationdescription) ; $destinationpackage->to_file($output) ;