Tuesday 4 March 2014

Old Scripts (2005) - that probably still work - convert Debian/Ubuntu packages to .tgz Slackware <-> .bz2

Just another of my perl files. As far as I remember I based this work on Alien a package convertor or at least a bit of it.

#!/usr/bin/perl # # #convertpkg - converts Debian packages to .tgz (Slackware) or .bz2 (ISlack), .tgz to .bz2 and .bz2 to .tgz #Copyright (C) 22.10.2005 Iuri Stanchev # #This program 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 2 #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, write to the Free Software #Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. package convertpkg; use strict; use lib '.'; # For debugging, removed by Makefile. use Getopt::Long; # Display usage help. sub usage { print STDERR <<EOF; Description: convertpkg - converts Debian packages to .tgz (Slackware) or .bz2 (ISlack), .tgz to .bz2 and .bz2 to .tgz Usage: convertpkg [options] file [...] Option: Description: file [...] Package file or files to convert. -h, --help Display this help message. Target Package: -b, --to-bz2 Generate a ISlack package. -t, --to-tgz Generate a Slackware tgz package. Examples: Converting ISlack to Slackware package: convertpkg -t example-0.0.0-i386.bz2 Converting Slackware to ISlack package: convertpkg -b example-0.0.0-i386.tgz Converting Debian to Slackware package: convertpkg -t example_0.0.0_i386.deb Converting Debian to ISlack package: convertpkg -b example_0.0.0_i386.deb EOF exit 1; } # Start by processing the parameters. my (%destformats, $new_dest, $new_file, $format, $string1, @pairs, $line1, $line2, $line3, $line4, $line5, $line6, $line7, $line8, $line9, $line10); my $versionbump=1; # Bundling is nice anyway, and it is required or Getopt::Long will confuse # -T and -t. Getopt::Long::Configure("bundling"); GetOptions( "to-bz2|b" => sub { $destformats{bz2}=1 }, "to-tgz|t" => sub { $destformats{tgz}=1 }, "help|h" => \&usage, ) || usage(); # if (! -w '.') { die("Cannot write to current directory. Try moving to /tmp and re-running convertpkg.\n"); } if ($> != 0) { print STDERR "Warning: convertpkg is not running as root!\n"; print STDERR "Warning: Ownerships of files in the generated packages will probably be messed up.\n"; } foreach my $file (@ARGV) { if (! -f $file) { die "File \"$file\" not found.\n"; } # Debian to ? if ($file =~ m/.deb/) { foreach my $format (keys %destformats) { print STDERR "Processing '$file'\n"; $new_file = $file; $new_dest = $file; system ("mkdir debtotgz"); system ("ar p $file data.tar.gz | gunzip > debtotgz/data.tar"); system ("ar p $file control.tar.gz | gunzip > debtotgz/control.tar"); chdir "debtotgz"; system ("tar -xvvf data.tar"); system ("tar -xvvf control.tar"); system ("mkdir install"); system ("mv -f postinst install/"); system ("cat control | grep -A 11 Description: > install/slack-desc"); open(OUTF,"install/slack-desc") or dienice("Can't open survey.out: $!"); @pairs = split(/_/, $file); $line1 = <OUTF>; $line2 = <OUTF>; $line3 = <OUTF>; $line4 = <OUTF>; $line5 = <OUTF>; $line6 = <OUTF>; $line7 = <OUTF>; $line8 = <OUTF>; $line9 = <OUTF>; $line10 = <OUTF>; $line1 = @pairs[0].": ".substr($line1, 13, 30); $line2 = @pairs[0].":".$line2; $line3 = @pairs[0].":".$line3; $line4 = @pairs[0].":".$line4; $line5 = @pairs[0].":".$line5; $line6 = @pairs[0].":".$line6; $line7 = @pairs[0].":".$line7; $line8 = @pairs[0].":".$line8; $line9 = @pairs[0].":".$line9; $line10 = @pairs[0].":".$line10; close(OUTF); open(OUTF,">install/slack-desc") or dienice("Can't open survey.out: $!"); print OUTF "$line1"; print OUTF @pairs[0].": \n"; if ($line2 ne @pairs[0].":") {print OUTF "$line2";} if ($line3 ne @pairs[0].":") {print OUTF "$line3";} if ($line4 ne @pairs[0].":") {print OUTF "$line4";} if ($line5 ne @pairs[0].":") {print OUTF "$line5";} if ($line6 ne @pairs[0].":") {print OUTF "$line6";} if ($line7 ne @pairs[0].":") {print OUTF "$line7";} if ($line8 ne @pairs[0].":") {print OUTF "$line8";} if ($line9 ne @pairs[0].":") {print OUTF "$line9";} if ($line10 ne @pairs[0].":") {print OUTF "$line10";} close(OUTF); system ("rm -f control"); system ("rm -f md5sums"); system ("rm -f mpostrm"); system ("rm -f prerm"); system ("rm -f shlibs"); system ("rm -f control.tar"); system ("rm -f data.tar"); system ("rm -f postrm"); system ("rm -f preinst"); $new_file =~ s/\.deb\b/\.tar/i; system ("tar -cvvf $new_file ."); if ($format eq 'tgz') { $new_dest =~s/\.deb\b/\.tgz/i; system ("gzip $new_file"); chdir ".."; $string1 = $new_dest; $string1 =~ s/_/-/g; system ("mv debtotgz/$new_file.gz $string1"); } elsif ($format eq 'bz2') { $new_dest =~s/\.deb\b/\.bz2/i; system ("bzip2 $new_file"); chdir ".."; $string1 = $new_dest; $string1 =~ s/_/-/g; system ("mv debtotgz/$new_file.bz2 $string1"); } else {die "Unknown type of package - Error 1, $file.\n";} } system ("rm -rf debtotgz"); } #Tgz to Bz2 elsif ($file =~ m/.tgz/) { foreach my $format (keys %destformats) { if ($format eq 'bz2') { print STDERR "Processing '$file'\n"; $new_file = $file; $new_dest = $file; system ("gunzip $file"); $new_file =~ s/\.tgz\b/\.tar/i; $new_dest =~s/\.tgz\b/\.bz2/i; system ("bzip2 $new_file"); system ("mv $new_file.bz2 $new_dest") } else {die "Unknown type of package - Error 2, $file.\n";} } } #Bz2 to Tgz elsif ($file =~ m/.bz2/) { foreach my $format (keys %destformats) { if ($format eq 'tgz') { print STDERR "Processing '$file'\n"; $new_file = $file; $new_dest = $file; system ("bunzip2 $file"); $new_file =~ s/\.bz2\b/\""/i; $new_dest =~s/\.bz2\b/\.tgz/i; system ("gzip $new_file"); system ("mv $new_file.gz $new_dest"); } else {die "Unknown type of package - Error 3, $file.\n";}} } #Oh well ... else { die "Unknown type of package - Error 4, $file.\n"; } }