summaryrefslogtreecommitdiff
path: root/patch/patch-update/update
blob: 6d7f2bf672006a514ed9b1a491572e50a5971ffb (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
#!/bin/rc -e

# patch/update -- update file(s) in patch

flagfmt=a
args='name file...'
if(! ifs=() eval `{aux/getflags $*} || test $#* -lt 2){
	aux/usage
	exit usage
}

if(! test -d /n/sources/patch){
	rfork n
	9fs sources
}

d=/n/sources/patch/$1
shift
if(! test -d $d){
	echo 'no such patch' $d >[1=2]
	exit nopatch
}

for(file in $*){
	src=`{cleanname -d `{pwd} $file}
	dst=`{awk '$1 == ENVIRON["src"] { print $2 }' $d/files}
	if (~ $dst ''){
		echo $src not found in $d/files -- wrong patch? >[1=2]
		exit 'nofile'
	}
	echo cp $src $d/$dst
	cp $src $d/$dst
	chmod ug+rw $d/$dst >[2]/dev/null
	chmod a+r $d/$dst >[2]/dev/null
}