Plan 9 from Bell Labs’s /usr/web/sources/patch/sorry/install-added-venti/mountdist.orig

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc

# We don't support ext2 because I'm not motivated enough
# to convert ext2srv, a server that only half works to begin with,
# to 9P2000.  If someone else wants to update ext2srv, I'll be happy
# to put back support for installing from ext2 partitions back.
#			- rsc

# prereq: mountfs configdist
# desc: locate and mount the distribution

fn domount{
	if(! test -e $mountmedia(2))
		logprog $srvmedia
	unmount /n/distmedia >[2]/dev/null
	logprog $mountmedia
}

fn exitifdone{
	if(test -f /n/dist/dist/replica/plan9.db)
		exit
}

fn trycdimage{
	if(test -f $1){
		rm -f /srv/9660.dist
		unmount /n/dist
		9660srv 9660.dist >[2]/dev/null
		logprog mount /srv/9660.dist /n/dist $1
		exitifdone
		mountdist=notdone
		export mountdist
		exit notdone
	}
}

fn trycdimagebz2 {
	if(test -f $1){
		echo -n 'bunzip2 < '^$1^' >/n/kfs/dist/plan9.iso'
		bunzip2 < $1 >/n/kfs/dist/_plan9.iso &&
		mv /n/kfs/dist/_plan9.iso /n/kfs/dist/plan9.iso
		echo
		trycdimage /n/kfs/dist/plan9.iso
		mountdist=notdone
		export mountdist
		exit notdone
	}
}

fn havedist {
	test -f $1/dist/replica/plan9.db ||
	test -f $1/plan9.iso ||
	test -f $1/plan9.iso.bz2
}

switch($1){
case checkready
	if(! ~ $distisfrom local && ! ~ $download done){
		mountdist=notdone
		export mountdist
	}
	if(! ~ $#mountmedia 0 1){
		if(domount){
			mountdist=done
			export mountdist
			if(mountdist checkdone)
				exit
		}
		srvmedia=()
		mountmedia=()
		mountdist=ready
		export srvmedia mountmedia mountdist
	}
		
case go
	kfs=()
	ext2=()
	fat=()
	x9660=()

	echo Please wait... Scanning storage devices...

	parts=`{ls /dev/sd??/* >[2]/dev/null | grep -v '/(plan9.*|ctl|log|raw)$'}
	for (i in $parts) {
		echo -n '	'^$i
		n=`{echo $i | sed 's;/;_;g'}
		if(! test -f /tmp/localpart.$n)
			dd -if $i -bs 2048 -count 32 -of /tmp/localpart.$n >[2]/dev/null
		if(iskfs /tmp/localpart.$n)
			kfs=($kfs $i)
		if(isfat /tmp/localpart.$n)
			fat=($fat $i)
	#	if(isext2 /tmp/localpart.$n)
	#		ext2=($ext2 $i)
		if(is9660 /tmp/localpart.$n)
			x9660=($x9660 $i)
		echo
	}
	echo
	echo The following storage media were detected.
	echo Choose the one containing the distribution.
	echo
	for(i in $parts){
		switch($i){
		case $kfs
			echo	'	'^$i^' (plan9 kfs)'
	#	case $ext2
	#		echo '	'^$i^' (linux ext2)'
		case $fat
			echo '	'^$i^' (microsoft fat)'
		case $x9660
			echo '	'^$i^' (iso9660 cdrom)'
		}
	}
	echo

	mountstatus=x
	while(! ~ $mountstatus ''){
		prompt -w '' 'Distribution disk' $kfs $fat $x9660 #$ext2
		disk=$rd

		srvmedia=()
		mountmedia=()
		switch($disk){
		case $fs
			mountmedia=(bind /n/kfs /n/distmedia)
		case $kfs
			kname=`{kfsname $disk}
			srvmedia=(disk/kfs -f $disk -n $kname)
			mountmedia=(mount /srv/kfs.$kname /n/distmedia)
	#	case $ext2
	#		srvmedia=(ext2srv -r)
	#		mountmedia=(mount /srv/ext2 /n/distmedia $disk)
		case $fat
			srvmedia=(dossrv)
			mountmedia=(mount /srv/dos /n/distmedia $disk)
		case $x9660
			srvmedia=(9660srv)
			mountmedia=(mount /srv/9660 /n/distmedia $disk)
		case *
			echo Unknown disk type '(cannot happen)'
			exit oops
		}
		export srvmedia mountmedia
		domount
		mountstatus=$status
	}

	first=yes
	dir=/
	while(~ $first yes || ! havedist /n/distmedia/$dir){
		if(~ $first yes){
			echo
			echo Which directory contains the distribution?
			echo 'Any of the following will suffice (in order of preference):'
			echo '	- the root directory of the cd image'
			echo '	- the directory containing plan9.iso'
			echo '	- the directory containing plan9.iso.bz2'
			echo 'Typing `browse'' will put you in a shell that you can use to'
			echo 'look for the directory.'
			echo
			first=no
		}

		prompt -d browse 'Location of archives'
		dir=$rd
		if(~ $dir browse){
			echo This is a simple shell.  Commands are:
			echo '	cd directory	- change to directory'
			echo '	lc				- list contents of current directory'
			echo '	exit			- exit shell'
			echo 
			echo 'Move to the directory containing the distribution'
			echo 'and then exit.'
			echo
			oifs=$ifs
			ifs=$nl
			dir=`{cdsh -r /n/distmedia}
			ifs=$oifs
		}
		if(~ $#dir 0)
			dir=safdsfdsfdsf
		if(! ~ $#dir 1)
			dir=$"dir
		if(! havedist /n/distmedia/$dir)
			echo 'No distribution found in '^`{cleanname /$dir}
	}
	distmediadir=$dir
	export distmediadir

case checkdone
	if(! ~ $#distmediadir 1){
		mountdist=notdone
		export mountdist
		exit notdone
	}
	if(! havedist /n/distmedia/$distmediadir && ! havedist /n/kfs/dist){
		mountdist=notdone
		export mountdist
		exit notdone
	}

	exitifdone

	if(test -f /n/distmedia/$distmediadir/dist/replica/plan9.db){
		bind /n/distmedia/$distmediadir /n/dist
		exitifdone
		mountdist=notdone
		export mountdist
		exit notdone
	}

	trycdimage /n/distmedia/$distmediadir/plan9.iso
	trycdimage /n/kfs/dist/plan9.iso

	trycdimagebz2 /n/distmedia/$distmediadir/plan9.iso.bz2
	trycdimagebz2 /n/kfs/dist/plan9.iso.bz2

	mountdist=notdone
	export mountdist
	exit notdone
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.