disk = sdC0 fstype = fossil #| fossil+venti mbr = yes fossilp = /dev/$disk/fossil fossilsrv = installer fscons = /srv/fs^$fossilsrv^cons dist = /n/distmedia distdir = dist distisfrom=local #| net installurl = http://10.0.0.1 ventiarena = (/dev/$disk/arenas) ventiindex = (/dev/$disk/isect) ventireformat = yes fat = /dev/$disk/9fat bootfile = $disk!9fat!9pcf bootargs = 'local!#S'^/$disk/fossil bootdisk = $bootargs venti = '#S'^/$disk/arenas monitor=vesa vgasize=1280x1024x32 fn hasmbr { x=`{xd -b $1 | sed -n '32p;32q'} ~ $x(16) 55 && ~ $x(17) aa } fn dombr { if(~ mbr yes && ! hasmbr /dev/$disk/data) disk/mbr -m /386/mbr /dev/$disk/data } fn partdisk { disk/fdisk -a /dev/$disk/data disk/fdisk -p /dev/$disk/data >/dev/$disk/ctl >[2]/dev/null for(i in /dev/sd*/plan9*){ if(test -f $i){ d=`{basename -d $i} disk/prep -p $i >$d/ctl >[2]/dev/null } } } fn diskparted { mbrandplan9=0 disks=`{ls /dev/sd*/plan9 >[2]/dev/null | sed 's!/dev/(sd..)/plan9!\1!'} for(disk in $disks) { if(hasmbr /dev/$disk/data) mbrandplan9=1 if(~ $mbrandplan9 0) status='disk not partitioned' } fn autotype { if(~ $fstype fossil) echo -a 9fat -a nvram -a fossil -a swap if(~ $fstype fossil+venti) echo -a 9fat -a nvram -a arenas -a isect -a fossil -a swap # -a other } fn prepdisk { disk/prep `{autotype} $disk disk/prep -p $disk >`{basename -d $disk}^/ctl >[2]/dev/null } fn diskprepped { if(! test -f /dev/$disk/9fat) prepdisk=ready if(! ~ $prepdisk ready){ prepdisk=done switch($fstype){ case fossil if(! test -f /dev/$disk/fossil* && ! test -f /dev/fs/fossil*) prepdisk=ready case fossil+venti if(! test -f /dev/$disk/fossil* && ! test -f /dev/fs/fossil*) prepdisk=ready if(! test -f /dev/$disk/arenas && ! test -f /dev/fs/arenas*) prepdisk=ready if(! test -f /dev/$disk/isect && ! test -f /dev/fs/isect*) prepdisk=ready } } if(! ~ $prepdisk ready) status='disk not prepped' } fn fmtfossil { fossil/flfmt -y $fossilp n=`{cat /dev/swap | grep ' user' | sed 's/^[0-9]+\/([0-9]+) .*/\1/'} if(test $n -gt 32768) m=3000 # if have at least 128 user MB, use 24MB for fossil if not if(test $n -gt 16384) m=1500 # 64 user MB => 12MB for fossil if not if(test $n -gt 8192) m=750 # 32 user MB => 6MB for fossil if not m=256 # 2MB for fossil (this will be slow) # if we're using a venti in the back, take hourly snapshots # that retire after three days, in addition to the daily dumps at 5am if(~ $fstype fossil+venti){ v='' snap='fsys main snaptime -s 60 -a 0500 -t 2880' } # otherwise, take the daily dumps but nothing else -- # we can't retire snapshots unless dumps are being archived if not{ v='-V' snap='' } echo \ 'fsys main config '^$fossilp^' fsys main open '^$v^' -c '^$m^' '^$snap^' ' | fossil/conf -w } fn isfossil { if(! cmp -s <{dd -quiet 1 -if $fossilp -bs 1024 -iseek 127 | dd -quiet 1 -bs 14 -count 1} <{echo 'fossil config'}) status='no config' if not if(! cmp -s <{dd -quiet 1 -if $arg -bs 1024 -iseek 128 | dd -quiet 1 -bs 4 -count 1 | xd -b | sed 1q} <{echo '0000000 37 76 ae 89'}) status='not write buffer' } fn run_fossil { echo 'srv -p fs'^$1^'cons' > /env/fossi.$1.conf echo 'srv fossil.'^$1 > /env/fossi.$1.conf echo 'fsys main config '^$disk >> /env/fossil.$1.conf echo 'fsys main open -AWVP' >> /env/fossil.$1.conf echo 'fsys main' >> /env/fossil.$1.conf fossil/fossil -c '. /env/fossil.'^$1.conf mount fossil.$1 /n/$1 } fn initialise_newfs { if(! test -s /n/newfs/adm/users){ echo fsys main create /active/adm adm sys d775 >>$fscons echo fsys main create /active/adm/users adm sys 664 >>$fscons echo uname upas :upas >>$fscons echo users -w >>$fscons sleep 2 } if(! test -s /n/newfs/adm/users){ status = 'could not create /adm/users' exit oops } for(i in dist dist/replica dist/replica/client){ if(! test -d /n/newfs/$i) echo fsys main create /active/$i sys sys d775 >>$fscons sleep 2 } if(! test -d /n/newfs/dist/replica/client){ status = 'could not create /dist/replica/client' exit oops } if(! test -e /n/newfs/dist/replica/client/plan9.db){ echo fsys main create /active/dist/replica/client/plan9.db sys sys 664 >>$fscons echo fsys main create /active/dist/replica/client/plan9.log sys sys a664 >>$fscons } if(test -d /n/newfs/dist/replica/client && test -f /n/newfs/adm/users){ status = '' exit } status = '/n/newfs/dist/replica/client or /n/newfs/adm/users missing' exit oops } fn havedist { if(!(test -f $dist/$distdir/replica/plan9.db || test -f $dist/plan9.iso || test -f $dist/plan9.iso.bz2)) { status = 'No distribution found in '^$dist ' or '^$dist/$distdir exit } if(test -f $dist/$distdir/dist/replica/plan9.db) { bind $dist/$distdir $dist bind -a $dist/386/bin /bin bind -a $dist/rc/bin /bin } } fn isventi { if(cmp -s <{dd -quiet 1 -if $arg -bs 1024 -iseek 248 | dd -quiet 1 -bs 13 -count 1} <{echo 'venti config'}) exit status = 'no venti config' exit oops } fn fmtventi { gg=() for(f in $ventiarena) if(! isventi $f) gg=($gg $f) if(! ~ $#gg 0) { status = 'not venti partition : ('^$"gg^')' exit oops } n=-1 fmta=() for(a in $ventiarena){ n=`{hoc -e 1+$n} if(isventiarenas $a) { if(~ $ventireformat yes) fmta=($fmta arenas$n:$a) } if not fmta=($fmta arenas$n:$a) } n=-1 fmti=() for(a in $ventiindex) { n=`{hoc -e 1+$n} if(isventiisect $a) { if(~ $ventireformat yes) fmti=($fmti isect$n:$a) } if not fmti=($fmti isect$n:$a) } echo Formatting Venti arenas and indices (this takes a while). # do each disk in parallel echo good >/tmp/fmt dd=() for(a in $fmta $fmti){ d=`{echo $a | sed 's!.*:(/.*/).*!\1!'} if(! ~ $d $dd) dd=($dd $d) } for(d in $dd){ { for(a in $fmta){ i=`{echo $a | sed 's!(.*):(/.*/)(.*)!\1 \2 \2\3!'} if(~ $i(2) $d){ echo $i(3) ... venti/fmtarenas $i(1) $i(3) || echo bad >/tmp/fmt echo done with $i(3) } } for(a in $fmti){ i=`{echo $a | sed 's!(.*):(/.*/)(.*)!\1 \2 \2\3!'} if(~ $i(2) $d){ echo $i(3) ... venti/fmtisect $i(1) $i(3) || echo bad >/tmp/fmt echo done with $i(3) } } } & } wait if(~ bad `{cat /tmp/fmt}){ status = 'There were errors formatting the indices and arenas.' exit oops } echo Done formatting Venti arenas and indices. v=$ventiarena(1) echo Storing Venti config on $v... { echo index main for(i in $ventiindex) echo isect $i for(a in $ventiarena) echo arenas $a } | venti/conf -w $v echo Initializing index... venti/fmtindex $v echo Done with Venti! } fn download { baropt='-w 145,129,445,168' if(! hget -vo /n/newfs/dist/_plan9.iso.bz2 $installurl/plan9.iso.bz2 |[2] bargraph $baropt 'downloading '^plan9.iso.bz2) exit mv /n/newfs/dist/_plan9.iso.bz2 /n/newfs/dist/plan9.iso.bz2 if(~ $fstype fossil){ echo fsys main sync >>$fscons } if(test -f /n/newfs/dist/plan9.iso.bz2) { mount /srv/$fossilsrv $dist distmediadir=/dist } if not { status = 'download failed' } } fn copydist { if(! test -d /n/dist/dist/replica) { status = 'missing dist/replica' exit } inst/watchfd applylog 0 `{ls -l /n/dist/dist/replica/plan9.log | awk '{print $6}'} 'Installing file system' & replica/pull -c / /rc/bin/inst/replcfg if(~ $status '' *conflicts || test -f /n/newfs/dist/replica/didplan9witherrors) >/n/newfs/dist/replica/didplan9 if not >/n/newfs/dist/replica/didplan9witherrors if(! test -f /n/newfs/dist/replica/didplan9){ status = 'copydist failed' } } fn add_plan9ini { { echo bootfile'='$bootfile echo bootargs'='$bootargs echo bootdisk'='$bootdisk echo venti'='$venti echo monitor'='$monitor echo vgasize'='$vgasize echo mouseport'='$mouseport } >/tmp/plan9.ini } fn init_9fat { if(! test -f $fat) { status = 'You have no 9fat partition. Can''t setup booting.' exit } if(! test -f /tmp/plan9.ini) add_plan9ini need9fatformat=no if(! isfat $fat) need9fatformat=yes if not if(! mount -c /srv/dos /n/9fat $fat >[2]/dev/null) need9fatformat=yes if not if(! test -f /n/9fat/plan9.ini) need9fatformat=yes if(~ $need9fatformat yes){ echo Initializing Plan 9 FAT partition. disk/format -r 2 -d -b /386/pbs $fat /n/newfs/386/9load # silently install pbslba if the partition is way into the disk. # it''s our only hope. only need this for >8.5GB into the disk. # but... # there are so few non-LBA bioses out # there anymore that we'll do this even if we're only 2GB into # the disk. it's just not worth the headaches of dealing with # crappy bioses that don't address the whole 8.5GB properly 9fatoffset=`{grep '^part 9fat ' /dev/$disk/ctl | awk '{print $4}'} if(! ~ $#9fatoffset 1) { status = 'could not find plan 9 partition.' exit bad } if(test $9fatoffset -gt 2097152) # 2GB disk/format -b /386/pbslba $fat mount -c /srv/dos /n/9fat $fat } if(! test -f /n/9fat/4e){ cp /n/newfs/386/9load /n/9fat/9load cp /n/newfs/386/9pcf /n/9fat/9pcf if(test -f /n/9fat/plan9.ini && ! test -f /n/9fat/plan9-3e.ini) mv /n/9fat/plan9.ini /n/9fat/plan9-3e.ini if(test -f /n/9fat/9pcdisk && ! test -f /n/9fat/9pc3e) mv /n/9fat/9pcdisk /n/9fat/9pc3e awk -f /bin/inst/mkini.awk >/n/9fat/plan9.ini >/n/9fat/4e } } fn bootplan9 { first=`{ls -p '#S' | sed 1q} if(! ~ $first $disk) { echo 'warning: The plan 9 partition is not on the boot disk,' echo 'so making it the active partition will have no effect.' } p9offset=`{grep '^part 9fat ' /dev/$disk/ctl |awk '{print $3}'} if(! ~ $#p9offset 1) { echo 'could not find plan 9 partition.' echo 'cannot happen' exit bad } dombr echo Setting Plan 9 partition active. p9part=`{disk/fdisk /dev/$disk/data >[2]/dev/null [1=2] exit 'no plan 9 partition found' } p9part=$p9part(1) { echo 'A '^$p9part; echo w } | disk/fdisk /dev/$disk/data >[2]/dev/null >/dev/null x=$status if(~ $x '' '|'){ echo echo 'The Plan 9 partition is now marked as active.' exit '' } exit $x } fn finish { echo -n 'Halting file systems...' if(ps | grep -s ' venti$') venti/sync -h tcp!127.0.0.1!17034 if(ps | grep -s ' fossil$'){ echo fsys all halt >>$fscons slay fossil|rc } }