~vcs-imports/alien/master

« back to all changes in this revision

Viewing changes to Alien/Package/Deb.pm

  • Committer: joey
  • Date: 2000-04-21 06:16:26 UTC
  • Revision ID: git-v1:eae03ee44d34f8f21d5d441f60821c28b9a8130d
The rewrite can convert from rpm to deb -- this is getting exciting!

Show diffs side-by-side

added added

removed removed

Lines of Context:
122
122
        $this->copyright("see /usr/share/doc/".$this->name."/copyright");
123
123
        $this->group("unknown") if ! $this->group;
124
124
        $this->distribution("Debian");
 
125
        $this->origformat("deb");
 
126
        $this->binary_info(scalar `dpkg --info $file`);
125
127
 
126
128
        # Read in the list of conffiles, if any.
127
129
        my @conffiles;
151
153
        # Read in the scripts, if any.
152
154
        foreach my $field (qw{postinst postrm preinst prerm}) {
153
155
                if ($this->have_dpkg_deb) {
154
 
                        $this->$field(`dpkg-deb --info $file $field 2>/dev/null`);
 
156
                        $this->$field(scalar `dpkg-deb --info $file $field 2>/dev/null`);
155
157
                }
156
158
                else {
157
 
                        $this->$field(`ar p $file control.tar.gz | tar Oxzf - $field 2>/dev/null`);
 
159
                        $this->$field(scalar `ar p $file control.tar.gz | tar Oxzf - $field 2>/dev/null`);
158
160
                }
159
161
        }
160
162
 
184
186
        return 1;
185
187
}
186
188
 
 
189
=item prep
 
190
 
 
191
Adds a populated debian directory the unpacked package tree, making it
 
192
ready for building. This can either be done automatically, or via a patch
 
193
file. 
 
194
 
 
195
=cut
 
196
 
 
197
sub prep {
 
198
        my $this=shift;
 
199
        my $dir=$this->unpacked_tree;
 
200
 
 
201
        mkdir "$dir/debian", 0755 ||
 
202
                die "mkdir $dir/debian failed: $!";
 
203
        
 
204
        # Use a patch file to debianize?
 
205
        if (defined $this->patchfile) {
 
206
                # The -f passed to zcat makes it pass uncompressed files
 
207
                # through without error.
 
208
                system("zcat -f ".$this->patchfile." | (cd $dir; patch -p1)") ||
 
209
                        die "patch error: $!";
 
210
                # Look for .rej files.
 
211
                die "patch failed with .rej files; giving up"
 
212
                        if `find $dir -name "*.rej"`;
 
213
                system('find . -name \'*.orig\' -exec rm {} \\;');
 
214
                chmod 0755,"$dir/debian/rules";
 
215
                return;
 
216
        }
 
217
 
 
218
        # Automatic debianization.
 
219
        # Changelog file.
 
220
        open (OUT, ">$dir/debian/changelog") || die "$dir/debian/changelog: $!";
 
221
        print OUT $this->name." (".$this->version."-".$this->release.") experimental; urgency=low\n";
 
222
        print OUT "\n";
 
223
        print OUT "  * Converted from .".$this->origformat." format to .deb\n";
 
224
        print OUT "\n";
 
225
        print OUT " -- ".$this->username." <".$this->email.">  ".$this->date."\n";
 
226
        print OUT "\n";
 
227
        print OUT $this->changelogtext."\n";
 
228
        close OUT;
 
229
 
 
230
        # Control file.
 
231
        open (OUT, ">$dir/debian/control") || die "$dir/debian/control: $!";
 
232
        print OUT "Source: ".$this->name."\n";
 
233
        print OUT "Section: alien\n";
 
234
        print OUT "Priority: extra\n";
 
235
        print OUT "Maintainer: ".$this->username." <".$this->email.">\n";
 
236
        print OUT "\n";
 
237
        print OUT "Package: ".$this->name."\n";
 
238
        print OUT "Architecture: ".$this->arch."\n";
 
239
        print OUT "Depends: \${shlibs:Depends}\n";
 
240
        print OUT "Description: ".$this->summary."\n";
 
241
        print OUT $this->description."\n";
 
242
        print OUT ".\n"
 
243
        print OUT " (Converted from a .".$this->origformat." package by alien.)\n";
 
244
        close OUT;
 
245
 
 
246
        # Copyright file.
 
247
        open (OUT, ">$dir/debian/copyright") || die "$dir/debian/copyright: $!";
 
248
        print OUT "This package was debianized by the alien program by converting\n";
 
249
        print OUT "a binary .".$this->origformat." package on ".$this->date."\n";
 
250
        print OUT "\n";
 
251
        print OUT "Copyright: ".$this->copyright."\n";
 
252
        print OUT "\n";
 
253
        print OUT "Information from the binary package:\n";
 
254
        print OUT $this->binary_info."\n";
 
255
        close OUT;
 
256
 
 
257
        # Conffiles, if any.
 
258
        my @conffiles=@{$this->conffiles};
 
259
        if (@conffiles) {
 
260
                open (OUT, ">$dir/debian/conffiles") || die "$dir/debian/conffiles: $!";
 
261
                print OUT join("\n", @conffiles)."\n";
 
262
                close OUT;
 
263
        }
 
264
 
 
265
        # A minimal rules file.
 
266
        open (OUT, ">$dir/debian/rules") || die "$dir/debian/rules: $!";
 
267
        print OUT <<EOF;
 
268
#!/usr/bin/make -f
 
269
# debian/rules for alien
 
270
 
 
271
# Uncomment this to turn on verbose mode.
 
272
#export DH_VERBOSE=1
 
273
 
 
274
build:
 
275
        dh_testdir
 
276
 
 
277
clean:
 
278
        dh_testdir
 
279
        dh_testroot
 
280
        dh_clean
 
281
 
 
282
binary-indep: build
 
283
 
 
284
binary-arch: build
 
285
        dh_testdir
 
286
        dh_testroot
 
287
        dh_clean -k
 
288
        dh_installdirs
 
289
        cp -a `ls |grep -v debian` debian/tmp
 
290
#
 
291
# If you need to move files around in debian/tmp or do some
 
292
# binary patching ... Insert it here
 
293
#
 
294
        dh_installdocs
 
295
        dh_installchangelogs
 
296
#       dh_strip
 
297
        dh_compress
 
298
#       dh_fixperms
 
299
        dh_suidregister
 
300
        dh_installdeb
 
301
        -dh_shlibdeps
 
302
        dh_gencontrol
 
303
        dh_makeshlibs
 
304
        dh_md5sums
 
305
        dh_builddeb
 
306
 
 
307
binary: binary-indep binary-arch
 
308
.PHONY: build clean binary-indep binary-arch binary
 
309
EOF
 
310
        close OUT;
 
311
        chmod 0755,"$dir/debian/rules";
 
312
 
 
313
        # Save any scripts.
 
314
        foreach my $script (qw{postinst postrm preinst prerm}) {
 
315
                my $data=$this->$script();
 
316
                next unless defined $data;
 
317
                next if $data =~ m/^\s*$/;
 
318
                open (OUT,">$dir/debian/$script") ||
 
319
                        die "$dir/debian/$script: $!";
 
320
                print OUT $data;
 
321
                close OUT;
 
322
        }
 
323
}
 
