/[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.19 - (hide annotations) (download)
Mon Nov 15 16:23:41 2004 UTC (15 years, 7 months ago) by vapier
Branch: MAIN
Branch point for: bsd-porting, rc-scripts-1_6
Changes since 1.18: +1 -2 lines
stop using /etc/conf.d/basic

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

  ViewVC Help
Powered by ViewVC 1.1.20