-
Notifications
You must be signed in to change notification settings - Fork 0
/
inject.pl
executable file
·210 lines (181 loc) · 5.3 KB
/
inject.pl
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
#!/usr/bin/perl -w
#
# inject.pl - perl script to copy package definitions into an existing
# Fink installation
#
# Fink - a package manager that downloads source and installs it
# Copyright (c) 2001 Christoph Pfisterer
# Copyright (c) 2001-2003 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
$| = 1;
use 5.006; # perl 5.6.0 or newer required
use strict;
use File::Find;
### list our directories
my @contents = `ls`;
my ($filename,@directories);
foreach $filename (@contents) {
chomp($filename);
if (-d $filename and not $filename eq "CVS") {
push(@directories, $filename);
}
}
### check if we're unharmed
foreach $filename (@directories) {
if (not -d "$filename/stable/main/finkinfo") {
print "ERROR: Package is incomplete.\n";
exit 1;
}
}
### locate Fink installation
my ($basepath, $guessed, $param, $path);
$guessed = "";
$param = shift;
if (defined $param) {
$basepath = $param;
} else {
$basepath = undef;
if (exists $ENV{PATH}) {
foreach $path (split(/:/, $ENV{PATH})) {
if (substr($path,-1) eq "/") {
$path = substr($path,0,-1);
}
if (-f "$path/init.sh" and -f "$path/fink") {
$path =~ /^(.+)\/[^\/]+$/;
$basepath = $1;
last;
}
}
}
if (not defined $basepath or $basepath eq "") {
$basepath = "/sw";
}
$guessed = " (guessed)";
}
unless (-f "$basepath/bin/fink" and
-f "$basepath/bin/init.sh" and
-f "$basepath/etc/fink.conf" and
-l "$basepath/fink/dists") {
&print_breaking("The directory '$basepath'$guessed does not contain a ".
"Fink installation. Please provide the correct path ".
"as a parameter to this script.");
exit 1;
}
foreach $filename (@directories) {
if (-d "$basepath/fink/CVS" or -d "$basepath/fink/$filename/CVS") {
&print_breaking("The directory '$basepath' contains a Fink installation ".
"that was set up to get package descriptions directly ".
"from CVS. This script will not update this ".
"installation. Run 'cvs update -d -P' in the directory ".
"'$basepath/fink' instead.");
exit 1;
}
}
### parse config file for root method
# TODO: really parse the file, support both su and sudo
# for now, we just use sudo...
if ($> != 0) {
exit &execute("sudo ./inject.pl $basepath");
}
umask oct("022");
### copy description files
print "Copying...\n";
if (not -d "$basepath/fink/debs") {
&execute("/bin/mkdir -p -m755 $basepath/fink/debs");
}
if (&execute("/bin/cp -f README $basepath/fink/; /bin/chmod 644 $basepath/fink/README")) {
print "ERROR: Can't copy README file.\n";
exit 1;
}
if (&execute("/bin/cp -f VERSION $basepath/fink/; /bin/chmod 644 $basepath/fink/VERSION")) {
print "ERROR: Can't copy VERSION file.\n";
exit 1;
}
&execute("rm -f $basepath/fink/stamp-*");
if (-f "stamp-cvs-live") {
my @now = gmtime(time);
my $timestamp = sprintf("%04d%02d%02d-%02d%02d",
$now[5]+1900, $now[4]+1, $now[3],
$now[2], $now[1]);
&execute("touch $basepath/fink/stamp-cvs-$timestamp");
} else {
&execute("cp stamp-* $basepath/fink/");
}
sub wanted {
my ($dir);
if (-f and not /^[\.#]/ and (/\.info$/ or /\.patch$/)) {
$dir = $basepath."/fink/".$File::Find::dir;
if (not -d $dir) {
if (&execute("/bin/mkdir -p -m755 $dir")) {
print "ERROR: Can't copy package descriptions.\n";
exit 1;
}
}
if (&execute("/bin/cp -f $_ $dir/; /bin/chmod 644 $dir/$_")) {
print "ERROR: Can't copy package descriptions.\n";
exit 1;
}
}
}
### this version of the script is for "10.2" and later, not "dists"
foreach $filename (@directories) {
find(\&wanted, "$filename");
}
### inform the user
unless (defined $ARGV[0] and $ARGV[0] eq "-quiet") {
print "\n";
&print_breaking("Your Fink installation in '$basepath' was updated with ".
"new package description files. Please update the package ".
"manager using 'fink update fink', then use appropriate ".
"commands to update the other packages, ".
"e.g. 'fink update-all'.");
print "\n";
}
### helper functions
sub execute {
my $cmd = shift;
my $quiet = shift || 0;
my ($retval, $prog);
print "$cmd\n";
$retval = system($cmd);
$retval >>= 8 if defined $retval and $retval >= 256;
if ($retval and not $quiet) {
($prog) = split(/\s+/, $cmd);
print "### $prog failed, exit code $retval\n";
}
return $retval;
}
sub print_breaking {
my $s = shift;
my ($pos, $t);
my $linelength = 77;
chomp($s);
while (length($s) > $linelength) {
$pos = rindex($s," ",$linelength);
if ($pos < 0) {
$t = substr($s,0,$linelength);
$s = substr($s,$linelength);
} else {
$t = substr($s,0,$pos);
$s = substr($s,$pos+1);
}
print "$t\n";
}
print "$s\n";
}
### eof
exit 0;