dpkg.in 8.8 KB

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