create 1.4 KB

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