/[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.14 - (show annotations) (download)
Mon Dec 29 01:00:27 2003 UTC (16 years, 6 months ago) by azarah
Branch: MAIN
Changes since 1.13: +8 -1 lines
Update /sbin/depscan.sh, /sbin/env-update.sh, src/awk/cachedepends.awk,
src/awk/gendepends.awk and src/awk/genenviron.awk to use ENVIRON rather
then gawk -v.  Also add some tests to see if we got the environment
variables.

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.13 2003/11/15 15:42:10 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 # Get our environment variables
75 SVCDIR = ENVIRON["SVCDIR"]
76 if (SVCDIR == "") {
77 eerror("Could not get SVCDIR!")
78 exit 1
79 }
80
81 pipe = "ls /etc/init.d/*"
82 while ((pipe | getline tmpstring) > 0)
83 scripts = scripts " " tmpstring
84 close(pipe)
85
86 split(scripts, TMPRCSCRIPTS)
87
88 # Make sure that its a file we are working with,
89 # and do not process scripts, source or backup files.
90 for (x in TMPRCSCRIPTS)
91 if (((isfile(TMPRCSCRIPTS[x])) || (islink(TMPRCSCRIPTS[x]))) &&
92 (TMPRCSCRIPTS[x] !~ /((\.(c|bak))|\~)$/)) {
93
94 RCCOUNT++
95
96 RCSCRIPTS[RCCOUNT] = TMPRCSCRIPTS[x]
97 }
98
99 if (RCCOUNT == 0) {
100 eerror("No scripts to process!")
101 exit 1
102 }
103
104 print_start()
105
106 for (count = 1;count <= RCCOUNT;count++) {
107
108 MYFNR = 1
109 MYFILENAME = RCSCRIPTS[count]
110
111 while (((getline < (RCSCRIPTS[count])) > 0) && (!NEXTFILE)) {
112
113 # If line start with a '#' and is the first line
114 if (($0 ~ /^[[:space:]]*#/) && (MYFNR == 1)) {
115
116 # Remove any spaces and tabs
117 gsub(/[[:space:]]+/, "")
118
119 if ($0 == "#!/sbin/runscript") {
120
121 if (RCSCRIPTS[count] ~ /\.sh$/) {
122
123 ewarn(RCSCRIPTS[count] " is invalid (should not end with '.sh')")
124 NEXTFILE = 1
125 continue
126 }
127
128 ISRCSCRIPT = 1
129 print_header1()
130 } else {
131
132 NEXTFILE = 1
133 continue
134 }
135 }
136
137 # Filter out comments and only process if its a rcscript
138 if (($0 !~ /^[[:space:]]*#/) && (ISRCSCRIPT)) {
139
140 # If line contain 'depend()', set GOTDEPEND to 1
141 if ($0 ~ /depend[[:space:]]*\(\)/) {
142
143 GOTDEPEND = 1
144
145 print_header2()
146 print " # Actual depend() function ..." >> (SVCDIR "/depcache")
147 }
148
149 # We have the depend function...
150 if (GOTDEPEND) {
151
152 # Basic theory is that COUNT will be 0 when we
153 # have matching '{' and '}'
154 COUNT += gsub(/{/, "{")
155 COUNT -= gsub(/}/, "}")
156
157 # This is just to verify that we have started with
158 # the body of depend()
159 SBCOUNT += gsub(/{/, "{")
160
161 # Make sure depend() contain something, else bash
162 # errors out (empty function).
163 if ((SBCOUNT > 0) && (COUNT == 0))
164 print " \treturn 0" >> (SVCDIR "/depcache")
165
166 # Print the depend() function
167 print " " $0 >> (SVCDIR "/depcache")
168
169 # If COUNT=0, and SBCOUNT>0, it means we have read
170 # all matching '{' and '}' for depend(), so stop.
171 if ((SBCOUNT > 0) && (COUNT == 0)) {
172
173 GOTDEPEND = 0
174 COUNT = 0
175 SBCOUNT = 0
176 ISRCSCRIPT = 0
177
178 print_end()
179
180 NEXTFILE = 1
181 continue
182 }
183 }
184 }
185
186 MYFNR++
187 }
188
189 close(RCSCRIPTS[count])
190
191 NEXTFILE = 0
192
193 }
194 }
195
196
197 # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20