apply 1.2 KB

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