xref: /plan9-contrib/rc/bin/patch/create (revision ec59a3ddbfceee0efe34584c2c9981a5e5ff1ec4)
1#!/bin/rc
2rfork e
3
4fn xchmod {
5	chmod $* >[2]/dev/null
6}
7
8if(~ $#* 0 1 2){
9	echo 'usage: patch/create name email file... [< description]' >[1=2]
10	exit usage
11}
12
13if(! echo $1 | grep -s '^[a-z_0-9.\-]+$'){
14	echo 'bad name: [a-z0-9._\-]+ only' >[1=2]
15	exit usage
16}
17if(! echo $2 | grep -s '^(-|[A-Za-z0-9.\-+]+@[A-Za-z0-9.\-+]+)$'){
18	echo 'bad email: [a-z0-9.-+] only; use ''-'' to not leave an email address.' >[1=2]
19	exit usage
20}
21
22if(! test -d /n/sources/patch){
23	rfork n
24	9fs sources
25}
26
27patch=$1
28email=$2
29shift
30shift
31d=/n/sources/patch/$patch
32if(! mkdir $d){
33	echo mkdir $d failed >[1=2]
34	exit mkdir
35}
36if(! ~ $email -){
37	echo $email >$d/email
38}
39
40xchmod o-w $d
41>$d/readme
42>$d/files
43>$d/notes
44for(i in $*){
45	i=`{cleanname -d `{pwd} $i}
46	if(! test -f $i){
47		echo error: cannot find $i >[1=2]
48		rm -rf $d
49		exit oops
50	}
51	short=`{basename $i}
52	uniq=$short
53	n=0
54	while(test -f $d/$uniq){
55		uniq=$short.$n
56		n=`{echo 1+$n | hoc}
57	}
58	cp $i $d/$uniq
59	if(test -f /n/sources/plan9/$i){
60		if(cmp -s /n/sources/plan9/$i $i)
61			echo warning: new file $i does not differ from sources >[1=2]
62		cp /n/sources/plan9/$i $d/$uniq.orig
63	}
64	if not
65		echo warning: new file $i not on sources >[1=2]
66	echo $i $uniq >>$d/files
67	xchmod ug+rw $d/*
68	xchmod a+r $d/*
69}
70
71if(~ `{cat /proc/$pid/fd | awk 'NR==2{print $NF}'} */dev/cons && test -w /dev/consctl){
72	>/dev/consctl {
73		echo holdon
74		cat >$d/readme
75	}
76}
77if not
78	cat >$d/readme
79
80if(! test -s $d/readme){
81	echo 'no description given; aborting' >[1=2]
82	rm -rf $d
83	exit oops
84}
85
86echo $d
87