/[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.13 - (show annotations) (download)
Sat Nov 15 15:42:10 2003 UTC (16 years, 7 months ago) by azarah
Branch: MAIN
Changes since 1.12: +64 -57 lines
Add a warning to cachedepends.awk if a rc-script's name ends in
'.sh', bug #33134.  Add better error checking to /sbin/depscan.sh.

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

  ViewVC Help
Powered by ViewVC 1.1.20