Subversion Repositories planix.SVN

Rev

Rev 2 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/bin/rc

# 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/newfs/dist/plan9.iso'
                bunzip2 < $1 >/n/newfs/dist/_plan9.iso &&
                mv /n/newfs/dist/_plan9.iso /n/newfs/dist/plan9.iso
                echo
                trycdimage /n/newfs/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
        fat=()
        ext2=()
        x9660=()
        fossil=()

        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(isfat /tmp/localpart.$n)
                        fat=($fat $i)
                if(isext2 /tmp/localpart.$n)
                        ext2=($ext2 $i)
                if(is9660 /tmp/localpart.$n)
                        x9660=($x9660 $i)
                if(isfossil $i)
                        fossil=($fossil $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 $fat
                        echo    '       '^$i^' (microsoft fat)'
                case $ext2
                        echo    '       '^$i^' (linux ext2)'
                case $x9660
                        echo    '       '^$i^' (iso9660 cdrom)'
                case $fossil
                        echo    '       '^$i^' (plan9 fossil)'
                }
        }
        echo

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

                srvmedia=()
                mountmedia=()
                switch($disk){
                case $fs
                        mountmedia=(bind /n/newfs /n/distmedia)
                case $fat
                        srvmedia=(dossrv)
                        mountmedia=(mount /srv/dos /n/distmedia $disk)
                case $ext2
                        srvmedia=(ext2srv -r)
                        mountmedia=(mount /srv/ext2 /n/distmedia $disk)
                case $x9660
                        srvmedia=(9660srv)
                        mountmedia=(mount /srv/9660 /n/distmedia $disk)
                case $fossil
                        echo 'srv fossil.mountdist' > /tmp/fossi.conf
                        echo 'fsys main config '^$disk >> /tmp/fossil.conf
                        echo 'fsys main open -AWVP' >> /tmp/fossil.conf
                        echo 'fsys main' >> /tmp/fossil.conf
                        srvmedia=(fossil/fossil -c '. /tmp/fossil.conf')
                        mountmedia=(mount /srv/fossil.mountdist /n/distmedia)
                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/newfs/dist){
                mountdist=notdone
                export mountdist
                exit notdone
        }

        exitifdone

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

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

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

        mountdist=notdone
        export mountdist
        exit notdone
}