/[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.18 - (hide annotations) (download)
Mon Aug 23 06:39:42 2004 UTC (15 years, 10 months ago) by vapier
Branch: MAIN
Changes since 1.17: +2 -2 lines
fix copyright lines

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.18 # $Header: /home/cvsroot/gentoo-src/rc-scripts/src/awk/cachedepends.awk,v 1.17 2004/04/21 17:09:18 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 " [ -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 azarah 1.1 }
63    
64     function print_end() {
65 agriffis 1.16 print "" >> TMPCACHE
66     print " depend" >> TMPCACHE
67     print ")" >> TMPCACHE
68     print "" >> TMPCACHE
69 azarah 1.1 }
70    
71 azarah 1.3 BEGIN {
72    
73     extension("/lib/rcscripts/filefuncs.so", "dlload")
74    
75 azarah 1.14 # Get our environment variables
76     SVCDIR = ENVIRON["SVCDIR"]
77     if (SVCDIR == "") {
78     eerror("Could not get SVCDIR!")
79     exit 1
80     }
81    
82 agriffis 1.16 # 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 azarah 1.3 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 azarah 1.12 if (((isfile(TMPRCSCRIPTS[x])) || (islink(TMPRCSCRIPTS[x]))) &&
101 azarah 1.13 (TMPRCSCRIPTS[x] !~ /((\.(c|bak))|\~)$/)) {
102 azarah 1.3
103     RCCOUNT++
104    
105     RCSCRIPTS[RCCOUNT] = TMPRCSCRIPTS[x]
106     }
107 azarah 1.5
108     if (RCCOUNT == 0) {
109     eerror("No scripts to process!")
110 agriffis 1.16 system("rm -f "TMPCACHE)
111 azarah 1.5 exit 1
112     }
113 azarah 1.3
114     print_start()
115    
116     for (count = 1;count <= RCCOUNT;count++) {
117    
118     MYFNR = 1
119     MYFILENAME = RCSCRIPTS[count]
120 azarah 1.15 STAT_DATA[1] = 1
121 azarah 1.3
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 azarah 1.1
127 azarah 1.3 # Remove any spaces and tabs
128     gsub(/[[:space:]]+/, "")
129 azarah 1.1
130 azarah 1.3 if ($0 == "#!/sbin/runscript") {
131 azarah 1.13
132     if (RCSCRIPTS[count] ~ /\.sh$/) {
133    
134     ewarn(RCSCRIPTS[count] " is invalid (should not end with '.sh')")
135     NEXTFILE = 1
136     continue
137     }
138 azarah 1.15
139     if (stat(MYFILENAME, STAT_DATA) != 0)
140     ewarn("Could not stat \"" MYFILENAME "\"")
141 azarah 1.3
142     ISRCSCRIPT = 1
143 azarah 1.15 print_header1(STAT_DATA["mtime"])
144 azarah 1.3 } else {
145    
146     NEXTFILE = 1
147     continue
148     }
149     }
150 azarah 1.1
151 azarah 1.3 # Filter out comments and only process if its a rcscript
152 azarah 1.9 if (($0 !~ /^[[:space:]]*#/) && (ISRCSCRIPT)) {
153 azarah 1.1
154 azarah 1.3 # If line contain 'depend()', set GOTDEPEND to 1
155 azarah 1.8 if ($0 ~ /depend[[:space:]]*\(\)/) {
156    
157 azarah 1.3 GOTDEPEND = 1
158 azarah 1.8
159     print_header2()
160 agriffis 1.16 print " # Actual depend() function ..." >> TMPCACHE
161 azarah 1.8 }
162 azarah 1.1
163 azarah 1.3 # We have the depend function...
164 azarah 1.9 if (GOTDEPEND) {
165 azarah 1.1
166 azarah 1.3 # Basic theory is that COUNT will be 0 when we
167     # have matching '{' and '}'
168     COUNT += gsub(/{/, "{")
169     COUNT -= gsub(/}/, "}")
170 azarah 1.1
171 azarah 1.3 # This is just to verify that we have started with
172     # the body of depend()
173     SBCOUNT += gsub(/{/, "{")
174 azarah 1.11
175     # Make sure depend() contain something, else bash
176     # errors out (empty function).
177     if ((SBCOUNT > 0) && (COUNT == 0))
178 agriffis 1.16 print " \treturn 0" >> TMPCACHE
179 azarah 1.1
180 azarah 1.3 # Print the depend() function
181 agriffis 1.16 print " " $0 >> TMPCACHE
182 azarah 1.1
183 azarah 1.3 # 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 azarah 1.8 ISRCSCRIPT = 0
191 azarah 1.3
192     print_end()
193 azarah 1.8
194 azarah 1.3 NEXTFILE = 1
195     continue
196     }
197     }
198     }
199    
200     MYFNR++
201     }
202    
203     close(RCSCRIPTS[count])
204 azarah 1.1
205 azarah 1.3 NEXTFILE = 0
206 azarah 1.2
207 azarah 1.1 }
208 agriffis 1.16
209     system("mv "TMPCACHE" "SVCDIR"/depcache")
210 azarah 1.1 }
211    
212 azarah 1.3
213     # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20