File: Totgz.pm

package info (click to toggle)
alien 6.03hamm2
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 216 kB
  • ctags: 47
  • sloc: perl: 700; makefile: 111
file content (67 lines) | stat: -rw-r--r-- 1,723 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
#!/usr/bin/perl
#
# Package for converting to .tgz file.

package To::tgz;

use strict;

sub FixFields { my ($self,%fields)=@_;
	# Nothing to do.

	return %fields;
}

sub Convert { my ($self,$workdir,%fields)=@_;
	if ($main::scripts) {
		my $install_made=undef;
		my %scripttrans=(
			'doinst.sh' => 'POSTINST',
			'delete.sh' => 'POSTRM',
			'predelete.sh' => 'PRERM',
			'predoinst.sh' => 'PREINST',
		);
		my $script;
		foreach $script (keys(%scripttrans)) {
			if ($fields{$scripttrans{$script}}) {
				if (!$install_made) {
					Alien::Status("Setting up scripts.");
					mkdir "$fields{NAME}-$fields{VERSION}/install",0755
						|| Alien::Error("Unable to make install directory");
					$install_made=1;
				}
				open (OUT,">$workdir/install/$script") ||
					Alien::Error("$workdir/install/$script: $!");;
				print OUT $fields{$scripttrans{$script}};
				close OUT;
				chmod 0755,"$workdir/install/$script";
			}
		}
	}
}

# Passed the available info about the package in a hash, return the name of
# the tgz package that will be made.
sub GetPackageName { my ($self,%fields)=@_;
	return "$fields{NAME}-$fields{VERSION}-$fields{RELEASE}.tgz";
}

# Build a tgz file.
sub Build { my ($self,%fields)=@_;
	Alien::SafeSystem("tar czf ../".$self->GetPackageName(%fields)." .");
}

# Install the passed tgz file.
sub Install { my ($self,$package)=shift;
	if (-x "/sbin/installpkg") {
		Alien::SafeSystem("/sbin/installpkg $package");
	}
	else {
		print STDERR "Sorry, I cannot install the generated .tgz file,\n";
		print STDERR "\"$package\" because /sbin/installpkg is not\n";
		print STDERR "present. You can use tar to install it yourself.\n";
		exit 1; # otherwise alien will delete the package file on us.
	}
}

1