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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.17 - (show annotations) (download)
Wed Apr 21 17:09:18 2004 UTC (16 years, 2 months ago) by vapier
Branch: MAIN
Changes since 1.16: +2 -3 lines
update copyright years

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

  ViewVC Help
Powered by ViewVC 1.1.20