324
 
187
325
=item package
188
326
 
189
327
Set/get package name. 
302
440
        return $ret;
303
441
}
304
442
 
 
443
=item date
 
444
 
 
445
Returns the date, in rfc822 format.
 
446
 
 
447
=cut
 
448
 
 
449
sub date {
 
450
        my $this=shift;
 
451
 
 
452
        my $date=`822-date`;
 
453
        chomp $date;
 
454
        if (!$date) {
 
455
                die "822-date did not return a valid result. You probably need to install the dpkg-dev debian package";
 
456
        }
 
457
 
 
458
        return $date;
 
459
}
 
460
 
 
461
=item email
 
462
 
 
463
Returns an email address for the current user.
 
464
 
 
465
=cut
 
466
 
 
467
sub email {
 
468
        my $this=shift;
 
469
 
 
470
        return $ENV{EMAIL} if exists $ENV{EMAIL};
 
471
 
 
472
        my $login = getlogin || (getpwuid($<))[0] || $ENV{USER};
 
473
        open (MAILNAME,"</etc/mailname");
 
474
        my $mailname=<MAILNAME>;
 
475
        chomp $mailname;
 
476
        close MAILNAME;
 
477
        if (!$mailname) {
 
478
                $mailname=`hostname -f`;
 
479
                chomp $mailname;
 
480
        }
 
481
        return "$login\@$mailname";
 
482
}
 
483
 
 
484
=item username
 
485
 
 
486
Returns the user name of the real uid.
 
487
 
 
488
=cut
 
489
 
 
490
sub username {
 
491
        my $this=shift;
 
492
 
 
493
        my $username;
 
494
        my $login = getlogin || (getpwuid($<))[0] || $ENV{USER};
 
495
        (undef, undef, undef, undef, undef, undef, $username) = getpwnam($login);
 
496
 
 
497
        # Remove GECOS fields from username.
 
498
        $username=~s/,.*//g;
 
499
 
 
500
        # The ultimate fallback.
 
501
        if (!$username) {
 
502
                $username=$login;
 
503
        }
 
504
}
 
505
 
305
506
=head1 AUTHOR
306
507
 
307
508
Joey Hess <joey@kitenet.net>