From cd02f8033bdaeafcb5da1be8ba500e1004f95d8c Mon Sep 17 00:00:00 2001 From: joey Date: Fri, 21 Apr 2000 08:53:31 +0000 Subject: [PATCH] Killed files which have been rewritten and moved. --- lib/Fromdeb.pm | 133 ------------------------------------ lib/Fromrpm.pm | 178 ------------------------------------------------- lib/Todeb.pm | 124 ---------------------------------- lib/Torpm.pm | 147 ---------------------------------------- 4 files changed, 582 deletions(-) delete mode 100644 lib/Fromdeb.pm delete mode 100644 lib/Fromrpm.pm delete mode 100644 lib/Todeb.pm delete mode 100644 lib/Torpm.pm diff --git a/lib/Fromdeb.pm b/lib/Fromdeb.pm deleted file mode 100644 index fa85456..0000000 --- a/lib/Fromdeb.pm +++ /dev/null @@ -1,133 +0,0 @@ -#!/usr/bin/perl -# -# Package for converting from a .deb file. - -package From::deb; - -use strict; - -# Global variable initialization. - -# This is set to 1 if dpkg-deb is in the path. -my $dpkg_deb=undef; -my $dir; -foreach $dir (split(/:/,$ENV{PATH})) { - if (-x "$dir/dpkg-deb") { - $dpkg_deb=1; - last; - } -} - -# Query a deb file for fields, and return a hash of the fields found. -# Pass the filename of the deb file to query. -sub GetFields { my ($self,$file)=@_; - my %fields; - - # Extract the control file from the deb file. - my @control; - if ($dpkg_deb) { - @control = `dpkg-deb --info $file control`; - } - else { - # It can have one of two names, depending on the tar - # version the .deb was built from. - @control = `ar p $file control.tar.gz | tar Oxzf - control [./]control`; - } - - # Parse control file and extract fields. - my $i=0; - while ($i<=$#control) { - $_ = $control[$i]; - chomp; - $fields{NAME} = $1 if (/^Package:\s*(.+)/i); - $fields{VERSION} = $1 if (/^Version:\s*(.+)/i); - $fields{ARCH} = $1 if (/^Architecture:\s*(.+)/i); - $fields{MAINTAINER} = $1 if (/^Maintainer:\s*(.+)/i); - $fields{DEPENDS} = $1 if (/^Depends:\s*(.+)/i); - $fields{REQUIRES} = $1 if (/^Requires:\s*(.+)/i); - $fields{GROUP} = $1 if (/^Section:\s*(.+)/i); - if (/^Description:\s*(.+)/i) { - $fields{SUMMARY} = "$1"; - $i++; - while (($i<=$#control) && ($control[$i])) { - $control[$i] =~ s/^ //g; #remove leading space - $control[$i] = "\n" if ($control[$i] eq ".\n"); - $fields{DESCRIPTION}.=$control[$i]; - $i++; - } - $i--; - } - $i++; - } - - $fields{COPYRIGHT}="see /usr/share/doc/$fields{NAME}/copyright"; - $fields{GROUP}="unknown" if (!$fields{GROUP}); - $fields{DISTRIBUTION}="Debian"; - if ($fields{VERSION} =~ /(.+)-(.+)/) { - $fields{VERSION} = $1; - $fields{RELEASE} = $2; - } else { - $fields{RELEASE} = '1'; - } - # Just get rid of epochs for now. - if ($fields{VERSION} =~ /\d+:(.*)/) { - $fields{VERSION} = $1; - } - - # Read in the list of conffiles, if any. - if ($dpkg_deb) { - $fields{CONFFILES}=`dpkg-deb --info $file conffiles 2>/dev/null`; - } - else { - $fields{CONFFILES}= - `ar p $file control.tar.gz | tar Oxzf - conffiles 2>/dev/null`; - } - - # Read in the list of all files. - # Note that tar doesn't supply a leading `/', so we have to add that. - $fields{FILELIST}=undef; - if ($dpkg_deb) { - my $fn; - foreach $fn (`dpkg-deb --fsys-tarfile $file | tar tf -`) { - $fields{FILELIST}.="/$fn"; - } - } - else { - my $fn; - foreach $fn (`ar p $file data.tar.gz | tar tzf -`) { - $fields{FILELIST}.="/$fn"; - } - } - - if ($main::scripts) { - # Read in the scripts, if any. - my $field; - for $field ('postinst', 'postrm', 'preinst', 'prerm') { - if ($dpkg_deb) { - $fields{uc($field)}=`dpkg-deb --info $file $field 2>/dev/null`; - } - else { - $fields{uc($field)}= - `ar p $file control.tar.gz | tar Oxzf - $field 2>/dev/null`; - } - } - } - - $fields{RELEASE}++ unless $main::keep_version; - - return %fields; -} - -# Handles unpacking of debs. -sub Unpack { my ($self,$file,%fields)=@_; - if ($dpkg_deb) { - Alien::SafeSystem ("(cd ..;dpkg-deb -x $file $fields{NAME}-$fields{VERSION})", - "Error unpacking $file\n"); - } - else { - Alien::SafeSystem ("(cd ..;ar p $file data.tar.gz) | tar zxpf -", - "Error unpacking $file\n"); - } -} - -1 diff --git a/lib/Fromrpm.pm b/lib/Fromrpm.pm deleted file mode 100644 index 4bec426..0000000 --- a/lib/Fromrpm.pm +++ /dev/null @@ -1,178 +0,0 @@ -#!/usr/bin/perl -# -# Package for converting from a .rpm file. - -package From::rpm; - -use strict; - -# Query a rpm file for fields, and return a hash of the fields found. -# Pass the filename of the rpm file to query. -sub GetFields { my ($self,$file)=@_; - my %fields; - - # This maps rpm fields (the keys) to the name we want - # for each field (the values). - my %fieldtrans; - - # Get the scripts fields too? - if ($main::scripts) { - %fieldtrans=( - 'PREIN' => 'PREINST', - 'POSTIN' => 'POSTINST', - 'PREUN' => 'PRERM', - 'POSTUN' => 'POSTRM', - ); - } - - # These fields need no translation. - my $field; - foreach $field ('NAME','VERSION','RELEASE','ARCH','CHANGELOGTEXT','SUMMARY', - 'DESCRIPTION', 'COPYRIGHT', 'PREFIXES') { - $fieldtrans{$field}=$field; - } - - # Use --queryformat to pull out all the fields we need. - foreach $field (keys(%fieldtrans)) { - $_=`LANG=C rpm -qp $file --queryformat \%{$field}`; - $fields{$fieldtrans{$field}}=$_ if $_ ne '(none)'; - } - - if ($main::scripts) { - # Fix up the scripts - they are always shell scripts, so make them so. - foreach $field ('PREINST','POSTINST','PRERM','POSTRM') { - $fields{$field}="#!/bin/sh\n$fields{$field}" if $fields{$field}; - } - } - - # Get the conffiles list. - $fields{CONFFILES}=`rpm -qcp $file`; - - # Include the output of rpm -qi in the copyright file. - $fields{COPYRIGHT_EXTRA}=`rpm -qpi $file`; - - # Get the filelist, it's used in the parent directory check in Unpack(). - $fields{FILELIST}=`rpm -qpl $file`; - - # Sanity check fields. - if (!$fields{SUMMARY}) { - # Older rpms will have no summary, but will have a - # description. We'll take the 1st line out of the - # description, and use it for the summary. - ($fields{SUMMARY})=($fields{DESCRIPTION}."\n")=~m/(.*?)\n/m; - - # Fallback. - if (!$fields{SUMMARY}) { - $fields{SUMMARY}="Converted RPM package"; - } - } - if (!$fields{COPYRIGHT}) { - $fields{COPYRIGHT}="unknown"; - } - if (!$fields{DESCRIPTION}) { - $fields{DESCRIPTION}=$fields{SUMMARY}; - } - - # Convert ARCH into string, if it isn't already a string. - if ($fields{ARCH} eq 1) { - $fields{ARCH}='i386'; - } - elsif ($fields{ARCH} eq 2) { - $fields{ARCH}='alpha'; - } - elsif ($fields{ARCH} eq 3) { - $fields{ARCH}='sparc'; - } - elsif ($fields{ARCH} eq 6) { - $fields{ARCH}='m68k'; - } - elsif ($fields{ARCH} eq "noarch") { # noarch = all - $fields{ARCH}='all'; - } - - # Treat 486, 586, etc, as 386. - if ($fields{ARCH}=~m/i\d86/) { - $fields{ARCH}='i386'; - } - - - # Treat ppc as powerpc. - if ($fields{ARCH} eq 'ppc') { - $fields{ARCH} = 'powerpc'; - } - - if ($fields{RELEASE} eq undef || $fields{VERSION} eq undef|| !$fields{NAME}) { - Alien::Error("Error querying rpm file."); - } - - $fields{RELEASE}++ unless $main::keep_version; - $fields{DISTRIBUTION}="Red Hat"; - - return %fields; -} - -# Unpack a rpm file. -sub Unpack { my ($self,$file,%fields)=@_; - Alien::SafeSystem("(cd ..;rpm2cpio $file) | cpio --extract --make-directories --no-absolute-filenames --preserve-modification-time", - "Error unpacking $file\n"); - - # If the package is relocatable. We'd like to move it to be under the - # PREFIXES directory. However, it's possible that that directory is in - # the package - it seems some rpm's are marked as relocatable and - # unpack already in the directory they can relocate to, while some are - # marked relocatable and the directory they can relocate to is removed - # from all filenames in the package. I suppose this is due to some - # vchange between versions of rpm, but none of this is adequatly - # documented, so we'll just muddle through. - # - # Test to see if the package contains the PREFIXES directory already. - print "----$fields{PREFIXES}\n"; - if ($fields{PREFIXES} ne undef && ! -e "./$fields{PREFIXES}") { - print "Moving unpacked files into $fields{PREFIXES}\n"; - - # Get the files to move. - my $filelist=join ' ',glob('*'); - - # Now, make the destination directory. - my $collect=undef; - foreach (split(m:/:,$fields{PREFIXES})) { - if ($_ ne undef) { # this keeps us from using anything but relative paths. - $collect.="$_/"; - mkdir $collect,0755 || Alien::Error("Unable to make directory: $collect: $!"); - } - } - # Now move all files in the package to the directory we made. - Alien::SafeSystem("mv $filelist ./$fields{PREFIXES}", - "Error moving unpacked files into the default prefix directory\n"); - } - - # When cpio extracts the file, any child directories that are present, but - # whose parent directories are not, end up mode 700. This next block corrects - # that to 755, which is more reasonable. - # - # Of course, this whole thing assumes we get the filelist in sorted order. - my $lastdir=undef; - foreach $file (split(/\n/,$fields{FILELIST})) { - $file=~s/^\///; - if (($lastdir && $file=~m:^\Q$lastdir\E/[^/]*$: eq undef) || !$lastdir) { - # We've found one of the nasty directories. Fix it up. - # - # Note that I strip the trailing filename off $file here, for two - # reasons. First, it makes the loop easier, we don't need to fix the - # perms on the last file, after all! Second, it makes the -d test below - # fire, which saves us from trying to fix a parent directory twice. - ($file)=$file=~m:(.*)/.*?:; - my $dircollect=undef; - my $dir; - foreach $dir (split(/\//,$file)) { - $dircollect.="$dir/"; - chmod 0755,$dircollect; # TADA! - } - } - if (-d "./$file") { - $lastdir=$file; - } - } -} - -1 diff --git a/lib/Todeb.pm b/lib/Todeb.pm deleted file mode 100644 index 7b2b7e6..0000000 --- a/lib/Todeb.pm +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/perl -# -# Package for converting to .deb file. - -package To::deb; - -use strict; - -# Mangle the fields to fit debian standards. -sub FixFields { my ($self,%fields)=@_; - # Make sure package name is all lower case. - $fields{NAME}=lc($fields{NAME}); - # Make sure the package name contains no invalid characters. - $fields{NAME} =~ tr/_/-/; - $fields{NAME} =~ s/[^a-z0-9-\.\+]//g; - - # make sure the version contains digets. - if ($fields{VERSION} !~ m/[0-9]/) { - # drat. well, add some. dpkg-deb won't work - # on a version w/o numbers. - $fields{VERSION}.="0"; - } - # same with revision. - if ($fields{RELEASE} !~ m/[0-9]/) { - $fields{RELEASE}.="-1"; - } - - # Fix up the description field to Debian standards (indented at - # least one space, no empty lines.) - my $description=undef; - my $line; - foreach $line (split(/\n/,$fields{DESCRIPTION})) { - $line=~s/\t/ /g; # change tabs to spaces. - $line=~s/\s+$//g; # remove trailing whitespace. - if (!$line) { # empty lines - $line=" ."; - } - else { # normal lines - $line=" $line"; - } - $description.=$line."\n"; - } - chomp $description; - $fields{DESCRIPTION}=$description."\n"; - - return %fields; -} - -# Create debian/* files, either from a patch, or automatically. -sub Convert { my ($self,$workdir,$nopatch,%fields)=@_; - if ($main::generate && !$main::single) { - Alien::SafeSystem("cp -fa $workdir $workdir.orig", "Error creating $workdir.orig"); - } - - # Do the actual conversion here. - mkdir "$fields{NAME}-$fields{VERSION}/debian",0755 - || Alien::Error("Unable to make debian directory"); - my $patchfile=$main::patchfile; - $patchfile=Alien::GetPatch($fields{NAME},$fields{VERSION},$fields{RELEASE}) if !$patchfile; - if ($patchfile && ! $nopatch) { - Alien::Patch($patchfile,$workdir); - } - else { - $self->AutoDebianize($workdir,%fields); - } - chmod 0755,"$workdir/debian/rules"; - - # Make the .orig directory if we were instructed to do so. - if ($main::single) { - print "Directory $workdir prepared.\n"; - } - elsif ($main::generate) { - print "Directories $workdir and $workdir.orig prepared.\n"; - } -} - -# Fill out templates to create debian/* files. -# Pass it the work directory, and the type of package we are debianizing. -sub AutoDebianize { my ($self,$workdir,%fields)=@_; - Alien::Status("Automatic package debianization"); - - # Generate some more fields we need. - $fields{DATE}=Alien::GetDate(); - $fields{EMAIL}=Alien::GetEmail(); - $fields{USERNAME}=Alien::GetUserName(); - - # Fill out all the templates. - my $fn; - foreach $fn (glob("$main::libdir/to-$main::desttype/$main::filetype/*")) { - my $destfn=$fn; - $destfn=~s#^$main::libdir/to-$main::desttype/$main::filetype/##; - Alien::FillOutTemplate($fn,"$main::workdir/debian/$destfn",%fields); - } - - # Autogenerate the scripts without templates, so the scripts - # only exist if they need to. - my $script; - foreach $script ('postinst','postrm','preinst','prerm') { - if ($fields{uc($script)}) { - open (OUT,">$workdir/debian/$script") || - Alien::Error("$workdir/debian/$script: $!"); - print OUT $fields{uc($script)}; - close OUT; - } - } -} - -# Passed the available info about the package in a hash, return the name of -# the debian package that will be made. -sub GetPackageName { my ($self,%fields)=@_; - return "$fields{NAME}_$fields{VERSION}-$fields{RELEASE}_$fields{ARCH}.deb"; -} - -# Build the debian package. -sub Build { my ($self)=@_; - Alien::SafeSystem("debian/rules binary","Package build failed.\n"); -} - -# Install the debian package that is passed. -sub Install { my ($self,$package)=@_; - Alien::SafeSystem("dpkg --no-force-overwrite -i $package"); -} - -1 diff --git a/lib/Torpm.pm b/lib/Torpm.pm deleted file mode 100644 index a3d6325..0000000 --- a/lib/Torpm.pm +++ /dev/null @@ -1,147 +0,0 @@ -#!/usr/bin/perl -# -# Package for converting to .rpm file. - -package To::rpm; - -use strict; - -# Mangle the fields to make rpm happy with them. -sub FixFields { my ($self,%fields)=@_; - # Make sure the version has no dashes in it. - $fields{VERSION} =~ tr/-/_/; - - # Fix up the scripts. Since debian/slackware scripts can be anything, even - # perl programs or binary files, and redhat is limited to only shell scripts, - # we need to encode the files and add a scrap of shell script to make it - # unextract and run on the fly. - my $field; - foreach $field ('POSTINST', 'POSTRM', 'PREINST', 'PRERM') { - if ($fields{$field}) { - # Rpm expands %S, so escape such things. - my $f = pack("u",$fields{$field}); - $f =~ s/%/%%/g; - $fields{$field}= - "set -e\n". - "mkdir /tmp/alien.\$\$\n". - qq{perl -pe '\$_=unpack("u",\$_)' << '__EOF__' > /tmp/alien.\$\$/script\n}. - $f. - "__EOF__\n". - "chmod 755 /tmp/alien.\$\$/script\n". - "/tmp/alien.\$\$/script \"\$@\"\n". - "rm -f /tmp/alien.\$\$/script\n". - "rmdir /tmp/alien.\$\$"; - } - } - - return %fields; -} - -# Generate the spec file. -sub Convert { my ($self,$workdir,$nopatch,%fields)=@_; - Alien::Status("Automatic spec file generation"); - - # Create some more fields we will need. - my $pwd=`pwd`; - chomp $pwd; - $fields{BUILDROOT}="$pwd/$workdir"; # must be absolute filename. - - # Remove directories from the filelist. Place %config in front of files - # that are conffiles. - my @conffiles=split(/\n/,$fields{CONFFILES}); - my $filelist; - my $fn; - foreach $fn (split(/\n/,$fields{FILELIST})) { - if ($fn=~m:/$: eq undef) { # not a directory - if (grep(m:^\Q$fn\E$:,@conffiles)) { # it's a conffile - $filelist.="%config $fn\n"; - } - else { # normal file - # Filename must be quoted so rpm can handle - # spaces. - $filelist.="\"$fn\"\n"; - } - } - else { - # Add directories too. - $filelist.="%dir \"$fn\"\n"; - } - } - $fields{FILELIST}=$filelist; - - Alien::FillOutTemplate("$main::libdir/to-$main::desttype/$main::filetype/spec", - "$workdir/$fields{NAME}-$fields{VERSION}-$fields{RELEASE}.spec",%fields); - - if ($main::generate) { - print "Directory $workdir prepared.\n"; - } -} - -# Passed the available info about the package in a hash, return the name of -# the rpm package that will be made. -sub GetPackageName { my ($self,%fields)=@_; - - # Ask rpm how it's set up. We want to know what architecture it will output, - # and where it will place rpms. - my ($rpmarch, $rpmdir); - foreach (`rpm --showrc`) { - chomp; - if (/^build arch\s+:\s(.*)$/) { - $rpmarch=$1; - } - elsif (/^rpmdir\s+:\s(.*)$/) { - $rpmdir=$1; - } - } - if (!$rpmarch) { - Alien::Error("rpm --showrc failed."); - } - - # Debian's "all" architecture is a special case, and the output rpm - # will be a noarch rpm. - if ($fields{ARCH} eq 'all') { $rpmarch='noarch' } - - if (! $rpmdir) { - # Presumably we're delaing with rpm 3.0 or above, which - # doesn't output rpmdir in any format I'd care to try to parse. - # Instead, rpm is now of a late enough version to notice the - # %define's in the spec file, that will make the file end up in - # the directory we started in. - return "$fields{NAME}-$fields{VERSION}-$fields{RELEASE}.$rpmarch.rpm"; - } - else { - # Old rpm. - return "$rpmdir/$rpmarch/$fields{NAME}-$fields{VERSION}-$fields{RELEASE}.$rpmarch.rpm"; - } -} - -# Build a rpm file. -sub Build { my ($self,%fields)=@_; - # Debian's "all" architecture is a special case where we make noarch rpms. - my $buildarch; - if ($fields{ARCH} eq 'all') { - # Nasty version check in here because rpm gratuitously - # changed this option at version 3.0. - my $lc_all=$ENV{LC_ALL}; - $ENV{LC_ALL}='C'; - my $version=`rpm --version`; - $ENV{LC_ALL}=$lc_all; # important to reset it. - my $minor; - ($version,$minor)=$version=~m/version (\d+).(\d+)/; - if ($version >= 3 || ($version eq 2 && $minor >= 92)) { - $buildarch="--target noarch"; - } - else { - $buildarch="--buildarch noarch" - } - } - Alien::SafeSystem("rpm $buildarch -bb $ENV{RPMBUILDOPT} $fields{NAME}-$fields{VERSION}-$fields{RELEASE}.spec", - "Error putting together the RPM package.\n"); -} - -# Install the passed rpm file. -sub Install { my ($self,$package)=@_; - Alien::SafeSystem("rpm -ivh $ENV{RPMINSTALLOPT} $package"); -} - -1