/[gentoo-src]/rc-scripts/src/awk/cachedepends.awk
Gentoo

Diff of /rc-scripts/src/awk/cachedepends.awk

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.8 Revision 1.15
1# Copyright 1999-2003 Gentoo Technologies, Inc. 1# Copyright 1999-2003 Gentoo Technologies, Inc.
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# Author: Martin Schlemmer <azarah@gentoo.org> 3# Author: Martin Schlemmer <azarah@gentoo.org>
4# $Header: /var/cvsroot/gentoo-src/rc-scripts/src/awk/cachedepends.awk,v 1.8 2003/02/06 02:00:01 azarah Exp $ 4# $Header: /var/cvsroot/gentoo-src/rc-scripts/src/awk/cachedepends.awk,v 1.15 2004/02/26 17:29:43 azarah Exp $
5 5
6function print_start() { 6function print_start() {
7 print "source /sbin/functions.sh" >> (DEPCACHE) 7 print "source /sbin/functions.sh" >> (SVCDIR "/depcache")
8 print "" >> (DEPCACHE) 8 print "" >> (SVCDIR "/depcache")
9 print "need() {" >> (DEPCACHE) 9 print "need() {" >> (SVCDIR "/depcache")
10 print " echo \"NEED $*\"; return 0" >> (DEPCACHE) 10 print " echo \"NEED $*\"; return 0" >> (SVCDIR "/depcache")
11 print "}" >> (DEPCACHE) 11 print "}" >> (SVCDIR "/depcache")
12 print "" >> (DEPCACHE) 12 print "" >> (SVCDIR "/depcache")
13 print "use() {" >> (DEPCACHE) 13 print "use() {" >> (SVCDIR "/depcache")
14 print " echo \"USE $*\"; return 0" >> (DEPCACHE) 14 print " echo \"USE $*\"; return 0" >> (SVCDIR "/depcache")
15 print "}" >> (DEPCACHE) 15 print "}" >> (SVCDIR "/depcache")
16 print "" >> (DEPCACHE) 16 print "" >> (SVCDIR "/depcache")
17 print "before() {" >> (DEPCACHE) 17 print "before() {" >> (SVCDIR "/depcache")
18 print " echo \"BEFORE $*\"; return 0" >> (DEPCACHE) 18 print " echo \"BEFORE $*\"; return 0" >> (SVCDIR "/depcache")
19 print "}" >> (DEPCACHE) 19 print "}" >> (SVCDIR "/depcache")
20 print "" >> (DEPCACHE) 20 print "" >> (SVCDIR "/depcache")
21 print "after() {" >> (DEPCACHE) 21 print "after() {" >> (SVCDIR "/depcache")
22 print " echo \"AFTER $*\"; return 0" >> (DEPCACHE) 22 print " echo \"AFTER $*\"; return 0" >> (SVCDIR "/depcache")
23 print "}" >> (DEPCACHE) 23 print "}" >> (SVCDIR "/depcache")
24 print "" >> (DEPCACHE) 24 print "" >> (SVCDIR "/depcache")
25 print "provide() {" >> (DEPCACHE) 25 print "provide() {" >> (SVCDIR "/depcache")
26 print " echo \"PROVIDE $*\"; return 0" >> (DEPCACHE) 26 print " echo \"PROVIDE $*\"; return 0" >> (SVCDIR "/depcache")
27 print "}" >> (DEPCACHE) 27 print "}" >> (SVCDIR "/depcache")
28 print "" >> (DEPCACHE) 28 print "" >> (SVCDIR "/depcache")
29 print "parallel() {" >> (SVCDIR "/depcache")
30 print " echo \"PARALLEL $*\"; return 0" >> (SVCDIR "/depcache")
31 print "}" >> (SVCDIR "/depcache")
32 print "" >> (SVCDIR "/depcache")
29} 33}
30 34
31function print_header1() { 35function print_header1(mtime) {
32 print "#*** " MYFILENAME " ***" >> (DEPCACHE) 36 print "#*** " MYFILENAME " ***" >> (SVCDIR "/depcache")
33 print "" >> (DEPCACHE) 37 print "" >> (SVCDIR "/depcache")
34 print "myservice=\"" MYFILENAME "\"" >> (DEPCACHE) 38 print "myservice=\"" MYFILENAME "\"" >> (SVCDIR "/depcache")
35 print "myservice=\"${myservice##*/}\"" >> (DEPCACHE) 39 print "myservice=\"${myservice##*/}\"" >> (SVCDIR "/depcache")
36 print "echo \"RCSCRIPT ${myservice}\"" >> (DEPCACHE) 40 print "echo \"RCSCRIPT ${myservice}\"" >> (SVCDIR "/depcache")
37 print "" >> (DEPCACHE) 41 print "" >> (SVCDIR "/depcache")
42 print "echo \"MTIME " mtime "\"" >> (SVCDIR "/depcache")
43 print "" >> (SVCDIR "/depcache")
38} 44}
39 45
40function print_header2() { 46function print_header2(mtime) {
41 print "(" >> (DEPCACHE) 47 print "(" >> (SVCDIR "/depcache")
42 print " # Get settings for rc-script ..." >> (DEPCACHE) 48 print " # Get settings for rc-script ..." >> (SVCDIR "/depcache")
43 print " [ -e /etc/conf.d/basic ] && source /etc/conf.d/basic" >> (DEPCACHE) 49 print " [ -e /etc/conf.d/basic ] && source /etc/conf.d/basic" >> (SVCDIR "/depcache")
44 print "" >> (DEPCACHE) 50 print "" >> (SVCDIR "/depcache")
45 print " [ -e \"/etc/conf.d/${myservice}\" ] && source \"/etc/conf.d/${myservice}\"" >> (DEPCACHE) 51 print " [ -e \"/etc/conf.d/${myservice}\" ] && source \"/etc/conf.d/${myservice}\"" >> (SVCDIR "/depcache")
46 print "" >> (DEPCACHE) 52 print "" >> (SVCDIR "/depcache")
47 print " [ -e /etc/conf.d/net ] && \\" >> (DEPCACHE) 53 print " [ -e /etc/conf.d/net ] && \\" >> (SVCDIR "/depcache")
48 print " [ \"${myservice%%.*}\" = \"net\" ] && \\" >> (DEPCACHE) 54 print " [ \"${myservice%%.*}\" = \"net\" ] && \\" >> (SVCDIR "/depcache")
49 print " [ \"${myservice##*.}\" != \"${myservice}\" ] && source /etc/conf.d/net" >> (DEPCACHE) 55 print " [ \"${myservice##*.}\" != \"${myservice}\" ] && source /etc/conf.d/net" >> (SVCDIR "/depcache")
50 print "" >> (DEPCACHE) 56 print "" >> (SVCDIR "/depcache")
51 print " [ -e /etc/rc.conf ] && source /etc/rc.conf" >> (DEPCACHE) 57 print " [ -e /etc/rc.conf ] && source /etc/rc.conf" >> (SVCDIR "/depcache")
52 print "" >> (DEPCACHE) 58 print "" >> (SVCDIR "/depcache")
53 print " depend() {" >> (DEPCACHE) 59 print " depend() {" >> (SVCDIR "/depcache")
54 print " return 0" >> (DEPCACHE) 60 print " return 0" >> (SVCDIR "/depcache")
55 print " }" >> (DEPCACHE) 61 print " }" >> (SVCDIR "/depcache")
56 print "" >> (DEPCACHE) 62 print "" >> (SVCDIR "/depcache")
57} 63}
58 64
59function print_end() { 65function print_end() {
60 print "" >> (DEPCACHE) 66 print "" >> (SVCDIR "/depcache")
61 print " depend" >> (DEPCACHE) 67 print " depend" >> (SVCDIR "/depcache")
62 print ")" >> (DEPCACHE) 68 print ")" >> (SVCDIR "/depcache")
63 print "" >> (DEPCACHE) 69 print "" >> (SVCDIR "/depcache")
64} 70}
65 71
66BEGIN { 72BEGIN {
67 73
68 extension("/lib/rcscripts/filefuncs.so", "dlload") 74 extension("/lib/rcscripts/filefuncs.so", "dlload")
75
76 # Get our environment variables
77 SVCDIR = ENVIRON["SVCDIR"]
78 if (SVCDIR == "") {
79 eerror("Could not get SVCDIR!")
80 exit 1
81 }
69 82
70 pipe = "ls /etc/init.d/*" 83 pipe = "ls /etc/init.d/*"
71 while ((pipe | getline tmpstring) > 0) 84 while ((pipe | getline tmpstring) > 0)
72 scripts = scripts " " tmpstring 85 scripts = scripts " " tmpstring
73 close(pipe) 86 close(pipe)
75 split(scripts, TMPRCSCRIPTS) 88 split(scripts, TMPRCSCRIPTS)
76 89
77 # Make sure that its a file we are working with, 90 # Make sure that its a file we are working with,
78 # and do not process scripts, source or backup files. 91 # and do not process scripts, source or backup files.
79 for (x in TMPRCSCRIPTS) 92 for (x in TMPRCSCRIPTS)
80 if ((isfile(TMPRCSCRIPTS[x])) && 93 if (((isfile(TMPRCSCRIPTS[x])) || (islink(TMPRCSCRIPTS[x]))) &&
81 (TMPRCSCRIPTS[x] !~ /((\.(sh|c|bak))|\~)$/)) { 94 (TMPRCSCRIPTS[x] !~ /((\.(c|bak))|\~)$/)) {
82 95
83 RCCOUNT++ 96 RCCOUNT++
84 97
85 RCSCRIPTS[RCCOUNT] = TMPRCSCRIPTS[x] 98 RCSCRIPTS[RCCOUNT] = TMPRCSCRIPTS[x]
86 } 99 }
88 if (RCCOUNT == 0) { 101 if (RCCOUNT == 0) {
89 eerror("No scripts to process!") 102 eerror("No scripts to process!")
90 exit 1 103 exit 1
91 } 104 }
92 105
93 DEPCACHE=SVCDIR "/depcache"
94
95 unlink(DEPCACHE)
96
97 print_start() 106 print_start()
98 107
99 for (count = 1;count <= RCCOUNT;count++) { 108 for (count = 1;count <= RCCOUNT;count++) {
100 109
101 MYFNR = 1 110 MYFNR = 1
102 MYFILENAME = RCSCRIPTS[count] 111 MYFILENAME = RCSCRIPTS[count]
112 STAT_DATA[1] = 1
103 113
104 while (((getline < (RCSCRIPTS[count])) > 0) && (!NEXTFILE)) { 114 while (((getline < (RCSCRIPTS[count])) > 0) && (!NEXTFILE)) {
105 115
106 # If line start with a '#' and is the first line 116 # If line start with a '#' and is the first line
107 if (($0 ~ /^[[:space:]]*#/) && (MYFNR == 1)) { 117 if (($0 ~ /^[[:space:]]*#/) && (MYFNR == 1)) {
108 118
109 # Remove any spaces and tabs 119 # Remove any spaces and tabs
110 gsub(/[[:space:]]+/, "") 120 gsub(/[[:space:]]+/, "")
111 121
112 if ($0 == "#!/sbin/runscript") { 122 if ($0 == "#!/sbin/runscript") {
123
124 if (RCSCRIPTS[count] ~ /\.sh$/) {
125
126 ewarn(RCSCRIPTS[count] " is invalid (should not end with '.sh')")
127 NEXTFILE = 1
128 continue
129 }
130
131 if (stat(MYFILENAME, STAT_DATA) != 0)
132 ewarn("Could not stat \"" MYFILENAME "\"")
113 133
114 ISRCSCRIPT = 1 134 ISRCSCRIPT = 1
115 print_header1() 135 print_header1(STAT_DATA["mtime"])
116 } else { 136 } else {
117 137
118 NEXTFILE = 1 138 NEXTFILE = 1
119 continue 139 continue
120 } 140 }
121 } 141 }
122 142
123 # Filter out comments and only process if its a rcscript 143 # Filter out comments and only process if its a rcscript
124 if (($0 !~ /^[[:space:]]*#/) && (ISRCSCRIPT == 1)) { 144 if (($0 !~ /^[[:space:]]*#/) && (ISRCSCRIPT)) {
125 145
126 # If line contain 'depend()', set GOTDEPEND to 1 146 # If line contain 'depend()', set GOTDEPEND to 1
127 if ($0 ~ /depend[[:space:]]*\(\)/) { 147 if ($0 ~ /depend[[:space:]]*\(\)/) {
128 148
129 GOTDEPEND = 1 149 GOTDEPEND = 1
130 150
131 print_header2() 151 print_header2()
132 print " # Actual depend() function ..." >> (DEPCACHE) 152 print " # Actual depend() function ..." >> (SVCDIR "/depcache")
133 } 153 }
134 154
135 # We have the depend function... 155 # We have the depend function...
136 if (GOTDEPEND == 1) { 156 if (GOTDEPEND) {
137 157
138 # Basic theory is that COUNT will be 0 when we 158 # Basic theory is that COUNT will be 0 when we
139 # have matching '{' and '}' 159 # have matching '{' and '}'
140 COUNT += gsub(/{/, "{") 160 COUNT += gsub(/{/, "{")
141 COUNT -= gsub(/}/, "}") 161 COUNT -= gsub(/}/, "}")
142 162
143 # This is just to verify that we have started with 163 # This is just to verify that we have started with
144 # the body of depend() 164 # the body of depend()
145 SBCOUNT += gsub(/{/, "{") 165 SBCOUNT += gsub(/{/, "{")
166
167 # Make sure depend() contain something, else bash
168 # errors out (empty function).
169 if ((SBCOUNT > 0) && (COUNT == 0))
170 print " \treturn 0" >> (SVCDIR "/depcache")
146 171
147 # Print the depend() function 172 # Print the depend() function
148 print " " $0 >> (DEPCACHE) 173 print " " $0 >> (SVCDIR "/depcache")
149 174
150 # If COUNT=0, and SBCOUNT>0, it means we have read 175 # If COUNT=0, and SBCOUNT>0, it means we have read
151 # all matching '{' and '}' for depend(), so stop. 176 # all matching '{' and '}' for depend(), so stop.
152 if ((SBCOUNT > 0) && (COUNT == 0)) { 177 if ((SBCOUNT > 0) && (COUNT == 0)) {
153 178
170 close(RCSCRIPTS[count]) 195 close(RCSCRIPTS[count])
171 196
172 NEXTFILE = 0 197 NEXTFILE = 0
173 198
174 } 199 }
175
176 close (DEPCACHE)
177} 200}
178 201
179 202
180# vim:ts=4 203# vim:ts=4

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.15

  ViewVC Help
Powered by ViewVC 1.1.20