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
348
349
350
351
352
353
354
355
356
357
358
359
|
#! @PERL@
#
# 1999 (c) Piotr Roszatycki <dexter@debian.org>
# This software is under GNU license
# last modification: 1999-12-08
#
# apt
sub quote {
$_ = shift(@_);
s/([^\w\/.+-])/\\$1/g;
return($_);
}
sub bt
{
my ($dt) = @_;
my (@time);
@time = localtime($dt);
$bt = sprintf "%02d-%02d-%d %02d:%02d", $time[4] + 1, $time[3],
$time[5] + 1900, $time[2], $time[1];
return $bt;
}
sub ft
{
my ($f) = @_;
return "d" if -d $f;
return "l" if -l $f;
return "p" if -p $f;
return "S" if -S $f;
return "b" if -b $f;
return "c" if -c $f;
return "-";
}
sub fm
{
my ($n) = @_;
my ($m);
if( $n & 0400 ) {
$m .= "r";
} else {
$m .= "-";
}
if( $n & 0200 ) {
$m .= "w";
} else {
$m .= "-";
}
if( $n & 04000 ) {
$m .= "s";
} elsif( $n & 0100 ) {
$m .= "x";
} else {
$m .= "-";
}
if( $n & 0040 ) {
$m .= "r";
} else {
$m .= "-";
}
if( $n & 0020 ) {
$m .= "w";
} else {
$m .= "-";
}
if( $n & 02000 ) {
$m .= "s";
} elsif( $n & 0010 ) {
$m .= "x";
} else {
$m .= "-";
}
if( $n & 0004 ) {
$m .= "r";
} else {
$m .= "-";
}
if( $n & 0002 ) {
$m .= "w";
} else {
$m .= "-";
}
if( $n & 01000 ) {
$m .= "t";
} elsif( $n & 0001 ) {
$m .= "x";
} else {
$m .= "-";
}
return $m;
}
sub ls {
my ($file,$path,$mode) = @_;
if (-f $file) {
my @stat = stat(_);
# mode, nlink, uid, gid, size, mtime, filename
printf "%s %d %d %d %d %s %s\n", $mode || ft($file).fm($stat[2] & 07777),
$stat[3], $stat[4], $stat[5], $stat[7], bt($stat[9]), $path;
}
}
$DATE=bt(time());
sub list
{
my ($pkg, $fn, $dn, $sz, $bt);
my($check,$stats,$config);
chop($check = `apt-get -q check 2>/dev/null`);
chop($available = `apt-cache dumpavail 2>/dev/null`);
chop($stats = `apt-cache stats 2>/dev/null`);
chop($config = `apt-config dump 2>&1`);
$sz = length($check);
print "-r--r--r-- 1 root root $sz $DATE CHECK\n";
$sz = length($available);
print "-r--r--r-- 1 root root $sz $DATE AVAILABLE\n";
$sz = length($stats);
print "-r--r--r-- 1 root root $sz $DATE STATS\n";
$sz = length($config);
print "-r--r--r-- 1 root root $sz $DATE CONFIG\n";
$sz = length($pressupdate);
print "-r-xr--r-- 1 root root $sz $DATE UPDATE\n";
$sz = length($pressupgrade);
print "-r-xr--r-- 1 root root $sz $DATE UPGRADE\n";
print "-r-xr--r-- 1 root root $sz $DATE DIST-UPGRADE\n";
ls("/etc/apt/sources.list","sources.list");
ls('/etc/apt/apt.conf','apt.conf') if (-f '/etc/apt/apt.conf');
print "drwxr-xr-x 1 root root 0 $DATE all\n";
if ( open(PIPEIN, "find /var/cache/apt/archives -type f |") ) {
while(<PIPEIN>) {
chop;
next if /\/lock$/;
my $file = $_;
s%/var/cache/apt/archives/%CACHE/%;
ls($file, $_);
}
close PIPEIN;
}
my %sects = ();
my %debd = ();
my %deba = ();
open STAT, "/var/lib/dpkg/status"
or exit 1;
while( <STAT> ) {
chop;
if( /^([\w-]*): (.*)/ ) {
$pkg = $2 if( lc($1) eq 'package' );
$debd{$pkg}{lc($1)} = $2;
}
}
close STAT;
foreach $pkg (sort keys %debd) {
next if $debd{$pkg}{status} =~ /not-installed/;
$fn = $debd{$pkg}{package}. "_". $debd{$pkg}{version};
$dn = $debd{$pkg}{section};
if( ! $dn ) {
$dn = "unknown";
} elsif( $dn =~ /^(non-us)$/i ) {
$dn .= "/main";
} elsif( $dn !~ /\// ) {
$dn = "main/". $dn;
}
unless( $sects{$dn} ) {
my $sub = $dn;
while( $sub =~ s!^(.*)/[^/]*$!$1! ) {
unless( $sects{$sub} ) {
print "drwxr-xr-x 1 root root 0 $DATE $sub/\n";
$sects{$sub} = 1;
}
}
print "drwxr-xr-x 1 root root 0 $DATE $dn/\n";
$sects{$dn} = 1;
}
$sz = $debd{$pkg}{'status'} =~ /config-files/ ? 0 : $debd{$pkg}{'installed-size'} * 1024;
@stat = stat("/var/lib/dpkg/info/".$debd{$pkg}{package}.".list");
$bt = bt($stat[9]);
print "-rw-r--r-- 1 root root $sz $bt $dn/$fn.debd\n";
print "lrwxrwxrwx 1 root root $sz $bt all/$fn.debd -> ../$dn/$fn.debd\n";
}
open STAT, "apt-cache dumpavail |"
or exit 1;
while( <STAT> ) {
chop;
if( /^([\w-]*): (.*)/ ) {
$pkg = $2 if( lc($1) eq 'package' );
$deba{$pkg}{lc($1)} = $2;
}
}
close STAT;
foreach $pkg (sort keys %deba) {
next if $deba{$pkg}{version} eq $debd{$pkg}{version};
$fn = $deba{$pkg}{package}. "_". $deba{$pkg}{version};
$dn = $deba{$pkg}{section};
if( ! $dn ) {
$dn = "unknown";
} elsif( $dn =~ /^(non-us)$/i ) {
$dn .= "/main";
} elsif( $dn !~ /\// ) {
$dn = "main/". $dn;
}
unless( $sects{$dn} ) {
my $sub = $dn;
while( $sub =~ s!^(.*)/[^/]*$!$1! ) {
unless( $sects{$sub} ) {
print "drwxr-xr-x 1 root root 0 $DATE $sub/\n";
$sects{$sub} = 1;
}
}
print "drwxr-xr-x 1 root root 0 $DATE $dn/\n";
$sects{$dn} = 1;
}
$sz = $deba{$pkg}{'status'} =~ /config-files/ ? 0 : $deba{$pkg}{'installed-size'} * 1024;
print "-rw-r--r-- 1 root root $sz $DATE $dn/$fn.deba\n";
print "lrwxrwxrwx 1 root root $sz $DATE all/$fn.deba -> ../$dn/$fn.deba\n";
}
}
sub copyout
{
my($archive,$filename) = @_;
my $qarchive = quote($archive);
my $qfilename = quote($filename);
if( $archive eq 'CHECK' ) {
system("apt-get -q check > $qfilename");
} elsif( $archive eq 'AVAILABLE' ) {
system("apt-cache dumpavail > $qfilename");
} elsif( $archive eq 'STATS' ) {
system("apt-cache stats > $qfilename");
} elsif( $archive eq 'CONFIG' ) {
system("(apt-config dump 2>&1) > $qfilename");
} elsif( $archive eq 'UPDATE' ) {
open O, ">$filename";
print O $pressupdate;
close O;
} elsif( $archive eq 'UPGRADE' || $archive eq 'DIST-UPGRADE' ) {
open O, ">$filename";
print O $pressupgrade;
close O;
} elsif( $archive eq 'apt.conf' ) {
system("cp /etc/apt/apt.conf $qfilename");
} elsif( $archive eq 'sources.list' ) {
system("cp /etc/apt/sources.list $qfilename");
} elsif( $archive =~ /^CACHE\// ) {
$archive =~ s%^CACHE/%/var/cache/apt/archives/%;
system("cp $qarchive $qfilename");
} else {
open O, ">$filename";
print O $archive, "\n";
close O;
}
}
sub copyin
{
my($archive,$filename) = @_;
my $qarchive = quote($archive);
my $qfilename = quote($filename);
if( $archive =~ /\.deb$/ ) {
system("dpkg -i $qfilename>/dev/null");
} elsif( $archive eq 'apt.conf' ) {
system("cp $qfilename /etc/apt/apt.conf");
} elsif( $archive eq 'sources.list' ) {
system("cp $qfilename /etc/apt/sources.list");
} elsif( $archive =~ /^CACHE\// ) {
$qarchive =~ s%^CACHE/%/var/cache/apt/archives/%;
system("cp $qfilename $qarchive");
} else {
die "extfs: cannot create regular file \`$archive\': Permission denied\n";
}
}
sub run
{
my($archive,$filename) = @_;
if( $archive eq 'UPDATE' ) {
system("apt-get update");
} elsif( $archive eq 'UPGRADE' ) {
system("apt-get upgrade -u");
} elsif( $archive eq 'DIST-UPGRADE' ) {
system("apt-get dist-upgrade -u");
} else {
die "extfs: $archive: command not found\n";
}
}
sub rm
{
my($archive) = @_;
my $qarchive = quote($archive);
if( $archive =~ /^CACHE\// ) {
$qarchive =~ s%^CACHE/%/var/cache/apt/archives/%;
system("rm -f $qarchive");
} elsif( $archive eq 'apt.conf' ) {
system("rm -f /etc/apt/apt.conf");
} elsif( $archive eq 'sources.list' ) {
system("rm -f /etc/apt/sources.list");
} elsif( $archive =~ /\.debd?$/ ) {
# uncommented and changed to use dpkg - alpha
my $qname = $qarchive;
$qname =~ s%.*/%%g;
$qname =~ s%_.*%%g;
system("dpkg --remove $qname >/dev/null");
die("extfs: $archive: Operation not permitted\n") if $? != 0;
} else {
die "extfs: $archive: Operation not permitted\n";
}
}
$pressupdate=<<EOInstall;
WARNING
Don\'t use this method if you don't want to retrieve new lists of packages.
==========================================================================
This is not a real file. It is a way to retrieve new lists of packages.
To update this information go back to the panel and press Enter on this file.
EOInstall
$pressupgrade=<<EOInstall;
WARNING
Don\'t use this method if you are not willing to perform an upgrade.
===================================================================
This is not a real file. It is a way to perform an upgrade.
To upgrade this information go back to the panel and press Enter on this file.
EOInstall
# override any locale for dates
$ENV{"LC_ALL"}="C";
if ($ARGV[0] eq "list") { list(); exit(0); }
elsif ($ARGV[0] eq "copyout") { copyout($ARGV[2], $ARGV[3]); exit(0); }
elsif ($ARGV[0] eq "copyin") { copyin($ARGV[2], $ARGV[3]); exit(0); }
elsif ($ARGV[0] eq "run") { run($ARGV[2]); exit(0); }
elsif ($ARGV[0] eq "rm") { rm($ARGV[2]); exit(0); }
exit(1);
|