install 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. #!/bin/sh
  2. # Copyright (C) 1995-98 Ian Jackson <ian@chiark.greenend.org.uk>
  3. # Copyright (C) 1998 Heiko Schlittermann <heiko@lotte.sax.de>
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; version 2 dated June, 1991.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  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-installation-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 /bin/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 /bin/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. length($package) || die "internal error - no package";
  103. @filename || die "internal error - no filename";
  104. @filename==@msdosfilename || !@filename || !@msdosfilename ||
  105. die "internal error - mismatch >@filename< >@msdosfilename<";
  106. if ($medium && ($medium ne $thisdisk)) {
  107. print "
  108. This is
  109. $thisdisk
  110. However, $package is expected on disc:
  111. $medium
  112. Please change the discs and press <RETURN>.
  113. ";
  114. exit(1);
  115. }
  116. @invoke=(); $|=1;
  117. for ($i=0; $i<=$#filename; $i++) {
  118. $ppart= $i+1;
  119. print "Looking for part $ppart of $package ... ";
  120. if (-f "$binaryprefix$filename[$i]") {
  121. $print= $filename[$i];
  122. $invoke= "$binaryprefix$filename[$i]";
  123. } elsif (-f "$binaryprefix$msdosfilename[$i]") {
  124. $print= $msdosfilename[$i];
  125. $invoke= "$binaryprefix$msdosfilename[$i]";
  126. } else {
  127. $base= $filename[$i]; $base =~ s,.*/,,;
  128. $msdosbase= $msdosfilename[$i]; $msdosbase =~ s,.*/,,;
  129. defined($c= open(X,"-|")) ||
  130. die "failed to fork for find: $!\n";
  131. if (!$c) {
  132. exec("find", length($binaryprefix)
  133. ? $binaryprefix : ".","-follow",
  134. "-name",$base,"-o","-name",$msdosbase);
  135. die "failed to exec find: $!\n";
  136. }
  137. while (chop($invoke= <X>)) { last if -f $invoke; }
  138. $print= $invoke;
  139. if (substr($print,0,length($binaryprefix)+1) eq
  140. "$binaryprefix/") {
  141. $print= substr($print,length($binaryprefix));
  142. }
  143. }
  144. if (!length($invoke)) {
  145. print STDERR "
  146. Oh dear, I need to install or upgrade $package, but I don'\''t see
  147. the appropriate file(s) anywhere. I'\''m expecting version $version or
  148. later, as that is listed in the Packages.cd file.
  149. Perhaps you downloaded it with an unexpected name, or something.
  150. In any case, you must find the file(s) and then either place it with
  151. the correct filename(s) (as listed in the Packages.cd file or in
  152. /var/lib/dpkg/available) and rerun the installation, or upgrade the
  153. package by using `dpkg --install --auto-deconfigure'\'' by hand.
  154. ";
  155. exit(1);
  156. }
  157. print "$print\n";
  158. push(@invoke,$invoke);
  159. }
  160. print "Running dpkg -iB for $package ...\n";
  161. exec("dpkg","-iB","--",@invoke);
  162. die "failed to exec dpkg: $!\n";
  163. ' -- "$p_mountpoint$p_hierbase" "$predep" "$thisdisk"
  164. done
  165. perl -e '
  166. $SIG{INT} = sub { cd $vardir; unlink <tmp/*>; exit 1; };
  167. $| = 1;
  168. my ($vardir, $mountpoint, $hierbase, $mount, $umount) = @ARGV;
  169. my $line;
  170. my $AVAIL = "$vardir/methods/multicd/available";
  171. my $STATUS = "$vardir/status";
  172. my %Installed, %Filename, %Medium;
  173. print "Get currently installed package versions...";
  174. open(IN, "$STATUS") or die "Cannot open $STATUS: $!\n";
  175. $line = 0;
  176. { local $/ = "";
  177. while (<IN>) {
  178. my %status;
  179. my @pstat;
  180. $line++ % 20 or print ".";
  181. s/\n\s+/ /g;
  182. %status = ("", split /^(\S*?):\s*/m, $_);
  183. map { chomp $status{$_}; $status{$_} =~ s/^\s*(.*?)\s*$/$1/;} keys %status;
  184. @pstat = split(/ /, $status{Status});
  185. next unless ($pstat[0] eq "install");
  186. if ($pstat[2] eq "config-files" || $pstat[2] eq "not-installed") {
  187. $Installed{$status{Package}} = "0.0";
  188. } else {
  189. $Installed{$status{Package}} = $status{Version} || "" ;
  190. }
  191. }; }
  192. print "\nGot ", scalar keys %Installed, " installed/pending packages\n";
  193. print "Scanning available packages...";
  194. $line = 0;
  195. open(IN, "$AVAIL") or die("Cannot open $AVAIL: $!\n");
  196. { local $/ = "";
  197. while (<IN>) {
  198. my $updated;
  199. $line++ % 20 or print ".";
  200. s/\n\s+/ /g;
  201. %avail = ("", split /^(\S*?):\s*/m, $_);
  202. map { chomp $avail{$_}; $avail{$_} =~ s/^\s*(.*?)\s*$/$1/;} keys %avail;
  203. next unless defined $Installed{$avail{Package}};
  204. system "dpkg", "--compare-versions", $avail{Version}, "gt", $Installed{$avail{Package}};
  205. $updated = ($? == 0);
  206. #print "$avail{Package}(" . ($updated ? "+" : "=") . ") ";
  207. $updated or next;
  208. $Filename{$avail{Package}} = $avail{Filename};
  209. next unless defined $avail{"X-Medium"};
  210. ${Medium{$avail{"X-Medium"}}} or ${Medium{$avail{"X-Medium"}}} = [];
  211. push @{${Medium{$avail{"X-Medium"}}}}, $avail{Package};
  212. }; };
  213. print "\n";
  214. if (@_ = keys(%Medium)) {
  215. print "You will need the following distribution disc(s):\n",
  216. join (", ", @_), "\n";
  217. }
  218. foreach $need (sort @_) {
  219. if (-r "$mountpoint/.disk/info") {
  220. open(IN, "$mountpoint/.disk/info") or die("$mountpoint/.disk/info: $!\n");
  221. } else {
  222. open(IN, "$mountpoint/$hierbase/.disk/info") or die("$mountpoint/$hierbase/.disk/info: $!\n");
  223. }
  224. $disk = <IN>; chomp $disk; close(IN);
  225. print "Processing disc\n $need\n";
  226. while ($disk ne $need) {
  227. print "Wrong disc. This is disc\n $disk\n";
  228. print "However, I need disc\n $need\n";
  229. print "Please change the discs and press <RETURN>\n";
  230. system($umount);
  231. <STDIN>;
  232. system($mount); $? and warn("Cannot mount $mount\n");
  233. } continue {
  234. if (-r "$mountpoint/.disk/info") {
  235. open(IN, "$mountpoint/.disk/info") or die("$mountpoint/.disk/info: $!\n");
  236. } else {
  237. open(IN, "$mountpoint/$hierbase/.disk/info") or die("$mountpoint/$hierbase/.disk/info: $!\n");
  238. }
  239. $disk = <IN>; chomp $disk; close(IN);
  240. }
  241. -d "tmp" || mkdir "tmp", 0755 or die("Cannot mkdir tmp: $!\n");
  242. unlink <tmp/*>;
  243. print "creating symlinks...\n";
  244. foreach (@{$Medium{$need}}) {
  245. ($basename = $Filename{$_}) =~ s/.*\///;
  246. symlink "$mountpoint/$hierbase/$Filename{$_}",
  247. "tmp/$basename";
  248. }
  249. chdir "tmp" or die "Cannot chdir to tmp: $!\n";
  250. system "dpkg", "-iGROEB", ".";
  251. unlink <*>;
  252. chdir "..";
  253. if ($?) {
  254. print "\nThe dpkg run produced errors. Please tell me, if I should\n",
  255. "continue with the next CD. [Y/n]: ";
  256. $ans = <STDIN>;
  257. exit 1 if $ans =~ /^n/i;
  258. $ouch = $?;
  259. }
  260. }
  261. exit $ouch;
  262. ' "$vardir" "$p_mountpoint" "$p_hierbase" "`do_mount`" "`do_umount`"
  263. echo -n 'Installation OK. Hit RETURN. '
  264. read response
  265. xit=0
  266. # vim:ts=4:sw=4:aw:ai: