dpkg.in 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. #! @PERL@
  2. #
  3. # 1999 (c) Piotr Roszatycki <dexter@debian.org>
  4. # This software is under GNU license
  5. # last modification: 1999-12-08
  6. #
  7. # dpkg
  8. sub bt
  9. {
  10. my ($dt) = @_;
  11. my (@time);
  12. @time = localtime($dt);
  13. $bt = sprintf "%02d-%02d-%d %02d:%02d", $time[4] + 1, $time[3],
  14. $time[5] + 1900, $time[2], $time[1];
  15. return $bt;
  16. }
  17. sub ft
  18. {
  19. my ($f) = @_;
  20. return "d" if -d $f;
  21. return "l" if -l $f;
  22. return "p" if -p $f;
  23. return "S" if -S $f;
  24. return "b" if -b $f;
  25. return "c" if -c $f;
  26. return "-";
  27. }
  28. sub fm
  29. {
  30. my ($n) = @_;
  31. my ($m);
  32. if( $n & 0400 ) {
  33. $m .= "r";
  34. } else {
  35. $m .= "-";
  36. }
  37. if( $n & 0200 ) {
  38. $m .= "w";
  39. } else {
  40. $m .= "-";
  41. }
  42. if( $n & 04000 ) {
  43. $m .= "s";
  44. } elsif( $n & 0100 ) {
  45. $m .= "x";
  46. } else {
  47. $m .= "-";
  48. }
  49. if( $n & 0040 ) {
  50. $m .= "r";
  51. } else {
  52. $m .= "-";
  53. }
  54. if( $n & 0020 ) {
  55. $m .= "w";
  56. } else {
  57. $m .= "-";
  58. }
  59. if( $n & 02000 ) {
  60. $m .= "s";
  61. } elsif( $n & 0010 ) {
  62. $m .= "x";
  63. } else {
  64. $m .= "-";
  65. }
  66. if( $n & 0004 ) {
  67. $m .= "r";
  68. } else {
  69. $m .= "-";
  70. }
  71. if( $n & 0002 ) {
  72. $m .= "w";
  73. } else {
  74. $m .= "-";
  75. }
  76. if( $n & 01000 ) {
  77. $m .= "t";
  78. } elsif( $n & 0001 ) {
  79. $m .= "x";
  80. } else {
  81. $m .= "-";
  82. }
  83. return $m;
  84. }
  85. sub ls {
  86. my ($file,$path,$mode) = @_;
  87. my @stat = stat($file);
  88. # mode, nlink, uid, gid, size, mtime, filename
  89. printf "%s %d %d %d %d %s %s\n", $mode || ft($file).fm($stat[2] & 07777),
  90. $stat[3], $stat[4], $stat[5], $stat[7], bt($stat[9]), $path;
  91. }
  92. $DATE=bt(time());
  93. sub list
  94. {
  95. my ($pkg, $fn, $dn, $sz, $bt);
  96. my %debs = ();
  97. my %sects = ();
  98. my($diversions,$architecture);
  99. chop($diversions = `dpkg-divert --list 2>/dev/null`);
  100. chop($architecture = `dpkg-architecture 2>/dev/null`);
  101. chop($list = `dpkg -l '*' 2>/dev/null`);
  102. chop($getselections = `dpkg --get-selections 2>/dev/null`);
  103. chop($audit = `dpkg --audit 2>/dev/null`);
  104. $sz = length($diversions);
  105. print "-r--r--r-- 1 root root $sz $DATE DIVERSIONS\n";
  106. $sz = length($architecture);
  107. print "-r--r--r-- 1 root root $sz $DATE ARCHITECTURE\n";
  108. $sz = length($list);
  109. print "-r--r--r-- 1 root root $sz $DATE LIST\n";
  110. $sz = length($getselections);
  111. print "-r--r--r-- 1 root root $sz $DATE GET-SELECTIONS\n";
  112. $sz = length($audit);
  113. print "-r--r--r-- 1 root root $sz $DATE AUDIT\n";
  114. $sz = length($pressconfigure);
  115. print "-r-xr--r-- 1 root root $sz $DATE CONFIGURE\n";
  116. $sz = length($pressremove);
  117. print "-r-xr--r-- 1 root root $sz $DATE REMOVE\n";
  118. $sz = length($pressclearavail);
  119. print "-r-xr--r-- 1 root root $sz $DATE CLEAR-AVAIL\n";
  120. $sz = length($pressforgetoldunavail);
  121. print "-r-xr--r-- 1 root root $sz $DATE FORGET-OLD-UNAVAIL\n";
  122. ls("/var/lib/dpkg/status","STATUS","-r--r--r--");
  123. # ls("/var/lib/dpkg/available","AVAILABLE","-r--r--r--");
  124. print "drwxr-xr-x 1 root root 0 $DATE all\n";
  125. open STAT, "/var/lib/dpkg/status"
  126. or exit 1;
  127. while( <STAT> ) {
  128. chop;
  129. if( /^([\w-]*): (.*)/ ) {
  130. $pkg = $2 if( lc($1) eq 'package' );
  131. $debs{$pkg}{lc($1)} = $2;
  132. }
  133. }
  134. close STAT;
  135. foreach $pkg (sort keys %debs) {
  136. next if $debs{$pkg}{status} =~ /not-installed/;
  137. $fn = $debs{$pkg}{package}. "_". $debs{$pkg}{version};
  138. $dn = $debs{$pkg}{section};
  139. if( ! $dn ) {
  140. $dn = "unknown";
  141. } elsif( $dn =~ /^(non-us)$/i ) {
  142. $dn .= "/main";
  143. } elsif( $dn !~ /\// ) {
  144. $dn = "main/". $dn;
  145. }
  146. unless( $sects{$dn} ) {
  147. my $sub = $dn;
  148. while( $sub =~ s!^(.*)/[^/]*$!$1! ) {
  149. unless( $sects{$sub} ) {
  150. print "drwxr-xr-x 1 root root 0 $DATE $sub/\n";
  151. $sects{$sub} = 1;
  152. }
  153. }
  154. print "drwxr-xr-x 1 root root 0 $DATE $dn/\n";
  155. $sects{$dn} = 1;
  156. }
  157. $sz = $debs{$pkg}{'status'} =~ /config-files/ ? 0 : $debs{$pkg}{'installed-size'} * 1024;
  158. @stat = stat("/var/lib/dpkg/info/".$debs{$pkg}{package}.".list");
  159. $bt = bt($stat[9]);
  160. print "-rw-r--r-- 1 root root $sz $bt $dn/$fn.debd\n";
  161. print "lrwxrwxrwx 1 root root $sz $bt all/$fn.debd -> ../$dn/$fn.debd\n";
  162. }
  163. }
  164. sub copyout
  165. {
  166. my($archive,$filename) = @_;
  167. if( $archive eq 'DIVERSIONS' ) {
  168. system("dpkg-divert --list > $filename 2>/dev/null");
  169. } elsif( $archive eq 'ARCHITECTURE' ) {
  170. system("dpkg-architecture > $filename 2>/dev/null");
  171. } elsif( $archive eq 'LIST' ) {
  172. system("dpkg -l '*' > $filename 2>/dev/null");
  173. } elsif( $archive eq 'AUDIT' ) {
  174. system("dpkg --audit > $filename 2>/dev/null");
  175. } elsif( $archive eq 'GET-SELECTIONS' ) {
  176. system("dpkg --get-selections > $filename 2>/dev/null");
  177. } elsif( $archive eq 'STATUS' ) {
  178. system("cp /var/lib/dpkg/status $filename");
  179. } elsif( $archive eq 'AVAILABLE' ) {
  180. system("cp /var/lib/dpkg/available $filename");
  181. } elsif( $archive eq 'CONFIGURE' ) {
  182. open O, ">$filename";
  183. print O $pressconfigure;
  184. close O;
  185. } elsif( $archive eq 'REMOVE' ) {
  186. open O, ">$filename";
  187. print O $pressremove;
  188. close O;
  189. } elsif( $archive eq 'CLEAR-AVAIL' ) {
  190. open O, ">$filename";
  191. print O $pressclearavail;
  192. close O;
  193. } elsif( $archive eq 'FORGET-OLD-UNAVAIL' ) {
  194. open O, ">$filename";
  195. print O $pressforgetoldunavail;
  196. close O;
  197. } else {
  198. open O, ">$filename";
  199. print O $archive, "\n";
  200. close O;
  201. }
  202. }
  203. # too noisy but less dangerouse
  204. sub copyin
  205. {
  206. my($archive,$filename) = @_;
  207. if( $archive =~ /\.deb$/ ) {
  208. system("dpkg -i $filename>/dev/null");
  209. } else {
  210. die "extfs: cannot create regular file \`$archive\': Permission denied\n";
  211. }
  212. }
  213. sub run
  214. {
  215. my($archive,$filename) = @_;
  216. if( $archive eq 'CONFIGURE' ) {
  217. system("dpkg --pending --configure");
  218. } elsif( $archive eq 'REMOVE' ) {
  219. system("dpkg --pending --remove");
  220. } elsif( $archive eq 'CLEAR-AVAIL' ) {
  221. system("dpkg --clear-avail");
  222. } elsif( $archive eq 'FORGET-OLD-UNAVAIL' ) {
  223. system("dpkg --forget-old-unavail");
  224. } else {
  225. die "extfs: $filename: command not found\n";
  226. }
  227. }
  228. # Disabled - too dangerous and too noisy
  229. sub rm_disabled
  230. {
  231. my($archive) = @_;
  232. if( $archive =~ /\.debd?$/ ) {
  233. my $name = $archive;
  234. $name =~ s%.*/%%g;
  235. $name =~ s%_.*%%g;
  236. system("if dpkg -s $name | grep ^Status | grep -qs config-files; \
  237. then dpkg --purge $name>/dev/null; \
  238. else dpkg --remove $name>/dev/null; fi");
  239. die("extfs: $archive: Operation not permitted\n") if $? != 0;
  240. } else {
  241. die "extfs: $archive: Operation not permitted\n";
  242. }
  243. }
  244. $pressconfigure=<<EOInstall;
  245. WARNING
  246. Don\'t use this method if you are not willing to configure all
  247. non configured packages.
  248. This is not a real file. It is a way to configure all non configured packages.
  249. To configure packages go back to the panel and press Enter on this file.
  250. EOInstall
  251. $pressremove=<<EOInstall;
  252. WARNING
  253. Don\'t use this method if you are not willing to remove all
  254. unselected packages.
  255. This is not a real file. It is a way to remove all unselected packages.
  256. To remove packages go back to the panel and press Enter on this file.
  257. EOInstall
  258. $pressforgetoldunavail=<<EOInstall;
  259. WARNING
  260. Don\'t use this method if you are not willing to forget about
  261. uninstalled unavailable packages.
  262. This is not a real file. It is a way to forget about uninstalled
  263. unavailable packages.
  264. To forget this information go back to the panel and press Enter on this file.
  265. EOInstall
  266. $pressclearavail=<<EOInstall;
  267. WARNING
  268. Don\'t use this method if you are not willing to erase the existing
  269. information about what packages are available.
  270. This is not a real file. It is a way to erase the existing information
  271. about what packages are available.
  272. To clear this information go back to the panel and press Enter on this file.
  273. EOInstall
  274. # override any locale for dates
  275. $ENV{"LC_ALL"}="C";
  276. if ($ARGV[0] eq "list") { list(); exit(0); }
  277. elsif ($ARGV[0] eq "copyout") { copyout($ARGV[2], $ARGV[3]); exit(0); }
  278. elsif ($ARGV[0] eq "copyin") { copyin($ARGV[2], $ARGV[3]); exit(0); }
  279. elsif ($ARGV[0] eq "run") { run($ARGV[2],$ARGV[3]); exit(0); }
  280. #elsif ($ARGV[0] eq "rm") { rm($ARGV[2]); exit(0); }
  281. exit(1);