create 1.5 KB

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