diff options
author | cinap_lenrek <cinap_lenrek@localhost> | 2011-04-12 15:53:55 +0000 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@localhost> | 2011-04-12 15:53:55 +0000 |
commit | 67e93d6a0a4f15192638e131413b9d64c4269c76 (patch) | |
tree | 88fd1d17c4be283683a96ced44159e3ce6b6f2f7 /rc/bin/inst/defs | |
parent | 7208d528bd42f981f2535403f72e4c0d7d8df643 (diff) |
updating cwfs and moving installer in /rc/bin
Diffstat (limited to 'rc/bin/inst/defs')
-rwxr-xr-x | rc/bin/inst/defs | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/rc/bin/inst/defs b/rc/bin/inst/defs new file mode 100755 index 000000000..f9c9454c0 --- /dev/null +++ b/rc/bin/inst/defs @@ -0,0 +1,162 @@ +nl=' +' +tab=' ' +if(~ $#distname 0) + distname=plan9 + +wctl=/dev/null +if(test -w /dev/wctl) + wctl=/dev/wctl + +fn log { + echo $* >>/srv/log +} + +fn logprog { + echo '% '^$"* >>/srv/log + $* >[2=1] >>/srv/log +} + +fn sigint { + # nothing happens +} + +fn prompt { + def=() + what=() + if(~ $1 -d && ! ~ $#* 1){ + def=$2 + shift + shift + } + + optstr=() + if(~ $1 -w && ! ~ $#* 1){ + optstr=$2 + shift + shift + } + + pr=$1 + shift + + opts=($*) + if(~ $#opts 0) { + suf=' ' + } + if not if(! ~ $#optstr 0) { + if(~ $optstr '') + suf=' ' + if not { + pr=$pr^' ('^$"optstr^')' + suf='' + } + } + if not { + pr=$pr^' ('^$1 + shift + for(i) + pr=$pr^', '^$i + pr=$pr^')' + suf='' + } + + if(~ $#def 1) + pr=$pr^$suf^'['^$def^']' + if not + pr=$pr^$suf^'[no default]' + + pr=$pr^': ' + + + okay=no + while(~ $okay no) { + echo -n current >$wctl + echo -n top >$wctl + echo -n $pr >[1=2] + ifs='' {rd=`{read}} + if(~ $#rd 0) + exit notdone + if(~ $rd !*){ + ifs='' {rd=`{echo $rd | sed 's/!//'}} + echo $rd + rc -c $rd + echo !$status + } + if not{ + rd=`{echo $rd} + if(~ $#rd 0 || ~ $rd '') + rd=$def + + switch($#opts){ + case 0 + if(! ~ $rd '') + okay=yes + case * + if(~ $rd $opts) + okay=yes + } + } + } + echo -n $rd >/env/rd # just in case +} + +fn desc { + echo -n ' '^$1^' - ' + grep '^# desc: ' $1 | sed 's/# desc: //' +} + +fn prereq { + grep '^# prereq:' $1 | sed 's/# prereq://' +} + +fn mustdo { + echo You must `{grep '^# mustdo:' $1 | sed 's/# mustdo://'} +} + +# there's no easy way to pass shell variables +# up from children to parents; the parents have +# to be coerced into noticing that the environment +# changed, even when in the same environment group. +# +# instead, we explicitly export the variables we want +# to percolate, and the parent calls coherence to reread +# the variables. +# +# we just append to the vars file, so that later exports +# override earlier ones; when we call coherence, +# the duplicates are thrown out. + +fn export { + null=() + nonnull=() + for(i in $*){ + if(~ $#$i 0) + null=($null $i) + if not + nonnull=($nonnull $i) + } + if(! ~ $#nonnull 0) + whatis $nonnull |grep -v '^\./' >>/tmp/vars >[2]/dev/null + for(i in $null) + echo $i^'=()' >>/tmp/vars +} + +fn coherence { + if(test -f /tmp/vars) { + grep '^[a-z]*=' /tmp/vars >/tmp/vars2 + v=`{sed 's/^([a-z]*)=.*/\1/' /tmp/vars2 | sort -u} + . /tmp/vars2 + rm /tmp/vars2 + rm /tmp/vars + export $v + } +} + +# ip device stats + +fn isipdevup { + grep -s $1 /net/ipifc/*/status >[2]/dev/null +} + + |