-
Notifications
You must be signed in to change notification settings - Fork 0
/
postinstall.pl.in
executable file
·347 lines (292 loc) · 11.5 KB
/
postinstall.pl.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#!/usr/bin/perl -w
# -*- mode: Perl; tab-width: 4; -*-
#
# postinstall.pl - perl script to check and store which OS version we
# are running, and to setup the dists directory
#
# Fink - a package manager that downloads source and installs it
# Copyright (c) 2001 Christoph Pfisterer
# Copyright (c) 2001-2019 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.
#
$| = 1;
use 5.008_001; # perl 5.8.1 or newer required
use strict;
use lib "@PREFIX@/lib/perl5";
use Fink::Bootstrap qw(&check_host &add_injected_to_trees &get_selfupdatetrees);
use Fink::Services qw(&read_config &execute &apt_available);
use Fink::CLI qw(&print_breaking &prompt_boolean);
use Fink::Config qw($config);
use Fink::Configure qw($conf_file_compat_version &spotlight_warning);
use File::Find;
use File::Basename;
my $arch = shift;
my ($basepath);
$basepath = "@PREFIX@";
# read the configuration file
my $config;
my $configpath = "@PREFIX@/etc/fink.conf";
my $configNeedsUpdate = 0;
if (-f $configpath) {
$config = &Fink::Services::read_config($configpath,
{ Basepath => '@PREFIX@' }
);
} else {
print "ERROR: Configuration file \"$configpath\" not found.\n";
exit 1;
}
### check if we need to rerun configure since the fink.conf file
### compatibility version has changed.
my $expectedConfFileCompatVersion = $Fink::Configure::conf_file_compat_version;
my $actualConfFileCompatVersion = $config->param_default("ConfFileCompatVersion", "0");
if ($expectedConfFileCompatVersion > $actualConfFileCompatVersion) {
$configNeedsUpdate = 1;
}
elsif ($expectedConfFileCompatVersion < $actualConfFileCompatVersion) {
&print_breaking("\nWARNING: Your fink configuration file \"$configpath\" " .
"was created from a fink version newer than this one! Try to run " .
"'fink configure' or reinstall the latest fink to correct this.\n\n");
}
### check if we like this system
print "Checking system...";
my ($host);
my ($distribution);
$host = `$basepath/lib/fink/update/config.guess`;
chomp($host);
if ($host =~ /^\s*$/) {
print " ERROR: Can't determine host type.\n";
exit 1;
}
print " $host\n";
$distribution = check_host($host,0,$arch);
if ($distribution eq "unknown") {
exit(1);
}
### save $distribution in the config file, after reading old value
my $distold = $config->param("Distribution");
$config->set_param("Distribution", $distribution);
$config->save();
### are we updating?
my $updating = 0;
if ( not ($distold eq $distribution)) {
add_injected_to_trees($distribution);
$updating = 1;
### FIXME: this variable is a hook to action in Fink::SelfUpdate::finish,
### but that action has not yet been implemented. (The variable should
### be zeroed out in SelfUpdate.pm after the action has been taken.)
$config->set_param("UpdateFrom", $distold);
### add packages depending on which Update
if (($distold eq "10.4") and (($distribution eq "10.5") or ($distribution eq "10.6"))) {
$config->set_param("UpdatePackages", "perl586-core, rman");
}
$config->save();
}
### Find the user who owns dists
my ($username, @sb, $distdir);
$distdir = "$basepath/fink/dists" ;
$username = "root" ;
if (-d "$distdir/CVS") {
@sb = stat("$distdir/CVS");
if ($sb[4] != 0 and $> != $sb[4]) {
($username) = getpwuid($sb[4]);
}
}
### Error out when running on an unsupported old systems.
if (($distribution eq "10.1") or
($distribution eq "10.2") or
($distribution eq "10.3") or
($distribution eq "10.4-transitional")) {
print "ERROR: The current version of fink cannot be used with the $distribution distribution.\nPlease use an appropriate earlier version of fink.\n";
exit 1;
}
my $distroot = get_selfupdatetrees($distribution);
my $selfupdatetree = $distroot;
# At some time in the past, 10.4 may have been a symlink to 10.4-transitional;
# we want to undo that.
### FIXME: of course, we are not checking on other bad conditions which may
### exist if this symlink is still pointing to 10.4-transitional
if (-l "$basepath/fink/10.4") {
unlink "$basepath/fink/10.4";
}
# If $distroot is different from $distribution, we need a symlink between them.
my $notlink;
if (not ($distribution eq $distroot)) {
$notlink = "1";
### we want $basepath/fink/$distribution to be a symlink, but if it already exists
### and is *not* a symlink (or not the correct symlink), we move it out of
### the way first
if (-l "$basepath/fink/$distribution") {
if (readlink("$basepath/fink/$distribution") eq "$distroot") {
$notlink = "0";
}
}
if (-e "$basepath/fink/$distribution") {
if (-e "$basepath/fink/$distribution.old") {
my $aanswer = &prompt_boolean("\nWARNING: you have an obsolete file or directory $basepath/fink/$distribution.old which must be removed before the installation can continue; do you want to remove it now?\n", default => 1, timeout => 60);
if ($aanswer) {
if (&execute("/bin/rm -rf $basepath/fink/$distribution.old")) {
print "ERROR: Cannot remove $basepath/fink/$distribution.old\n";
exit 1;
}
} else {
print "\nOK: please run 'fink reinstall fink' when you are ready to have this file or directory deleted.\n\n";
exit 1;
}
}
if ($notlink) {
if (&execute("/bin/mv $basepath/fink/$distribution $basepath/fink/$distribution.old")) {
print "ERROR: Can't move $basepath/fink/$distribution to $basepath/fink/$distribution.old\n";
exit 1;
}
print "\nWARNING: An unexpected file or directory $basepath/fink/$distribution was found,\nand was moved to $basepath/fink/$distribution.old . It will be deleted the next time\nfink is updated, unless you have deleted it yourself before then.\n\n";
}
}
if ($notlink) {
if (&execute("ln -s $distroot $basepath/fink/$distribution")) {
print "ERROR: Can't create link from $distroot to $basepath/fink/$distribution\n";
exit 1;
}
}
}
if (not -d $basepath."/fink/".$distroot) {
if(&execute("/bin/mkdir -p $basepath/fink/$distroot/local/main/finkinfo")) {
print "ERROR: couldn't create directory $basepath/fink/$distroot/local/main/finkinfo\n";
exit 1;
}
if (&execute("/usr/sbin/chown -R $username $basepath/fink/$distroot")) {
print "ERROR: couldn't change ownership of $basepath/fink/$distroot to $username\n";
exit 1;
}
}
unlink $distdir;
if (&execute("ln -s $distribution $distdir")) {
print "ERROR: Can't create link from $distribution to $distdir\n";
exit 1;
}
# If SelfUpdateTrees is not defined, or just has a single entry, we update
# the entry to $selfupdatetree. Otherwise, we append $selfupdatetree
# to the entry (unless it is already present).
my @alltrees = ();
my $SUTrees = "";
if (defined $config->param("SelfUpdateTrees")) {
$SUTrees = $config->param("SelfUpdateTrees") ;
@alltrees = split(/\s+/, $SUTrees);
}
if (scalar @alltrees eq "1") {
$SUTrees = "";
@alltrees=();
}
for my $tree (@alltrees) {
$selfupdatetree = "" if ($tree eq $selfupdatetree);
}
my $SUTreesEntry = $SUTrees . " " . $selfupdatetree;
$SUTreesEntry =~ s/(^\s+|\s+$)//g;
$config->set_param("SelfUpdateTrees", $SUTreesEntry);
$config->save();
# Now that we've symlinked to the new directory, we can copy over the
# update packages if we are updating.
if ($updating) {
if(&execute("/bin/mkdir -p $basepath/fink/dists/local/injected/finkinfo/update-packages")) {
print "ERROR: couldn't create directory $basepath/fink/dists/local/injected/finkinfo/update-packages\n";
exit 1;
}
# just in case we need to overwrite something, use cp -f
if (&execute("cp -f $basepath/lib/fink/update-packages/* $basepath/fink/dists/local/injected/finkinfo/update-packages")) {
print "ERROR: couldn't copy package desriptions to $basepath/fink/dists/local/injected/finkinfo/update-packages\n";
exit 1;
}
}
# In this section, handle special cases where we have moved to a new real tree, but
# have maintained binary compatibility, by copying the .debs over to the new tree.
# Currently applies to 10.9-10.15 platforms coming from a
# dist that used the "10.7" subdir (regardless of actual platform)
if ( $distribution eq "10.9" or $distribution eq "10.10" or $distribution eq "10.11" or $distribution eq "10.12" or $distribution eq "10.13" or $distribution eq "10.14" or $distribution eq "10.14.5" or $distribution eq "10.15"
and -d "$basepath/fink/10.7" ) {
my @deb_list = glob "$basepath/fink/debs/*.deb";
my $copy_debs = 1;
foreach my $file ( @deb_list ) {
# Assume that we don't need to proceed if a single symlink resolves properly.
# Under normal circumstances
if (-l $file and -e $file) {
$copy_debs = 0;
last;
}
}
if ( $copy_debs ) {
print "Copying .debs...\n";
foreach my $file ( @deb_list ) {
# In %p/fink we have:
# "dists"->$distribution
# $distribution->REALDIR
# During upgrade, that second symlink is changed to point
# to REALDIR_NEW, which breaks symlinks to $distribution
# that had intended to reach files in REALDIR. The
# currently supported upgrade is from REALDIR=10.7, so we
# take the broken symlink, swap in that (old) REALDIR to
# find the file itself, and then copy it via the symlink
# (which now points to wherever REALDIR_NEW is).
my $target_file = readlink $file;
my $real_file = $target_file;
$real_file =~ s/$distribution/10.7/g; # assumes platform version has not changed (?)
my $dir = dirname ( $target_file );
# no need to make the directory if it already exists
unless ( -d "$basepath/fink/debs/$dir" ) {
if ( &execute ("/bin/mkdir -p $basepath/fink/debs/$dir" )) {
print "WARNING: couldn't create directory $basepath/fink/debs/$dir\n";
}
}
if ( &execute ("/bin/cp -f $basepath/fink/debs/$real_file $basepath/fink/debs/$target_file" )) {
print "WARNING: couldn't create file $basepath/fink/debs/$dir/$file\n";
}
}
}
}
# If a user upgrades to a new fink with AutoScanpackages, we'd rather do the
# first (uncached, long) scan in postinst than at the end of the user's next
# build.
sub pre_scanpackages {
my $autoscan = !$config->has_param("AutoScanpackages")
|| $config->param_boolean("AutoScanpackages");
return 0 unless $autoscan && apt_available;
require Fink::Scanpackages;
my $cache = Fink::Scanpackages->default_cache;
return 0 if -e $cache; # we already ran scanpackages at some point
print STDERR "Caching your binary packages...this may take a while.\n";
# Don't use the PDB, we don't want to trigger an index now
require Fink::Engine;
Fink::Engine::scanpackages({ pdb => 0 });
return 1;
}
pre_scanpackages();
if ($configNeedsUpdate) {
&print_breaking("\nThis fink version introduces new settings stored in the " .
"fink configuration file \"$configpath\". You should rerun the " .
"configuration process.\n");
my $answer = &prompt_boolean("Do you want to configure now?", default => 0, timeout => 60);
if ($answer) {
require Fink::Configure;
Fink::Configure::configure();
} else {
print "Please remember to call 'fink configure' later!\n\n";
}
} else {
# Only ask if not configuring, configure will ask later
if (&spotlight_warning()) {
$config->save;
}
}
exit 0;
# vim: ts=4 sw=4 noet