aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/fossil/conf.rc
blob: d3f69005a416c9d5b6a3628a6eb4bfe29b3ec73a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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