xref: /plan9/386/bin/fossil/conf (revision 7512b2c7bb972f701446cdb318996935dd2f1cc7)
1#!/bin/rc
2# THIS FILE IS AUTOMATICALLY GENERATED
3# FROM /sys/src/cmd/fossil/conf.rc.  DO NOT EDIT.
4
5
6# the fossil configuration is stored at the 127kB offset in the disk
7# and extends for at most 1 kB.
8
9rfork e
10fn usage {
11	echo 'usage: fossil/conf [-w] /dev/sdC0/fossil [config]' >[1=2]
12	exit usage
13}
14
15wflag=no
16while(! ~ $#* 0 && ~ $1 -* && ! ~ $1 --){
17	switch($1){
18	case -w
19		wflag=yes
20	case *
21		usage
22	}
23	shift
24}
25if(~ $1 --)
26	shift
27
28if(~ $wflag no && ! ~ $#* 1)
29	usage
30if(~ $wflag yes && ! ~ $#* 1 2)
31	usage
32
33disk=$1
34if(! test -f $disk){
35	echo 'unknown disk' $1 >[1=2]
36	exit nodisk
37}
38
39fn sigexit {
40	rm -f /tmp/fossilconf.$pid
41}
42
43if(~ $wflag yes){
44	{echo fossil config; cat $2} >/tmp/fossilconf.$pid || exit oops
45	if(! test -s /tmp/fossilconf.$pid){
46		echo 'config is empty; will not install' >[1=2]
47		exit emptyconfig
48	}
49	if(test `{ls -l /tmp/fossilconf.$pid | awk '{print $6}'} -gt 1024){
50		echo 'config is too long; max is a little less than a kilobyte' >[1=2]
51		exit toolong
52	}
53	dd -quiet 1 -bs 1024 -count 1 -if $disk -iseek 127 \
54		>/tmp/_fossilconf.old || exit backup
55	dd -quiet 1 -count 2 </dev/zero >>/tmp/fossilconf.$pid || exit dd
56	dd -quiet 1 -bs 1024 -count 1 -if /tmp/fossilconf.$pid \
57		-trunc 0 -of $disk -oseek 127 || exit dd2
58	exit 0
59}
60
61dd -quiet 1 -bs 1024 -count 1 -if $disk -iseek 127 |
62	aux/zerotrunc >/tmp/fossilconf.$pid
63
64if(! cmp -s <{sed 1q /tmp/fossilconf.$pid} <{echo fossil config}){
65	echo 'config has bad header' >[1=2]
66	exit badconfig
67}
68
69sed 1d /tmp/fossilconf.$pid
70exit 0
71
72