create 1.1 KB

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