/[gentoo-src]/rc-scripts/src/awk/cachedepends.awk
Gentoo

Diff of /rc-scripts/src/awk/cachedepends.awk

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.10 Revision 1.19
1# Copyright 1999-2003 Gentoo Technologies, Inc. 1# Copyright 1999-2004 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# Author: Martin Schlemmer <azarah@gentoo.org>
4# $Header: /var/cvsroot/gentoo-src/rc-scripts/src/awk/cachedepends.awk,v 1.10 2003/05/11 23:32:47 azarah Exp $ 3# $Header: /var/cvsroot/gentoo-src/rc-scripts/src/awk/cachedepends.awk,v 1.19 2004/11/15 16:23:41 vapier Exp $
5 4
6function print_start() { 5function print_start() {
7 print "source /sbin/functions.sh" 6 print "source /sbin/functions.sh" >> TMPCACHE
8 print "" 7 print "" >> TMPCACHE
9 print "need() {" 8 print "need() {" >> TMPCACHE
10 print " echo \"NEED $*\"; return 0" 9 print " echo \"NEED $*\"; return 0" >> TMPCACHE
11 print "}" 10 print "}" >> TMPCACHE
12 print "" 11 print "" >> TMPCACHE
13 print "use() {" 12 print "use() {" >> TMPCACHE
14 print " echo \"USE $*\"; return 0" 13 print " echo \"USE $*\"; return 0" >> TMPCACHE
15 print "}" 14 print "}" >> TMPCACHE
16 print "" 15 print "" >> TMPCACHE
17 print "before() {" 16 print "before() {" >> TMPCACHE
18 print " echo \"BEFORE $*\"; return 0" 17 print " echo \"BEFORE $*\"; return 0" >> TMPCACHE
19 print "}" 18 print "}" >> TMPCACHE
20 print "" 19 print "" >> TMPCACHE
21 print "after() {" 20 print "after() {" >> TMPCACHE
22 print " echo \"AFTER $*\"; return 0" 21 print " echo \"AFTER $*\"; return 0" >> TMPCACHE
23 print "}" 22 print "}" >> TMPCACHE
24 print "" 23 print "" >> TMPCACHE
25 print "provide() {" 24 print "provide() {" >> TMPCACHE
26 print " echo \"PROVIDE $*\"; return 0" 25 print " echo \"PROVIDE $*\"; return 0" >> TMPCACHE
27 print "}" 26 print "}" >> TMPCACHE
28 print "" 27 print "" >> TMPCACHE
29 print "parallel() {" 28 print "parallel() {" >> TMPCACHE
30 print " echo \"PARALLEL $*\"; return 0" 29 print " echo \"PARALLEL $*\"; return 0" >> TMPCACHE
31 print "}" 30 print "}" >> TMPCACHE
32 print "" 31 print "" >> TMPCACHE
33} 32}
34 33
35function print_header1() { 34function print_header1(mtime) {
36 print "#*** " MYFILENAME " ***" 35 print "#*** " MYFILENAME " ***" >> TMPCACHE
37 print "" 36 print "" >> TMPCACHE
38 print "myservice=\"" MYFILENAME "\"" 37 print "myservice=\"" MYFILENAME "\"" >> TMPCACHE
39 print "myservice=\"${myservice##*/}\"" 38 print "myservice=\"${myservice##*/}\"" >> TMPCACHE
40 print "echo \"RCSCRIPT ${myservice}\"" 39 print "echo \"RCSCRIPT ${myservice}\"" >> TMPCACHE
41 print "" 40 print "" >> TMPCACHE
41 print "echo \"MTIME " mtime "\"" >> TMPCACHE
42 print "" >> TMPCACHE
42} 43}
43 44
44function print_header2() { 45function print_header2(mtime) {
45 print "(" 46 print "(" >> TMPCACHE
46 print " # Get settings for rc-script ..." 47 print " # Get settings for rc-script ..." >> TMPCACHE
47 print " [ -e /etc/conf.d/basic ] && source /etc/conf.d/basic" 48 print "" >> TMPCACHE
48 print ""
49 print " [ -e \"/etc/conf.d/${myservice}\" ] && source \"/etc/conf.d/${myservice}\"" 49 print " [ -e \"/etc/conf.d/${myservice}\" ] && source \"/etc/conf.d/${myservice}\"" >> TMPCACHE
50 print "" 50 print "" >> TMPCACHE
51 print " [ -e /etc/conf.d/net ] && \\" 51 print " [ -e /etc/conf.d/net ] && \\" >> TMPCACHE
52 print " [ \"${myservice%%.*}\" = \"net\" ] && \\" 52 print " [ \"${myservice%%.*}\" = \"net\" ] && \\" >> TMPCACHE
53 print " [ \"${myservice##*.}\" != \"${myservice}\" ] && source /etc/conf.d/net" 53 print " [ \"${myservice##*.}\" != \"${myservice}\" ] && source /etc/conf.d/net" >> TMPCACHE
54 print "" 54 print "" >> TMPCACHE
55 print " [ -e /etc/rc.conf ] && source /etc/rc.conf" 55 print " [ -e /etc/rc.conf ] && source /etc/rc.conf" >> TMPCACHE
56 print "" 56 print "" >> TMPCACHE
57 print " depend() {" 57 print " depend() {" >> TMPCACHE
58 print " return 0" 58 print " return 0" >> TMPCACHE
59 print " }" 59 print " }" >> TMPCACHE
60 print "" 60 print "" >> TMPCACHE
61} 61}
62 62
63function print_end() { 63function print_end() {
64 print "" 64 print "" >> TMPCACHE
65 print " depend" 65 print " depend" >> TMPCACHE
66 print ")" 66 print ")" >> TMPCACHE
67 print "" 67 print "" >> TMPCACHE
68} 68}
69 69
70BEGIN { 70BEGIN {
71 71
72 extension("/lib/rcscripts/filefuncs.so", "dlload") 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 # 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 }
73 88
74 pipe = "ls /etc/init.d/*" 89 pipe = "ls /etc/init.d/*"
75 while ((pipe | getline tmpstring) > 0) 90 while ((pipe | getline tmpstring) > 0)
76 scripts = scripts " " tmpstring 91 scripts = scripts " " tmpstring
77 close(pipe) 92 close(pipe)
79 split(scripts, TMPRCSCRIPTS) 94 split(scripts, TMPRCSCRIPTS)
80 95
81 # Make sure that its a file we are working with, 96 # Make sure that its a file we are working with,
82 # and do not process scripts, source or backup files. 97 # and do not process scripts, source or backup files.
83 for (x in TMPRCSCRIPTS) 98 for (x in TMPRCSCRIPTS)
84 if ((isfile(TMPRCSCRIPTS[x])) && 99 if (((isfile(TMPRCSCRIPTS[x])) || (islink(TMPRCSCRIPTS[x]))) &&
85 (TMPRCSCRIPTS[x] !~ /((\.(sh|c|bak))|\~)$/)) { 100 (TMPRCSCRIPTS[x] !~ /((\.(c|bak))|\~)$/)) {
86 101
87 RCCOUNT++ 102 RCCOUNT++
88 103
89 RCSCRIPTS[RCCOUNT] = TMPRCSCRIPTS[x] 104 RCSCRIPTS[RCCOUNT] = TMPRCSCRIPTS[x]
90 } 105 }
91 106
92 if (RCCOUNT == 0) { 107 if (RCCOUNT == 0) {
93 eerror("No scripts to process!") 108 eerror("No scripts to process!")
109 system("rm -f "TMPCACHE)
94 exit 1 110 exit 1
95 } 111 }
96 112
97 print_start() 113 print_start()
98 114
99 for (count = 1;count <= RCCOUNT;count++) { 115 for (count = 1;count <= RCCOUNT;count++) {
100 116
101 MYFNR = 1 117 MYFNR = 1
102 MYFILENAME = RCSCRIPTS[count] 118 MYFILENAME = RCSCRIPTS[count]
119 STAT_DATA[1] = 1
103 120
104 while (((getline < (RCSCRIPTS[count])) > 0) && (!NEXTFILE)) { 121 while (((getline < (RCSCRIPTS[count])) > 0) && (!NEXTFILE)) {
105 122
106 # If line start with a '#' and is the first line 123 # If line start with a '#' and is the first line
107 if (($0 ~ /^[[:space:]]*#/) && (MYFNR == 1)) { 124 if (($0 ~ /^[[:space:]]*#/) && (MYFNR == 1)) {
108 125
109 # Remove any spaces and tabs 126 # Remove any spaces and tabs
110 gsub(/[[:space:]]+/, "") 127 gsub(/[[:space:]]+/, "")
111 128
112 if ($0 == "#!/sbin/runscript") { 129 if ($0 == "#!/sbin/runscript") {
130
131 if (RCSCRIPTS[count] ~ /\.sh$/) {
132
133 ewarn(RCSCRIPTS[count] " is invalid (should not end with '.sh')")
134 NEXTFILE = 1
135 continue
136 }
137
138 if (stat(MYFILENAME, STAT_DATA) != 0)
139 ewarn("Could not stat \"" MYFILENAME "\"")
113 140
114 ISRCSCRIPT = 1 141 ISRCSCRIPT = 1
115 print_header1() 142 print_header1(STAT_DATA["mtime"])
116 } else { 143 } else {
117 144
118 NEXTFILE = 1 145 NEXTFILE = 1
119 continue 146 continue
120 } 147 }
127 if ($0 ~ /depend[[:space:]]*\(\)/) { 154 if ($0 ~ /depend[[:space:]]*\(\)/) {
128 155
129 GOTDEPEND = 1 156 GOTDEPEND = 1
130 157
131 print_header2() 158 print_header2()
132 print " # Actual depend() function ..." 159 print " # Actual depend() function ..." >> TMPCACHE
133 } 160 }
134 161
135 # We have the depend function... 162 # We have the depend function...
136 if (GOTDEPEND) { 163 if (GOTDEPEND) {
137 164
141 COUNT -= gsub(/}/, "}") 168 COUNT -= gsub(/}/, "}")
142 169
143 # This is just to verify that we have started with 170 # This is just to verify that we have started with
144 # the body of depend() 171 # the body of depend()
145 SBCOUNT += gsub(/{/, "{") 172 SBCOUNT += gsub(/{/, "{")
173
174 # Make sure depend() contain something, else bash
175 # errors out (empty function).
176 if ((SBCOUNT > 0) && (COUNT == 0))
177 print " \treturn 0" >> TMPCACHE
146 178
147 # Print the depend() function 179 # Print the depend() function
148 print " " $0 180 print " " $0 >> TMPCACHE
149 181
150 # If COUNT=0, and SBCOUNT>0, it means we have read 182 # If COUNT=0, and SBCOUNT>0, it means we have read
151 # all matching '{' and '}' for depend(), so stop. 183 # all matching '{' and '}' for depend(), so stop.
152 if ((SBCOUNT > 0) && (COUNT == 0)) { 184 if ((SBCOUNT > 0) && (COUNT == 0)) {
153 185
170 close(RCSCRIPTS[count]) 202 close(RCSCRIPTS[count])
171 203
172 NEXTFILE = 0 204 NEXTFILE = 0
173 205
174 } 206 }
207
208 system("mv "TMPCACHE" "SVCDIR"/depcache")
175} 209}
176 210
177 211
178# vim:ts=4 212# vim:ts=4

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.19

  ViewVC Help
Powered by ViewVC 1.1.20