« blib/lib/auto/share/dist/Alien-Alien/lib/perl5/Alien/Package/Deb.pm
↑ Summary
blib/lib/auto/share/dist/Alien-Alien/lib/perl5/Alien/Package.pm »
| 1 | #!/usr/bin/perl -w | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | Alien::Package::Tgz - an object that represents a tgz package | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =cut | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | package Alien::Package::Tgz; | ||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use base qw(Alien::Package); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Cwd qw(abs_path); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | my $tarext=qr/\.(?:tgz|tar(?:\.(?:gz|Z|z|bz|bz2))?|taz)$/; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | This is an object class that represents a tgz package, as used in Slackware. | ||||||||||||||||||||||||||||
| 19 | It also allows conversion of raw tar files. | ||||||||||||||||||||||||||||
| 20 | It is derived from Alien::Package. | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head1 CLASS DATA | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =over 4 | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =item scripttrans | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | Translation table between canoical script names and the names used in | ||||||||||||||||||||||||||||
| 29 | tgz's. | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =cut | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 1 | ▶ | use constant scripttrans => { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | postinst => 'doinst.sh', | ||||||||||||||||||||||||||||
| 35 | postrm => 'delete.sh', | ||||||||||||||||||||||||||||
| 36 | prerm => 'predelete.sh', | ||||||||||||||||||||||||||||
| 37 | preinst => 'predoinst.sh', | ||||||||||||||||||||||||||||
| 38 | 1 | }; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =back | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =head1 METHODS | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =over 4 | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =item checkfile | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | Detect tgz files by their extension. | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =cut | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub checkfile { | ||||||||||||||||||||||||||
|
Subroutine
checkfile: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 54 | 0 | my $file=shift; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | return $file =~ m/$tarext$/; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =item install | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | Install a tgz with installpkg. Pass in the filename of the tgz to install. | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | installpkg (a slackware program) is used because I'm not sanguine about | ||||||||||||||||||||||||||||
| 64 | just untarring a tgz file. It might trash a system. | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =cut | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub install { | ||||||||||||||||||||||||||
|
Subroutine
install: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 70 | 0 | my $tgz=shift; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if (-x "/sbin/installpkg") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | my $v=$Alien::Package::verbose; | |||||||||||||||||||||||||||
| 74 | 0 | $Alien::Package::verbose=2; | |||||||||||||||||||||||||||
| 75 | 0 | ▶ | $this->do("/sbin/installpkg", "$tgz") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | or die "Unable to install"; | ||||||||||||||||||||||||||||
| 77 | 0 | $Alien::Package::verbose=$v; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | else { | ||||||||||||||||||||||||||||
| 80 | 0 | die "Sorry, I cannot install the generated .tgz file because /sbin/installpkg is not present. You can use tar to install it yourself.\n" | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =item scan | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | Scan a tgz file for fields. Has to scan the filename for most of the | ||||||||||||||||||||||||||||
| 87 | information, since there is little useful metadata in the file itself. | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =cut | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub scan { | ||||||||||||||||||||||||||
|
Subroutine
scan: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 93 | 0 | $this->SUPER::scan(@_); | |||||||||||||||||||||||||||
| 94 | 0 | my $file=$this->filename; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | # Get basename of the filename. | ||||||||||||||||||||||||||||
| 97 | 0 | my ($basename)=('/'.$file)=~m#^/?.*/(.*?)$#; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | # Strip out any tar extensions. | ||||||||||||||||||||||||||||
| 100 | 0 | $basename=~s/$tarext//; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if ($basename=~m/([\w-]+)-([0-9\.?]+).*/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | $this->name($1); | |||||||||||||||||||||||||||
| 104 | 0 | $this->version($2); | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | else { | ||||||||||||||||||||||||||||
| 107 | 0 | $this->name($basename); | |||||||||||||||||||||||||||
| 108 | 0 | $this->version(1); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | $this->arch('all'); | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | $this->summary("Converted tgz package"); | |||||||||||||||||||||||||||
| 114 | 0 | $this->description($this->summary); | |||||||||||||||||||||||||||
| 115 | 0 | $this->copyright('unknown'); | |||||||||||||||||||||||||||
| 116 | 0 | $this->release(1); | |||||||||||||||||||||||||||
| 117 | 0 | $this->distribution("Slackware/tarball"); | |||||||||||||||||||||||||||
| 118 | 0 | $this->group("unknown"); | |||||||||||||||||||||||||||
| 119 | 0 | $this->origformat('tgz'); | |||||||||||||||||||||||||||
| 120 | 0 | $this->changelogtext(''); | |||||||||||||||||||||||||||
| 121 | 0 | $this->binary_info($this->runpipe(0, "ls -l '$file'")); | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | # Now figure out the conffiles. Assume anything in etc/ is a | ||||||||||||||||||||||||||||
| 124 | # conffile. | ||||||||||||||||||||||||||||
| 125 | 0 | my @conffiles; | |||||||||||||||||||||||||||
| 126 | 0 | ▶ | open (FILELIST,"tar vtf $file | grep etc/ |") || | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | die "getting filelist: $!"; | ||||||||||||||||||||||||||||
| 128 | 0 | ▶ | while (<FILELIST>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | # Make sure it's a normal file. This is looking at the | ||||||||||||||||||||||||||||
| 130 | # permissions, and making sure the first character is '-'. | ||||||||||||||||||||||||||||
| 131 | # Ie: -rw-r--r-- | ||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if (m:^-:) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | # Strip it down to the filename. | ||||||||||||||||||||||||||||
| 134 | 0 | m/^(.*) (.*)$/; | |||||||||||||||||||||||||||
| 135 | 0 | push @conffiles, "/$2"; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | 0 | $this->conffiles(\@conffiles); | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | # Now get the whole filelist. We have to add leading /'s to the | ||||||||||||||||||||||||||||
| 141 | # filenames. We have to ignore all files under /install/ | ||||||||||||||||||||||||||||
| 142 | 0 | my @filelist; | |||||||||||||||||||||||||||
| 143 | 0 | ▶ | open (FILELIST, "tar tf $file |") || | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | die "getting filelist: $!"; | ||||||||||||||||||||||||||||
| 145 | 0 | ▶ | while (<FILELIST>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 0 | chomp; | |||||||||||||||||||||||||||
| 147 | 0 | ▶ | unless (m:^install/:) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 0 | push @filelist, "/$_"; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | 0 | $this->filelist(\@filelist); | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | # Now get the scripts. | ||||||||||||||||||||||||||||
| 154 | 0 | foreach my $script (keys %{scripttrans()}) { | |||||||||||||||||||||||||||
| 155 | 0 | $this->$script(scalar $this->runpipe(1, "tar Oxf '$file' install/${scripttrans()}{$script} 2>/dev/null")); | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 0 | return 1; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | =item unpack | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | Unpack tgz. | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =cut | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 0 | ▶ | sub unpack { | ||||||||||||||||||||||||||
|
Subroutine
unpack: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 168 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 169 | 0 | $this->SUPER::unpack(@_); | |||||||||||||||||||||||||||
| 170 | 0 | my $file=abs_path($this->filename); | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | $this->do("cd ".$this->unpacked_tree."; tar xpf $file") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | or die "Unpacking of '$file' failed: $!"; | ||||||||||||||||||||||||||||
| 174 | # Delete the install directory that has slackware info in it. | ||||||||||||||||||||||||||||
| 175 | 0 | $this->do("cd ".$this->unpacked_tree."; rm -rf ./install"); | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | return 1; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | =item prep | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | Adds a populated install directory to the build tree. | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =cut | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 0 | ▶ | sub prep { | ||||||||||||||||||||||||||
|
Subroutine
prep: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 187 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 188 | 0 | ▶ | my $dir=$this->unpacked_tree || die "The package must be unpacked first!"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$this->unpacked_tree || die('The package must be unpacked first!')
MC/DC0%0/1
$this->unpacked_tree || die('The package must be unpacked first!')
$this->unpacked_tree
Truth table0%0/2
A
A= $this->unpacked_tree
| |||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 0 | my $install_made=0; | |||||||||||||||||||||||||||
| 191 | 0 | ▶ | if ($this->usescripts) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | 0 | foreach my $script (keys %{scripttrans()}) { | |||||||||||||||||||||||||||
| 193 | 0 | my $data=$this->$script(); | |||||||||||||||||||||||||||
| 194 | 0 | my $out=$this->unpacked_tree."/install/".${scripttrans()}{$script}; | |||||||||||||||||||||||||||
| 195 | 0 | ▶ | next if ! defined $data || $data =~ m/^\s*$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $data or $data =~ /^\s*$/
MC/DC0%0/2
not defined $data or $data =~ /^\s*$/
not defined $data
$data =~ /^\s*$/
Truth table0%0/3
not(A) or B
A= not defined $dataB= $data =~ /^\s*$/
| |||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if (!$install_made) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | 0 | ▶ | mkdir($this->unpacked_tree."/install", 0755) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | || die "unable to mkdir ".$this->unpacked_tree."/install: $!"; | ||||||||||||||||||||||||||||
| 199 | 0 | $install_made=1; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | 0 | ▶ | open (OUT, ">$out") || die "$out: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | 0 | print OUT $data; | |||||||||||||||||||||||||||
| 203 | 0 | close OUT; | |||||||||||||||||||||||||||
| 204 | 0 | $this->do("chmod", 755, $out); | |||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | =item build | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | Build a tgz. | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | =cut | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 0 | ▶ | sub build { | ||||||||||||||||||||||||||
|
Subroutine
build: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 216 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 217 | 0 | my $tgz=$this->name."-".$this->version.".tgz"; | |||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 0 | ▶ | $this->do("cd ".$this->unpacked_tree."; tar czf ../$tgz .") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | or die "Package build failed"; | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 0 | return $tgz; | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | =back | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | Joey Hess <joey@kitenet.net> | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | =cut | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 1 | 1 | |||||||||||||||||||||||||||