/[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 - (hide 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 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.13 # $Header: /home/cvsroot/gentoo-src/rc-scripts/src/awk/cachedepends.awk,v 1.12 2003/07/16 18:27:55 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.8 function print_header1() {
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.8 }
43    
44     function print_header2() {
45 azarah 1.13 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 azarah 1.1 }
62    
63     function print_end() {
64 azarah 1.13 print "" >> (SVCDIR "/depcache")
65     print " depend" >> (SVCDIR "/depcache")
66     print ")" >> (SVCDIR "/depcache")
67     print "" >> (SVCDIR "/depcache")
68 azarah 1.1 }
69    
70 azarah 1.3 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 azarah 1.12 if (((isfile(TMPRCSCRIPTS[x])) || (islink(TMPRCSCRIPTS[x]))) &&
85 azarah 1.13 (TMPRCSCRIPTS[x] !~ /((\.(c|bak))|\~)$/)) {
86 azarah 1.3
87     RCCOUNT++
88    
89     RCSCRIPTS[RCCOUNT] = TMPRCSCRIPTS[x]
90     }
91 azarah 1.5
92     if (RCCOUNT == 0) {
93     eerror("No scripts to process!")
94     exit 1
95     }
96 azarah 1.3
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 azarah 1.1
109 azarah 1.3 # Remove any spaces and tabs
110     gsub(/[[:space:]]+/, "")
111 azarah 1.1
112 azarah 1.3 if ($0 == "#!/sbin/runscript") {
113 azarah 1.13
114     if (RCSCRIPTS[count] ~ /\.sh$/) {
115    
116     ewarn(RCSCRIPTS[count] " is invalid (should not end with '.sh')")
117     NEXTFILE = 1
118     continue
119     }
120 azarah 1.3
121     ISRCSCRIPT = 1
122 azarah 1.8 print_header1()
123 azarah 1.3 } else {
124    
125     NEXTFILE = 1
126     continue
127     }
128     }
129 azarah 1.1
130 azarah 1.3 # Filter out comments and only process if its a rcscript
131 azarah 1.9 if (($0 !~ /^[[:space:]]*#/) && (ISRCSCRIPT)) {
132 azarah 1.1
133 azarah 1.3 # If line contain 'depend()', set GOTDEPEND to 1
134 azarah 1.8 if ($0 ~ /depend[[:space:]]*\(\)/) {
135    
136 azarah 1.3 GOTDEPEND = 1
137 azarah 1.8
138     print_header2()
139 azarah 1.13 print " # Actual depend() function ..." >> (SVCDIR "/depcache")
140 azarah 1.8 }
141 azarah 1.1
142 azarah 1.3 # We have the depend function...
143 azarah 1.9 if (GOTDEPEND) {
144 azarah 1.1
145 azarah 1.3 # Basic theory is that COUNT will be 0 when we
146     # have matching '{' and '}'
147     COUNT += gsub(/{/, "{")
148     COUNT -= gsub(/}/, "}")
149 azarah 1.1
150 azarah 1.3 # This is just to verify that we have started with
151     # the body of depend()
152     SBCOUNT += gsub(/{/, "{")
153 azarah 1.11
154     # Make sure depend() contain something, else bash
155     # errors out (empty function).
156     if ((SBCOUNT > 0) && (COUNT == 0))
157 azarah 1.13 print " \treturn 0" >> (SVCDIR "/depcache")
158 azarah 1.1
159 azarah 1.3 # Print the depend() function
160 azarah 1.13 print " " $0 >> (SVCDIR "/depcache")
161 azarah 1.1
162 azarah 1.3 # 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 azarah 1.8 ISRCSCRIPT = 0
170 azarah 1.3
171     print_end()
172 azarah 1.8
173 azarah 1.3 NEXTFILE = 1
174     continue
175     }
176     }
177     }
178    
179     MYFNR++
180     }
181    
182     close(RCSCRIPTS[count])
183 azarah 1.1
184 azarah 1.3 NEXTFILE = 0
185 azarah 1.2
186 azarah 1.1 }
187     }
188    
189 azarah 1.3
190     # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20