deba.in 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. # deba
  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) = @_;
  87. my @stat = stat($file);
  88. # mode, nlink, uid, gid, size, mtime, filename
  89. printf "%s%s %d %d %d %d %s CONTENTS%s\n", ft($file), fm($stat[2] & 07777),
  90. $stat[3], $stat[4], $stat[5], $stat[7], bt($stat[9]), $file;
  91. }
  92. sub list
  93. {
  94. my($archive)=@_;
  95. chop($date=`LC_ALL=C date "+%b %d %Y %H:%M"`);
  96. chop($info_size=`apt-cache show $archive | wc -c`);
  97. $install_size=length($pressinstall);
  98. $upgrade_size=length($pressupgrade);
  99. print "-r--r--r-- 1 root root $info_size $date INFO\n";
  100. chop($debd = `dpkg -s $archive | grep -i ^Version | sed 's/^version: //i'`);
  101. chop($deba = `apt-cache show $archive | grep -i ^Version | sed 's/^version: //i'`);
  102. if( ! $debd ) {
  103. print "-r-xr--r-- 1 root root $install_size $date INSTALL\n";
  104. } elsif( $debd ne $deba ) {
  105. print "-r-xr--r-- 1 root root $upgrade_size $date UPGRADE\n";
  106. }
  107. }
  108. sub copyout
  109. {
  110. my($archive,$filename,$destfile)=@_;
  111. if($filename eq "INFO") {
  112. system("apt-cache show $archive > $destfile");
  113. } elsif($filename eq "INSTALL") {
  114. if ( open(FILEOUT,">$destfile") ) {
  115. print FILEOUT $pressinstall;
  116. close FILEOUT;
  117. system("chmod a+x $destfile");
  118. }
  119. } elsif($filename eq "UPGRADE") {
  120. if ( open(FILEOUT,">$destfile") ) {
  121. print FILEOUT $pressupgrade;
  122. close FILEOUT;
  123. system("chmod a+x $destfile");
  124. }
  125. } else {
  126. die "extfs: $filename: No such file or directory\n";
  127. }
  128. }
  129. sub run
  130. {
  131. my($archive,$filename)=@_;
  132. if($filename eq "INSTALL") {
  133. system("apt-get install $archive");
  134. } elsif($filename eq "UPGRADE") {
  135. system("apt-get install $archive");
  136. } else {
  137. die "extfs: $filename: Permission denied\n";
  138. }
  139. }
  140. $pressinstall=<<EOInstall;
  141. WARNING
  142. Don\'t use this method if you are not willing to install this package...
  143. This is not a real file. It is a way to install the package you are browsing.
  144. To install this package go back to the panel and press Enter on this file.
  145. EOInstall
  146. $pressupgrade=<<EOInstall;
  147. WARNING
  148. Don\'t use this method if you are not willing to upgrade this package...
  149. This is not a real file. It is a way to upgrade the package you are browsing.
  150. To upgrade this package go back to the panel and press Enter on this file.
  151. EOInstall
  152. umask 077;
  153. chop($name = `if [ -f "$ARGV[1]" ]; then cat $ARGV[1]; else echo $ARGV[1]; fi`);
  154. $name =~ s%.*/([0-9a-z.-]*)_.*%$1%;
  155. exit 1 unless $name;
  156. if($ARGV[0] eq "list") { &list($name); exit 0; }
  157. elsif($ARGV[0] eq "copyout") { &copyout($name,$ARGV[2],$ARGV[3]); exit 0; }
  158. elsif($ARGV[0] eq "run") { &run($name,$ARGV[2]); exit 0; }
  159. exit 1;