create 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. xchmod ug+rw $d/*
  62. xchmod a+r $d/*
  63. }
  64. if(~ `{cat /proc/$pid/fd | awk 'NR==2{print $NF}'} */dev/cons && test -w /dev/consctl){
  65. >/dev/consctl {
  66. echo holdon
  67. cat >$d/readme
  68. }
  69. }
  70. if not
  71. cat >$d/readme
  72. if(! test -s $d/readme){
  73. echo 'no description given; aborting' >[1=2]
  74. rm -rf $d
  75. exit oops
  76. }
  77. echo $d