File: Todeb.pm

package info (click to toggle)
alien 6.54
  • links: PTS
  • area: main
  • in suites: potato
  • size: 364 kB
  • ctags: 62
  • sloc: perl: 974; makefile: 117; sh: 8
file content (124 lines) | stat: -rw-r--r-- 3,573 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/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