#!/bin/rc # sysupgrade - upgrade the whole system # usage: sysupgrade [-ny] # requires: # - pkg (https://9p.sdf.org/who/bubstance/rc/pkginit.rc.txt) rfork en flagfmt='n:n, y:y' eval `''{aux/getflags $*} || exec aux/usage if(~ $n 1) ans=n if(~ $y 1) ans=y fn die{ >[1=2] echo !! $* >[1=2] echo !! exiting... exit $"* } fn fin{ say syncing filesystem... if(test -f /srv/cwfs.cmd) sync cwfs if not if(test -f /srv/hjfs.cmd) sync hjfs if not if(test -f /srv/gefs.cmd) sync gefs if not die failed to sync say system upgrade complete exit '' } fn mkdoc{ say rebuilding documentation... @{cd /sys/doc && mk clean && mk} || die failed to rebuild documentation say documentation successfully regenerated } fn mkman{ say rebuilding manpage indices... @{cd /sys/man && mk clean && mk} || die failed to rebuild manpages say manpages successfully regenerated } fn mknuke{ say cleaning existing libraries... @{cd /sys/src && mk nuke} || die failed to clean existing libraries } fn mkpkg{ say updating managed packages... pkg/up || die failed to update packages } fn say{ >[1=2] echo :: $* } fn sync{ switch($1){ case cwfs gefs hjfs >>/srv/$1.cmd echo sync || die failed to sync $1 case * die failed to sync $1 } } fn sighup sigint sigterm{ exit interrupt } # fetch available updates say updating system sources... sysupdate if(! test -d /lib/firmware/.git){ say cloning wireless firmware repository... @{cd /lib/firmware && git/clone gits://git.9front.org/plan9front/firmware .} || die failed to clone wireless firmware } if not{ say checking for new wireless firmware... @{cd /lib/firmware && git/pull} || die failed to fetch wireless firmware } say sources updated # check with user if(~ $#ans 0){ echo -n '|| continue and recompile? [y/N] ' switch(`{read}){ case [yY]* say beginning system upgrade... case * say exiting... exit '' } } if not if(~ $ans y) say beginning system upgrade... # create any missing directories say creating missing directories... @{cd / && . /sys/lib/rootstub} || die failed to create missing directories # build some components first say building assemblers and linkers... for(i in (9a 9l 8a 8l 7a 7l 6a 6l 5a 5l 2a 2l 1a 1l ka kl qa ql tl va vl)){ cd /sys/src/cmd/^$i && mk install } || die failed to build assemblers and linkers # check with user if(~ $#ans 0){ >[1=2] echo -n '|| clean existing libraries? [y/N] ' switch(`{read}){ case [yY]* mknuke case * say skipping... } } if not if(~ $ans y){ say cleaning existing libraries... @{cd /sys/src && mk nuke} || die failed to clean existing libraries } # build system say rebuilding system... @{cd /sys/src && mk install && mk clean} || die failed to rebuild system if(~ $#ans 0){ >[1=2] echo -n '|| rebuild managed packaged? [y/N] ' switch(`{read}){ case [yY]* mkpkg case * say skipping... } >[1=2] echo -n '|| rebuild manpages? [y/N] ' switch(`{read}){ case [yY]* mkman case * say skipping... } >[1=2] echo -n '|| rebuild documentation? [y/N] ' switch(`{read}){ case [yY]* mkdoc case * say skipping... } } if not if(~ $ans y){ mkpkg mkman #mkdoc } # build and install new kernel say building new kernel... switch($cputype){ case amd64 @{cd /sys/src/9/pc64 && mk install && mk clean} || die failed to build kernel say installing new bootloader and kernel... 9fs 9fat for(i in /n/9^('' fat)){ rm $i/9bootfat || die failed to remove old bootloader cp /386/9bootfat $i/ || die failed to copy new bootloader chmod +al $i/9bootfat || die failed to chmod new bootloader cp $i/9pc64 $i/9pc64.bak || die failed to create backup kernel cp /amd64/9pc64 $i/ || die failed to copy new kernel unmount $i } || die failed to install kernel say new bootloader and kernel successfully installed... case arm64 @{cd /sys/src/9/bcm64 && mk install && mk clean} || die failed to build kernel say installing new kernel... 9fs dos cp /arm64/^(9pi3 9pi4) /n/dos || die failed to copy new kernel say new kernel successfully installed... case * die failed to determine cputype } || exit fin