/[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.15 - (hide annotations) (download)
Thu Feb 26 17:29:43 2004 UTC (16 years, 4 months ago) by azarah
Branch: MAIN
Changes since 1.14: +10 -4 lines
Update to enable checking of mtimes on rc-scripts, and auto running
depscan.sh if needed.  Also try to run depscan.sh when RC_GOT_DEPTREE_INFO
is not set instead of just erroring.

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

  ViewVC Help
Powered by ViewVC 1.1.20