-
Notifications
You must be signed in to change notification settings - Fork 0
/
fink-virtual-pkgs.in
executable file
·218 lines (203 loc) · 6.08 KB
/
fink-virtual-pkgs.in
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#! /usr/bin/perl -w
#
# fink-virtual-pkgs
# Copyright (c) 2001 Christoph Pfisterer
# Copyright (c) 2001-2015 The Fink Package Manager Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA.
#
require 5.008_001; # perl 5.8.1 or newer required
use strict;
use Getopt::Long;
use Fcntl;
my $standalone = 0;
my $basepath = '@BASEPATH@';
my $config;
our $VERSION = 1.28;
UseFinkModules();
Getopt::Long::Configure(qw(bundling ignore_case require_order));
my ($dlist, $hash, $pkgname, @versions, $field, $provides);
my %options =
(
"apt" => 0,
"debug" => 0,
"dpkg" => 0,
);
GetOptions(
'apt|a' => \$options{apt},
'debug' => \$options{debug},
'dpkg|d' => \$options{dpkg},
'help|h' => \&usage,
'version|v' => \&version,
) or die "Unknown option\n";
if ($options{dpkg} and $options{apt}) { die "Can only specify one option dpkg or apt\n" }
if ($options{apt}) {
sysopen(FH,'/tmp/finkaptstatus', O_WRONLY | O_EXCL | O_CREAT) || die "Can not open file /tmp/finkaptstatus for writing: $!\n";
select FH;
}
if ($standalone == 0)
{
$dlist = Fink::VirtPackage->list(%options);
foreach $pkgname (sort keys %$dlist) {
$hash = $dlist->{$pkgname};
if ($options{dpkg}) {
if (@versions = parse_fullversion($hash->{version}) and exists $hash->{status} and $hash->{status} =~ /^\S+\s+ok\s+installed$/i) {
# columns: package, epoch, version, revision
printf "%s\t%lu\t%s\t%s\n",$hash->{package},$versions[0],$versions[1],$versions[2];
# for provides we tell dpkg about them with the version as zero
if (exists $hash->{provides})
{
foreach $provides (split /,/,$hash->{provides})
{
$provides =~ s/\s+//gs;
print "$provides\t0\t0\t0\n";
}
}
}
} else {
# The following code tries very hard to exactly match the output in the dpkg
# status file. This is necessary to make sure that (the new) apt works
# correctly. Thus, be very careful when changing any of this code.
print "Package: ".$hash->{package}."\n";
print "Status: ".$hash->{status}."\n";
print "Priority: optional\n";
print "Architecture: ".$config->param('Debarch')."\n";
print "Version: ".$hash->{version}."\n";
print "Maintainer: ".$hash->{maintainer}."\n";
foreach $field (keys %$hash)
{
next if ($field =~ /^(package|status|version|descdetail|compilescript|homepage|maintainer)$/);
if ($field eq "description") {
print "Description: ".$hash->{'description'}."\n";
if ($hash->{'descdetail'}) {
my $descdetail = $hash->{'descdetail'};
chomp($descdetail);
my @descdetails;
foreach my $line (split("\n", $descdetail)) {
if ($line eq "" || $line =~ /^[\s|\t]+?$/) {
$line = ".";
}
$line = " ".$line;
push @descdetails, $line;
}
$descdetail = join("\n", @descdetails);
print $descdetail."\n";
}
if ($hash->{'homepage'}) {
print " .\n";
print " Web site: ".$hash->{'homepage'}."\n";
}
printf " .\n";
printf " Maintainer: ".$hash->{'maintainer'}."\n";
} else {
printf ucfirst $field.": ".$hash->{$field}."\n";
}
}
print "\n";
}
}
}
else
{
# We are running without fink modules, so just kernel and Mac OS X pkgs
my $macosx_version = 0;
if (-x "/usr/bin/sw_vers") {
open(SW_VERS, "/usr/bin/sw_vers |") or die "Couldn't determine system version: $!\n";
while (<SW_VERS>) {
chomp;
if (/(ProductVersion\:)\s*([^\s]*)/) {
$macosx_version = $2;
last;
}
}
}
if ($options{dpkg})
{
# columns: package, epoch, version, revision
# for provides we tell dpkg about them with the version as zero
printf "%s\t0\t%s\t1\n", lc((uname())[0]), lc((uname())[2]);
print "kernel\t0\t0\t0\n";
if ($macosx_version ne 0) {
printf "macosx\t0\t%s\t1\n",$macosx_version;
}
}
else
{
print "Package: ".lc((uname())[0])."\n";
print "Status: install ok installed\n";
print "Version: ".lc((uname())[2])."-1\n", ;
print "Provides: kernel\n\n";
if ($macosx_version ne 0) {
print "Package: macosx\n";
print "Status: install ok installed\n";
print "Version: ".$macosx_version."-1\n", ;
}
}
}
if ($options{apt}) {
select STDOUT;
close FH;
}
sub version {
print "$0 revision $VERSION\n";
if ($standalone) {
print "\t(running in standalone mode, no Fink/Fink::VirtPackage available)\n";
} else {
print "\tFink version ", Fink::FinkVersion->fink_version(), "\n";
print "\tFink::VirtPackage revision ", $Fink::VirtPackage::VERSION, "\n";
}
exit 0;
}
sub usage {
print <<END;
usage: $0 [--debug] [-a|--apt] [-d|--dpkg] [-h|--help] [-v|--version]
--debug Print debugging info to STDERR
-a/--apt [called by apt, for internal use only]
-d/--dpkg [called by dpkg, for internal use only]
-h/--help This help
-v/--version Print the version
END
exit 0;
}
sub UseFinkModules {
# Be careful about using fink modules
eval {
die unless -d "$basepath/lib/perl5";
require lib;
import lib "$basepath/lib/perl5";
require Fink::FinkVersion;
require Fink::VirtPackage;
require Fink::Services;
import Fink::Services qw(parse_fullversion read_config)
};
$standalone = 1 if $@;
# read the configuration file
if ($standalone != 1)
{
my $configpath = "$basepath/etc/fink.conf";
if (-f $configpath) {
$config = read_config($configpath,
{ Basepath => "$basepath" }
);
} else {
$standalone=1;
}
}
if ($standalone == 1)
{
require POSIX;
import POSIX qw(uname);
}
}