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