File: Fromtgz.pm

package info (click to toggle)
alien 6.18
  • links: PTS
  • area: main
  • in suites: slink
  • size: 256 kB
  • ctags: 61
  • sloc: perl: 923; makefile: 118
file content (96 lines) | stat: -rw-r--r-- 2,367 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
#!/usr/bin/perl
#
# Package for converting from a tgz file.

package From::tgz;

use strict;

# Query a tgz file for fields, and return a hash of the fields found.
# Pass the filename of the tgz file to query.
sub GetFields { my ($self,$file)=@_;
	my %fields;

	# Get basename of the filename.
	my ($basename)=('/'.$file)=~m#^/?.*/(.*?)$#;

	# Strip out any tar extentions.
	$basename=~s/\.(tgz|tar\.gz)$//;

	if ($basename=~m/(.*)-(.*)/ ne undef) {
		$fields{NAME}=$1;
		$fields{VERSION}=$2;
	}
	else {
		$fields{NAME}=$basename;
		$fields{VERSION}=1;
	}

	$fields{ARCH}='all';
	if ($main::tgzdescription eq undef) {
		$fields{SUMMARY}='Converted Slackware tgz package';
	}
	else {
		$fields{SUMMARY}=$main::tgzdescription;
	}
	$fields{DESCRIPTION}=$fields{SUMMARY};
	$fields{COPYRIGHT}="unknown";
	$fields{RELEASE}=1;
	$fields{DISTRIBUTION}="Slackware";

	# Now figure out the conffiles. Assume anything in etc/ is a conffile.
	# It's a little nasty to do it here, but it's much cleaner than waiting 
	# until the tar file is unpacked and then doing it.
	$fields{CONFFILES}='';
	open (FILELIST,"tar zvtf $file | grep etc/ |") 
		|| Alien::Error("Getting filelist: $!");
	while (<FILELIST>) {
		# Make sure it's a normal file. This is looking at the
		# permissions, and making sure the first character is '-'.
		# Ie: -rw-r--r--
		if (m:^-:) {
			# Strip it down to the filename.
			m/^(.*) (.*)$/;
			$fields{CONFFILES}.="/$2\n";
		}
	}
	close FILELIST;

	# Now get the whole filelist. We have to add leading /'s to the 
	# filenames. We have to ignore all files under /install/
	$fields{FILELIST}='';
	open (FILELIST, "tar ztf $file |");
	while (<FILELIST>) {
		if ($_=~m:^install/: eq undef) {
			$fields{FILELIST}.="/$_";
		}
	}
	close FILELIST;

	# Now get the scripts.
	if ($main::scripts) {
		my %scripttrans=(
			'doinst.sh' => 'POSTINST',
			'delete.sh' => 'POSTRM',
			'predelete.sh' => 'PRERM',
			'predoinst.sh' => 'PREINST',
		);
		my $script;
		foreach $script (keys(%scripttrans)) {
			$fields{$scripttrans{$script}}=
				`tar Oxzf $file install/$script 2>/dev/null`;
		}
	}

	return %fields;
}

# Handles unpacking of tgz's.
sub Unpack { my ($self,$file)=@_;
	Alien::SafeSystem ("(cd ..;cat $file) | tar zxpf -","Error unpacking $file\n");

	# Delete this install directory that has slackware info in it.
	Alien::SafeSystem ("rm -rf install");
}

1