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