apply 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/rc
  2. rfork e
  3. if(! ~ $#* 1){
  4. echo 'usage: patch/apply patch-name' >[1=2]
  5. exit usage
  6. }
  7. if(! test -d /n/sources/patch){
  8. rfork n
  9. 9fs sources
  10. }
  11. if(! test -d /n/sources/patch/$1){
  12. echo 'no such patch' /n/sources/patch/$1 >[1=2]
  13. exit nopatch
  14. }
  15. cd /n/sources/patch/$1 || exit nopatch
  16. if(! patch/okay .){
  17. echo 'bad patch: '$status >[1=2]
  18. exit badpatch
  19. }
  20. if(! echo >.tmp || ! rm .tmp){
  21. echo no write permission >[1=2]
  22. exit 'no write permission'
  23. }
  24. echo -n merge... >[1=2]
  25. fn xxx {
  26. if(! test -f $1)
  27. cp $2 $2.new
  28. if not
  29. ape/diff3 -m $1 $2.orig $2 >$2.new
  30. if(grep -s '^<<<<' $2.new){
  31. echo conflicts merging $1';' see $d/$2.new >[1=2]
  32. touch failed
  33. }
  34. }
  35. rm -f failed
  36. cat files | sed 's/^/xxx /' | rc
  37. if(test -f failed){
  38. echo exiting without changes >[1=2]
  39. exit failed
  40. }
  41. echo -n backup... >[1=2]
  42. fn xxx {
  43. # echo cp $1 $2.backup
  44. cp $1 $2.backup
  45. }
  46. cat files | sed 's/^/xxx /' |rc
  47. echo -n copy... >[1=2]
  48. fn xxx {
  49. # echo cp $2.new $1
  50. cp $2.new $1 || touch failed
  51. }
  52. cat files | sed 's/^/xxx /' | rc
  53. fn xxx {
  54. # echo cp $2.backup $1
  55. cp $2.backup $1
  56. }
  57. if(test -f failed){
  58. echo copying failed, restoring backups >[1=2]
  59. cat files | sed 's/^/xxx /' | rc
  60. exit failed
  61. }
  62. echo >[1=2]
  63. echo to update sources: >[1=2]
  64. cat files | awk '{print " update " $1 }' >[1=2]