install 8.2 KB

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