*** empty log message ***
[midnight-commander.git] / vfs / extfs / debd
blob483c598c7793e586daa2d90fb20da5c69e60612e
1 #!/usr/bin/perl
3 # 1999 (c) Piotr Roszatycki <dexter@debian.org>
4 # This software is under GNU license
5 # last modification: 1999-12-08
7 # debd
9 sub bt
11 my ($dt) = @_;
12 my (@time);
13 @time = localtime($dt);
14 $bt = sprintf "%02d-%02d-%02d %02d:%02d", $time[4], $time[3], $time[5], $time[2], $time[1];
15 return $bt;
19 sub ft
21 my ($f) = @_;
22 return "d" if -d $f;
23 return "l" if -l $f;
24 return "p" if -p $f;
25 return "S" if -S $f;
26 return "b" if -b $f;
27 return "c" if -c $f;
28 return "-";
31 sub fm
33 my ($n) = @_;
34 my ($m);
36 if( $n & 0400 ) {
37 $m .= "r";
38 } else {
39 $m .= "-";
41 if( $n & 0200 ) {
42 $m .= "w";
43 } else {
44 $m .= "-";
46 if( $n & 04000 ) {
47 $m .= "s";
48 } elsif( $n & 0100 ) {
49 $m .= "x";
50 } else {
51 $m .= "-";
54 if( $n & 0040 ) {
55 $m .= "r";
56 } else {
57 $m .= "-";
59 if( $n & 0020 ) {
60 $m .= "w";
61 } else {
62 $m .= "-";
64 if( $n & 02000 ) {
65 $m .= "s";
66 } elsif( $n & 0010 ) {
67 $m .= "x";
68 } else {
69 $m .= "-";
72 if( $n & 0004 ) {
73 $m .= "r";
74 } else {
75 $m .= "-";
77 if( $n & 0002 ) {
78 $m .= "w";
79 } else {
80 $m .= "-";
82 if( $n & 01000 ) {
83 $m .= "t";
84 } elsif( $n & 0001 ) {
85 $m .= "x";
86 } else {
87 $m .= "-";
90 return $m;
93 sub ls {
94 my ($file) = @_;
95 my @stat = stat($file);
96 # mode, nlink, uid, gid, size, mtime, filename
97 printf "%s%s %d %d %d %d %s CONTENTS%s\n", ft($file), fm($stat[2] & 07777),
98 $stat[3], $stat[4], $stat[5], $stat[7], bt($stat[9]), $file;
101 sub list
103 my($archive)=@_;
104 chop($date=`LC_ALL=C date "+%b %d %Y %H:%M"`);
105 chop($info_size=`dpkg -s $archive | wc -c`);
106 $repack_size=length($pressrepack);
107 $reinstall_size=length($pressreinstall);
108 $remove_size=length($pressremove);
109 $purge_size=length($presspurge);
110 $reconfigure_size=length($pressreconfigure);
111 $reinstall_size=length($pressreinstall);
112 $select_size=length($pressselect);
113 $unselect_size=length($pressunselect);
115 print "dr-xr-xr-x 1 root root 0 $date CONTENTS\n";
116 print "dr-xr-xr-x 1 root root 0 $date DEBIAN\n";
117 print "-r--r--r-- 1 root root $info_size $date INFO\n";
118 print "-r-xr--r-- 1 root root $purge_size $date DPKG-PURGE\n";
120 chop($status = `dpkg -s $archive | grep ^Status`);
121 if( $status =~ /deinstall/ ) {
122 print "-r-xr--r-- 1 root root $select_size $date DPKG-SELECT\n";
123 } elsif( $status =~ /install/ ) {
124 print "-r-xr--r-- 1 root root $unselect_size $date DPKG-UNSELECT\n";
126 if( $status !~ /config-files/ ) {
127 if ( -x "/usr/bin/dpkg-repack" ) {
128 print "-r-xr--r-- 1 root root $repack_size $date DPKG-REPACK\n";
130 print "-r-xr--r-- 1 root root $remove_size $date DPKG-REMOVE\n";
131 if ( -x "/usr/bin/apt-get" ) {
132 print "-r-xr--r-- 1 root root $remove_size $date APT-REMOVE\n";
133 print "-r-xr--r-- 1 root root $reinstall_size $date APT-REINSTALL\n";
134 print "-r-xr--r-- 1 root root $purge_size $date APT-PURGE\n";
137 if( -x "/usr/bin/dpkg-reconfigure" && -x "/var/lib/dpkg/info/$archive.config" ) {
138 print "-r-xr--r-- 1 root root $reconfigure_size $date DPKG-RECONFIGURE\n";
143 if ( open(PIPEIN, "LANG=C ls -l /var/lib/dpkg/info/$archive.* |") ) {
144 while(<PIPEIN>) {
145 chop;
146 next if /\.list$/;
147 s%/var/lib/dpkg/info/$archive.%DEBIAN/%;
148 print $_, "\n";
150 close PIPEIN;
153 if ( open(LIST, "/var/lib/dpkg/info/$archive.list") ) {
154 while(<LIST>) {
155 chop;
156 ls($_);
158 close LIST;
162 sub copyout
164 my($archive,$filename,$destfile)=@_;
166 if($filename eq "INFO") {
167 system("dpkg -s $archive > $destfile");
168 } elsif($filename eq "DPKG-REPACK") {
169 if ( open(FILEOUT,">$destfile") ) {
170 print FILEOUT $pressrepack;
171 close FILEOUT;
172 system("chmod a+x $destfile");
174 } elsif($filename =~ /^DEBIAN/) {
175 $filename=~s!^DEBIAN/!!;
176 system("cat /var/lib/dpkg/info/$archive.$filename > $destfile");
177 } elsif($filename eq "DPKG-REMOVE" || $filename eq "APT-REMOVE") {
178 if ( open(FILEOUT,">$destfile") ) {
179 print FILEOUT $pressremove;
180 close FILEOUT;
181 system("chmod a+x $destfile");
183 } elsif($filename eq "DPKG-PURGE" || $filename eq "APT-PURGE") {
184 if ( open(FILEOUT,">$destfile") ) {
185 print FILEOUT $presspurge;
186 close FILEOUT;
187 system("chmod a+x $destfile");
189 } elsif($filename eq "DPKG-RECONFIGURE") {
190 if ( open(FILEOUT,">$destfile") ) {
191 print FILEOUT $pressreconfigure;
192 close FILEOUT;
193 system("chmod a+x $destfile");
195 } elsif($filename eq "APT-REINSTALL") {
196 if ( open(FILEOUT,">$destfile") ) {
197 print FILEOUT $pressreinstall;
198 close FILEOUT;
199 system("chmod a+x $destfile");
201 } elsif($filename eq "DPKG-SELECT") {
202 if ( open(FILEOUT,">$destfile") ) {
203 print FILEOUT $pressselect;
204 close FILEOUT;
205 system("chmod a+x $destfile");
207 } elsif($filename eq "DPKG-UNSELECT") {
208 if ( open(FILEOUT,">$destfile") ) {
209 print FILEOUT $pressunselect;
210 close FILEOUT;
211 system("chmod a+x $destfile");
213 } else {
214 $filename=~s!^CONTENTS!!;
215 system("cat $filename > $destfile");
219 sub run
221 my($archive,$filename)=@_;
222 if($filename eq "DPKG-REMOVE") {
223 system("dpkg --remove $archive");
224 } elsif($filename eq "APT-REMOVE") {
225 system("apt-get remove $archive");
226 } elsif($filename eq "DPKG-PURGE") {
227 system("dpkg --purge $archive");
228 } elsif($filename eq "APT-PURGE") {
229 system("apt-get --purge remove $archive");
230 } elsif($filename eq "DPKG-REPACK") {
231 system("dpkg-repack $archive");
232 } elsif($filename eq "DPKG-SELECT") {
233 system("echo $archive install | dpkg --set-selections");
234 } elsif($filename eq "DPKG-UNSELECT") {
235 system("echo $archive deinstall | dpkg --set-selections");
236 } elsif($filename eq "APT-REINSTALL") {
237 system("apt-get -u --reinstall install $archive");
238 } elsif($filename eq "DPKG-RECONFIGURE") {
239 system("dpkg-reconfigure $archive");
240 } elsif($filename=~/^DEBIAN/) {
241 $filename=~s!^DEBIAN!!;
242 system("/var/lib/dpkg/info/$archive.$filename");
243 } else {
244 $filename=~s!^CONTENTS!!;
245 system($filename);
249 $pressrepack=<<EOInstall;
251 WARNING
252 Don\'t use this method if you are not willing to repack this package...
254 This is not a real file. It is a way to repack the package you are browsing.
256 To repack this package go back to the panel and press Enter on this file.
258 EOInstall
260 $pressreinstall=<<EOInstall;
262 WARNING
263 Don\'t use this method if you are not willing to reinstall this package...
265 This is not a real file. It is a way to reinstall the package you are browsing.
267 To reinstall this package go back to the panel and press Enter on this file.
269 EOInstall
271 $pressremove=<<EOInstall;
273 WARNING
274 Don\'t use this method if you are not willing to remove this package...
276 This is not a real file. It is a way to remove the package you are browsing.
278 To remove this package go back to the panel and press Enter on this file.
280 EOInstall
282 $presspurge=<<EOInstall;
284 WARNING
285 Don\'t use this method if you are not willing to purge this package...
287 This is not a real file. It is a way to purge the package you are browsing.
289 To purge this package go back to the panel and press Enter on this file.
291 EOInstall
293 $pressreconfigure=<<EOInstall;
295 WARNING
296 Don\'t use this method if you are not willing to reconfigure this package...
298 This is not a real file. It is a way to reconfigure the package you are browsing.
300 To reconfigure this package go back to the panel and press Enter on this file.
302 EOInstall
304 $pressreinstall=<<EOInstall;
306 WARNING
307 Don\'t use this method if you are not willing to reinstall this package...
309 This is not a real file. It is a way to reinstall the package you are browsing.
311 To reinstall this package go back to the panel and press Enter on this file.
313 EOInstall
315 $pressselect=<<EOInstall;
317 WARNING
318 Don\'t use this method if you are not willing to select this package...
320 This is not a real file. It is a way to select the package you are browsing.
322 To select this package go back to the panel and press Enter on this file.
324 EOInstall
326 $pressunselect=<<EOInstall;
328 WARNING
329 Don\'t use this method if you are not willing to unselect this package...
331 This is not a real file. It is a way to unselect the package you are browsing.
333 To unselect this package go back to the panel and press Enter on this file.
335 EOInstall
337 umask 077;
339 chop($name = `if [ -f "$ARGV[1]" ]; then cat $ARGV[1]; else echo $ARGV[1]; fi`);
340 $name =~ s%.*/([0-9a-z.-]*)_.*%$1%;
342 exit 1 unless $name;
344 if($ARGV[0] eq "list") { &list($name); exit 0; }
345 elsif($ARGV[0] eq "copyout") { &copyout($name,$ARGV[2],$ARGV[3]); exit 0; }
346 elsif($ARGV[0] eq "run") { &run($name,$ARGV[2]); exit 0; }
348 exit 1;