install 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. #!/bin/sh
  2. #
  3. # Copyright © 1995-1998 Ian Jackson <ian@chiark.greenend.org.uk>
  4. # Copyright © 1998 Heiko Schlittermann <heiko@lotte.sax.de>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; version 2 dated June, 1991.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. set -e
  18. vardir="$1"
  19. method=$2
  20. option=$3
  21. cd "$vardir/methods/$method"
  22. . ./shvar.$option
  23. #debug() { echo "DEBUG: $@"; }
  24. debug() { true; }
  25. iarch=`dpkg --print-architecture`
  26. ismulti() { test -e "$1/.disk/info" || test -e "$1$2/.disk/info"; }
  27. # 1/ mountpoint
  28. # 2/ hierarchy
  29. getdisklabel () {
  30. debug "$1" "$2"
  31. if [ -f $1/.disk/info ]
  32. then
  33. echo -n `head -1 "$1/.disk/info"`
  34. else
  35. if [ -f $1$2/.disk/info ]
  36. then
  37. echo -n `head -1 "$1$2/.disk/info"`
  38. else
  39. echo -n 'Non-Debian disc'
  40. fi
  41. fi
  42. }
  43. xit=1
  44. do_umount() {
  45. if [ "$method" = "multi_mount" ]
  46. then
  47. echo true
  48. return
  49. fi
  50. if [ -n "$umount" ]; then
  51. echo umount "$umount"
  52. #">/dev/null" "2>&1"
  53. fi
  54. }
  55. do_mount() {
  56. if [ "$method" = "multi_mount" ]
  57. then
  58. echo true
  59. return
  60. fi
  61. if [ ! -b "$p_blockdev" ]
  62. then
  63. loop=",loop"
  64. fi
  65. if [ -n "$p_blockdev" ]
  66. then
  67. umount="$p_mountpoint"
  68. echo mount -rt iso9660 -o nosuid,nodev${loop} "$p_blockdev" "$p_mountpoint"\; umount="$p_mountpoint"
  69. fi
  70. if [ -n "$p_nfs" ]
  71. then
  72. umount="$p_mountpoint"
  73. echo mount -rt nfs "$p_nfs" -o nosuid,nodev "$p_mountpoint"\; umount="$p_mountpoint"
  74. fi
  75. #if [ -n "$p_multi" -a -n "$p_multi_contentsfile" ]; then
  76. #echo "This is disk "
  77. #echo " "`getdisklabel "${p_mountpoint}" "${p_hierbase}"`
  78. #fi
  79. }
  80. trap 'eval `do_umount`; exit $xit' 0
  81. eval `do_mount`
  82. predep="$vardir/predep-package"
  83. while true
  84. do
  85. thisdisk="`getdisklabel ${p_mountpoint} ${p_hierbase}`"
  86. set +e
  87. dpkg --predep-package >"$predep"
  88. rc=$?
  89. set -e
  90. if test $rc = 1; then break; fi
  91. test $rc = 0
  92. perl -e '
  93. ($binaryprefix,$predep,$thisdisk) = @ARGV;
  94. open(P,"< $predep") || die "cannot open $predep: $!\n";
  95. while (<P>) {
  96. s/\s*\n$//;
  97. $package= $_ if s/^Package: //i;
  98. /^X-Medium:\s+(.*)\s*/ and $medium = $1;
  99. @filename= split(/ /,$_) if s/^Filename: //i;
  100. @msdosfilename= split(/ /,$_) if s/^MSDOS-Filename: //i;
  101. }
  102. die "internal error - no package" if length($package) == 0;
  103. die "internal error - no filename" if not @filename;
  104. die "internal error - mismatch >@filename< >@msdosfilename<"
  105. if @filename && @msdosfilename &&
  106. @filename != @msdosfilename;
  107. if ($medium && ($medium ne $thisdisk)) {
  108. print "
  109. This is
  110. $thisdisk
  111. However, $package is expected on disc:
  112. $medium
  113. Please change the discs and press <RETURN>.
  114. ";
  115. exit(1);
  116. }
  117. @invoke=(); $|=1;
  118. for ($i=0; $i<=$#filename; $i++) {
  119. $ppart= $i+1;
  120. print "Looking for part $ppart of $package ... ";
  121. if (-f "$binaryprefix$filename[$i]") {
  122. $print= $filename[$i];
  123. $invoke= "$binaryprefix$filename[$i]";
  124. } elsif (-f "$binaryprefix$msdosfilename[$i]") {
  125. $print= $msdosfilename[$i];
  126. $invoke= "$binaryprefix$msdosfilename[$i]";
  127. } else {
  128. $base= $filename[$i]; $base =~ s,.*/,,;
  129. $msdosbase= $msdosfilename[$i]; $msdosbase =~ s,.*/,,;
  130. $c = open(X, "-|"));
  131. if (not defined $c) {
  132. die "failed to fork for find: $!\n";
  133. }
  134. if (!$c) {
  135. exec("find", "-L",
  136. length($binaryprefix) ? $binaryprefix : ".",
  137. "-name",$base,"-o","-name",$msdosbase);
  138. die "failed to exec find: $!\n";
  139. }
  140. while (chop($invoke= <X>)) { last if -f $invoke; }
  141. $print= $invoke;
  142. if (substr($print,0,length($binaryprefix)+1) eq
  143. "$binaryprefix/") {
  144. $print= substr($print,length($binaryprefix));
  145. }
  146. }
  147. if (!length($invoke)) {
  148. print STDERR "
  149. Oh dear, I need to install or upgrade $package, but I don'\''t see
  150. the appropriate file(s) anywhere. I'\''m expecting version $version or
  151. later, as that is listed in the Packages.cd file.
  152. Perhaps you downloaded it with an unexpected name, or something.
  153. In any case, you must find the file(s) and then either place it with
  154. the correct filename(s) (as listed in the Packages.cd file or in
  155. /var/lib/dpkg/available) and rerun the installation, or upgrade the
  156. package by using `dpkg --install --auto-deconfigure'\'' by hand.
  157. ";
  158. exit(1);
  159. }
  160. print "$print\n";
  161. push(@invoke,$invoke);
  162. }
  163. print "Running dpkg -iB for $package ...\n";
  164. exec("dpkg","-iB","--",@invoke);
  165. die "failed to exec dpkg: $!\n";
  166. ' -- "$p_mountpoint$p_hierbase" "$predep" "$thisdisk"
  167. done
  168. perl -e '
  169. $SIG{INT} = sub { cd $vardir; unlink <tmp/*>; exit 1; };
  170. $| = 1;
  171. my ($vardir, $mountpoint, $hierbase, $mount, $umount) = @ARGV;
  172. my $line;
  173. my $AVAIL = "$vardir/methods/multicd/available";
  174. my $STATUS = "$vardir/status";
  175. my %Installed, %Filename, %Medium;
  176. print "Get currently installed package versions...";
  177. open(IN, "$STATUS") or die "cannot open $STATUS: $!\n";
  178. $line = 0;
  179. { local $/ = "";
  180. while (<IN>) {
  181. my %status;
  182. my @pstat;
  183. $line++ % 20 or print ".";
  184. s/\n\s+/ /g;
  185. %status = ("", split /^(\S*?):\s*/m, $_);
  186. map { chomp $status{$_}; $status{$_} =~ s/^\s*(.*?)\s*$/$1/;} keys %status;
  187. @pstat = split(/ /, $status{Status});
  188. next unless ($pstat[0] eq "install");
  189. if ($pstat[2] eq "config-files" || $pstat[2] eq "not-installed") {
  190. $Installed{$status{Package}} = "0.0";
  191. } else {
  192. $Installed{$status{Package}} = $status{Version} || "" ;
  193. }
  194. }; }
  195. print "\nGot ", scalar keys %Installed, " installed/pending packages\n";
  196. print "Scanning available packages...";
  197. $line = 0;
  198. open(IN, "$AVAIL") or die("Cannot open $AVAIL: $!\n");
  199. { local $/ = "";
  200. while (<IN>) {
  201. my $updated;
  202. $line++ % 20 or print ".";
  203. s/\n\s+/ /g;
  204. %avail = ("", split /^(\S*?):\s*/m, $_);
  205. map { chomp $avail{$_}; $avail{$_} =~ s/^\s*(.*?)\s*$/$1/;} keys %avail;
  206. next unless defined $Installed{$avail{Package}};
  207. system "dpkg", "--compare-versions", $avail{Version}, "gt", $Installed{$avail{Package}};
  208. $updated = ($? == 0);
  209. #print "$avail{Package}(" . ($updated ? "+" : "=") . ") ";
  210. $updated or next;
  211. $Filename{$avail{Package}} = $avail{Filename};
  212. next unless defined $avail{"X-Medium"};
  213. ${Medium{$avail{"X-Medium"}}} or ${Medium{$avail{"X-Medium"}}} = [];
  214. push @{${Medium{$avail{"X-Medium"}}}}, $avail{Package};
  215. }; };
  216. print "\n";
  217. if (@_ = keys(%Medium)) {
  218. print "You will need the following distribution disc(s):\n",
  219. join (", ", @_), "\n";
  220. }
  221. foreach $need (sort @_) {
  222. if (-r "$mountpoint/.disk/info") {
  223. open(IN, "$mountpoint/.disk/info") or die("$mountpoint/.disk/info: $!\n");
  224. } else {
  225. open(IN, "$mountpoint/$hierbase/.disk/info") or die("$mountpoint/$hierbase/.disk/info: $!\n");
  226. }
  227. $disk = <IN>; chomp $disk; close(IN);
  228. print "Processing disc\n $need\n";
  229. while ($disk ne $need) {
  230. print "Wrong disc. This is disc\n $disk\n";
  231. print "However, I need disc\n $need\n";
  232. print "Please change the discs and press <RETURN>\n";
  233. system($umount);
  234. <STDIN>;
  235. system($mount);
  236. $? and warn("cannot mount $mount\n");
  237. } continue {
  238. if (-r "$mountpoint/.disk/info") {
  239. open(IN, "$mountpoint/.disk/info") or die("$mountpoint/.disk/info: $!\n");
  240. } else {
  241. open(IN, "$mountpoint/$hierbase/.disk/info") or die("$mountpoint/$hierbase/.disk/info: $!\n");
  242. }
  243. $disk = <IN>; chomp $disk; close(IN);
  244. }
  245. -d "tmp" || mkdir "tmp", 0755 or die("Cannot mkdir tmp: $!\n");
  246. unlink <tmp/*>;
  247. print "creating symlinks...\n";
  248. foreach (@{$Medium{$need}}) {
  249. ($basename = $Filename{$_}) =~ s/.*\///;
  250. symlink "$mountpoint/$hierbase/$Filename{$_}",
  251. "tmp/$basename";
  252. }
  253. chdir "tmp" or die "cannot chdir to tmp: $!\n";
  254. system "dpkg", "-iGROEB", ".";
  255. unlink <*>;
  256. chdir "..";
  257. if ($?) {
  258. print "\nThe dpkg run produced errors. Please tell me, if I should\n",
  259. "continue with the next CD. [Y/n]: ";
  260. $ans = <STDIN>;
  261. exit 1 if $ans =~ /^n/i;
  262. $ouch = $?;
  263. }
  264. }
  265. exit $ouch;
  266. ' "$vardir" "$p_mountpoint" "$p_hierbase" "`do_mount`" "`do_umount`"
  267. echo -n 'Installation OK. Hit RETURN. '
  268. read response
  269. xit=0