deb.in 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #! @PERL@
  2. #
  3. # Written by Fernando Alegre <alegre@debian.org> 1996
  4. #
  5. # Applied patch by Dimitri Maziuk <emaziuk@curtin.edu.au> 1997
  6. # (to handle new tar format)
  7. #
  8. # Modified by Fernando Alegre <alegre@debian.org> 1997
  9. # (to handle both new and old tar formats)
  10. #
  11. # Modified by Patrik Rak <prak@post.cz> 1998
  12. # (add by Michael Bramer Debian-mc-maintainer <grisu@debian.org>)
  13. # (to allow access to package control files)
  14. #
  15. # Modified by Martin Bialasinski <martinb@debian.org> 1999
  16. # (deal with change in tar format)
  17. #
  18. #
  19. # Copyright (C) 1997 Free Software Foundation
  20. #
  21. sub quote {
  22. $_ = shift(@_);
  23. s/([^\w\/.+-])/\\$1/g;
  24. return($_);
  25. }
  26. sub mcdebfs_list
  27. {
  28. #
  29. # CAVEAT: Hard links are listed as if they were symlinks
  30. # Empty directories do not appear at all
  31. #
  32. local($archivename)=@_;
  33. local $qarchivename = quote($archivename);
  34. chop($date=`LC_ALL=C date "+%b %d %H:%M"`);
  35. chop($info_size=`LC_ALL=C dpkg -I $qarchivename | wc -c`);
  36. $install_size=length($pressinstall);
  37. print "dr-xr-xr-x 1 root root 0 $date CONTENTS\n";
  38. print "dr-xr-xr-x 1 root root 0 $date DEBIAN\n";
  39. print "-r--r--r-- 1 root root $info_size $date INFO\n";
  40. print "-r-xr--r-- 1 root root $install_size $date INSTALL\n";
  41. if ( open(PIPEIN, "dpkg-deb -c $qarchivename |") )
  42. {
  43. while(<PIPEIN>)
  44. {
  45. split;
  46. $perm=$_[0]; $owgr=$_[1]; $size=$_[2];
  47. if($_[3] =~ /^\d\d\d\d\-/) { # New tar format
  48. ($year,$mon,$day) = split(/-/,$_[3]);
  49. $month = ("Gee","Jan","Feb","Mar","Apr","May","Jun",
  50. "Jul","Aug","Sep","Oct","Nov","Dec")[$mon] || "Gee";
  51. $time=$_[4];
  52. $pathindex=5;
  53. }
  54. else {
  55. $mstring='GeeJanFebMarAprMayJunJulAugSepOctNovDec';
  56. $month=$_[3];
  57. $mon=index($mstring,$month) / 3;
  58. $day=$_[4];
  59. $time=$_[5];
  60. $year=$_[6];
  61. $pathindex=7;
  62. }
  63. $path=$_[$pathindex++];
  64. $arrow=$_[$pathindex++];
  65. $link=$_[$pathindex++];
  66. $link2=$_[$pathindex++];
  67. $owgr=~s!/! !;
  68. if($arrow eq 'link')
  69. {
  70. # report hard links as soft links
  71. $arrow='->'; $link="/$link2";
  72. substr($perm, 0, 1) = "l";
  73. }
  74. if($arrow ne '')
  75. {
  76. $arrow=' ' . $arrow;
  77. $link= ' ' . $link;
  78. }
  79. $now=`date "+%Y %m"`;
  80. ($thisyear, $thismon) = split(/ /, $now);
  81. # show time for files younger than 6 months
  82. # but not for files with dates in the future
  83. if ($year * 12 + $mon > $thisyear * 12 + $thismon - 6 &&
  84. $year * 12 + $mon <= $thisyear * 12 + $thismon) {
  85. print "$perm 1 $owgr $size $month $day $time CONTENTS/$path$arrow$link\n";
  86. } else {
  87. print "$perm 1 $owgr $size $month $day $year CONTENTS/$path$arrow$link\n";
  88. }
  89. }
  90. }
  91. if ( open(PIPEIN, "LC_ALL=C dpkg-deb -I $qarchivename |") )
  92. {
  93. while(<PIPEIN>)
  94. {
  95. split;
  96. $size=$_[0];
  97. last if $size =~ /:/;
  98. next if $size !~ /\d+/;
  99. if($_[4] eq '*')
  100. {
  101. $perm='-r-xr-xr-x';
  102. $name=$_[5];
  103. }
  104. else
  105. {
  106. $perm='-r--r--r--';
  107. $name=$_[4];
  108. }
  109. print "$perm 1 root root $size $date DEBIAN/$name\n";
  110. }
  111. }
  112. }
  113. sub mcdebfs_copyout
  114. {
  115. local($archive,$filename,$destfile)=@_;
  116. local $qarchive = quote($archive);
  117. local $qfilename = quote($filename);
  118. local $qdestfile = quote($destfile);
  119. if($filename eq "INFO")
  120. {
  121. system("dpkg-deb -I $qarchive > $qdestfile");
  122. }
  123. elsif($filename =~ /^DEBIAN/)
  124. {
  125. $qfilename=~s!^DEBIAN/!!;
  126. system("dpkg-deb -I $qarchive $qfilename > $qdestfile");
  127. }
  128. elsif($filename eq "INSTALL")
  129. {
  130. if ( open(FILEOUT,">$destfile") )
  131. {
  132. print FILEOUT $pressinstall;
  133. close FILEOUT;
  134. system("chmod a+x $qdestfile");
  135. }
  136. }
  137. else
  138. {
  139. # files can be prepended with ./ or not, depending on the version of tar
  140. $qfilename=~s!^CONTENTS/!!;
  141. system("dpkg-deb --fsys-tarfile $qarchive | tar xOf - $qfilename ./$qfilename > $qdestfile 2>/dev/null");
  142. }
  143. }
  144. sub mcdebfs_run
  145. {
  146. local($archive,$filename)=@_;
  147. local $qarchive = quote($archive);
  148. if($filename eq "INSTALL")
  149. {
  150. print "Installing $archive\n";
  151. system("dpkg -i $qarchive");
  152. }
  153. else
  154. {
  155. use File::Temp qw(mkdtemp);
  156. my $template = "/tmp/mcdebfs.run.XXXXXX";
  157. $template="$ENV{MC_TMPDIR}/mcdebfs.XXXXXX" if ($ENV{MC_TMPDIR});
  158. $tmpdir = mkdtemp($template);
  159. $tmpcmd="$tmpdir/run";
  160. &mcdebfs_copyout($archive, $filename, $tmpcmd);
  161. system("chmod u+x $tmpcmd");
  162. system($tmpcmd);
  163. unlink($tmpcmd);
  164. rmdir($tmpdir);
  165. }
  166. }
  167. $pressinstall=<<EOInstall;
  168. WARNING
  169. Don\'t use this method if you are not willing to reinstall everything...
  170. This is not a real file. It is a way to install the package you are browsing.
  171. To install this package go back to the panel and press Enter on this file.
  172. In Debian systems, a package is automatically upgraded when you install a new
  173. version of it. There is no special upgrade option. Install always works.
  174. EOInstall
  175. umask 077;
  176. if($ARGV[0] eq "list") { shift; &mcdebfs_list(@ARGV); exit 0; }
  177. elsif($ARGV[0] eq "copyout") { shift; &mcdebfs_copyout(@ARGV); exit 0; }
  178. elsif($ARGV[0] eq "run") { shift; &mcdebfs_run(@ARGV); exit 0; }
  179. exit 1;