aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/fossil
diff options
context:
space:
mode:
authorDavid du Colombier <0intro@gmail.com>2013-09-26 22:31:57 +0200
committerDavid du Colombier <0intro@gmail.com>2013-09-26 22:31:57 +0200
commit68beda214434efb1da90b556df395e2cbf7bc787 (patch)
tree616fb8185dfcc99282a24fe78948cb982481f098 /src/cmd/fossil
parent3fcc209df911ca39a2c218fdacdd92eefb5ab281 (diff)
downloadplan9port-68beda214434efb1da90b556df395e2cbf7bc787.tar.gz
plan9port-68beda214434efb1da90b556df395e2cbf7bc787.tar.bz2
plan9port-68beda214434efb1da90b556df395e2cbf7bc787.zip
fossil: import conf.rc
R=rsc https://codereview.appspot.com/13983043
Diffstat (limited to 'src/cmd/fossil')
-rwxr-xr-xsrc/cmd/fossil/conf.rc68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/cmd/fossil/conf.rc b/src/cmd/fossil/conf.rc
new file mode 100755
index 00000000..d3f69005
--- /dev/null
+++ b/src/cmd/fossil/conf.rc
@@ -0,0 +1,68 @@
+#!/usr/local/plan9/bin/rc
+
+# the fossil configuration is stored at the 127kB offset in the disk
+# and extends for at most 1 kB.
+
+rfork e
+fn usage {
+ echo 'usage: fossil/conf [-w] /dev/sdC0/fossil [config]' >[1=2]
+ exit usage
+}
+
+wflag=no
+while(! ~ $#* 0 && ~ $1 -* && ! ~ $1 --){
+ switch($1){
+ case -w
+ wflag=yes
+ case *
+ usage
+ }
+ shift
+}
+if(~ $1 --)
+ shift
+
+if(~ $wflag no && ! ~ $#* 1)
+ usage
+if(~ $wflag yes && ! ~ $#* 1 2)
+ usage
+
+disk=$1
+if(! 9 test -f $disk){
+ echo 'unknown disk' $1 >[1=2]
+ exit nodisk
+}
+
+fn sigexit {
+ rm -f /tmp/fossilconf.$pid
+}
+
+if(~ $wflag yes){
+ {echo fossil config; cat $2} >/tmp/fossilconf.$pid || exit oops
+ if(! 9 test -s /tmp/fossilconf.$pid){
+ echo 'config is empty; will not install' >[1=2]
+ exit emptyconfig
+ }
+ if(9 test `{9 ls -l /tmp/fossilconf.$pid | awk '{print $6}'} -gt 1024){
+ echo 'config is too long; max is a little less than a kilobyte' >[1=2]
+ exit toolong
+ }
+ 9 dd -quiet 1 -bs 1024 -count 1 -if $disk -iseek 127 \
+ >/tmp/_fossilconf.old || exit backup
+ 9 dd -quiet 1 -count 2 </dev/zero >>/tmp/fossilconf.$pid || exit dd
+ 9 dd -quiet 1 -bs 1024 -count 1 -if /tmp/fossilconf.$pid \
+ -trunc 0 -of $disk -oseek 127 || exit dd2
+ exit 0
+}
+
+9 dd -quiet 1 -bs 1024 -count 1 -if $disk -iseek 127 |
+ zerotrunc >/tmp/fossilconf.$pid
+
+if(! cmp -s <{sed 1q /tmp/fossilconf.$pid} <{echo fossil config}){
+ echo 'config has bad header' >[1=2]
+ exit badconfig
+}
+
+sed 1d /tmp/fossilconf.$pid
+exit 0
+