install 8.3 KB

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