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

Contents of /rc-scripts/src/awk/genenviron.awk

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.15 - (show annotations) (download)
Wed Apr 27 02:39:54 2005 UTC (15 years, 2 months ago) by vapier
Branch: MAIN
CVS Tags: HEAD
Changes since 1.14: +2 -2 lines
sync special var list with portages env-update #88819

1 # Copyright 1999-2004 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-src/rc-scripts/src/awk/genenviron.awk,v 1.14 2004/08/23 06:39:42 vapier Exp $
4
5 BEGIN {
6
7 extension("/lib/rcscripts/filefuncs.so", "dlload")
8
9 # Get our environment variables
10 SVCDIR = ENVIRON["SVCDIR"]
11 if (SVCDIR == "") {
12 eerror("Could not get SVCDIR!")
13 exit 1
14 }
15
16 pipe = "ls -1 /etc/env.d/."
17 while ((pipe | getline tmpstring) > 0)
18 scripts = scripts " /etc/env.d/" tmpstring
19 close(pipe)
20
21 split(scripts, TMPENVFILES)
22
23 # Make sure that its a file we are working with,
24 # and do not process scripts, source or backup files.
25 # NOTE: do not use 'for (x in TMPENVFILES)', as gawk
26 # have this notion that it should mess with the
27 # order it list things then ....
28 for (x = 1;;x++) {
29
30 if (x in TMPENVFILES) {
31
32 if ((isfile(TMPENVFILES[x])) &&
33 (TMPENVFILES[x] !~ /((\.(sh|c|bak))|\~)$/)) {
34
35 ENVCOUNT++
36
37 ENVFILES[ENVCOUNT] = TMPENVFILES[x]
38 }
39 } else
40 break
41 }
42
43 if (ENVCOUNT == 0) {
44
45 eerror("No files to process!")
46 exit 1
47 }
48
49 ENVCACHE = SVCDIR "/envcache"
50 SHPROFILE = "/etc/profile.env"
51 CSHPROFILE = "/etc/csh.env"
52
53 # SPECIALS are treated differently. For each env.d file, the variables are
54 # appended seperated with a ':'. If not in specials, for each env.d file,
55 # the variable are just set to the new value.
56 tmpspecials="KDEDIRS:PATH:CLASSPATH:LDPATH:MANPATH:INFOPATH:ROOTPATH:CONFIG_PROTECT:CONFIG_PROTECT_MASK:PRELINK_PATH:PRELINK_PATH_MASK:PYTHONPATH:ADA_INCLUDE_PATH:ADA_OBJECTS_PATH"
57 split(tmpspecials, SPECIALS, ":")
58
59 unlink(ENVCACHE)
60
61 for (count = 1;count <= ENVCOUNT;count++) {
62
63 while ((getline < (ENVFILES[count])) > 0) {
64
65 # Filter out comments
66 if ($0 !~ /^[[:space:]]*#/) {
67
68 split($0, envnode, "=")
69
70 if (envnode[2] == "")
71 continue
72
73 if ($0 == "")
74 continue
75
76 # LDPATH should not be in environment
77 if (envnode[1] == "LDPATH")
78 continue
79
80 # In bash there should be no space between the variable name and
81 # the '=' ...
82 if (envnode[1] ~ /[^[:space:]]*[[:space:]]+$/)
83 continue
84
85 # strip variable name and '=' from data
86 sub("^[[:space:]]*" envnode[1] "[[:space:]]*=", "")
87 # strip all '"' and '\''
88 gsub(/\"/, "")
89 gsub(/\'/, "")
90 # strip leading and trailing spaces
91 gsub(/^[[:space:]]*/, "")
92 gsub(/[[:space:]]*$/, "")
93
94 if (envnode[1] in ENVTREE) {
95
96 DOSPECIAL = 0
97
98 for (x in SPECIALS) {
99
100 # Is this a special variable ?
101 if (envnode[1] == SPECIALS[x])
102 DOSPECIAL = 1
103 }
104
105 if (DOSPECIAL) {
106 split(ENVTREE[envnode[1]], tmpstr, ":")
107
108 # Check that we do not add dups ...
109 NODUPS = 1
110 for (x in tmpstr)
111 if (tmpstr[x] == $0)
112 NODUPS = 0
113
114 if (NODUPS)
115 # Once again, "CONFIG_PROTECT" and "CONFIG_PROTECT_MASK"
116 # are handled differently ...
117 if ((envnode[1] == "CONFIG_PROTECT") || (envnode[1] == "CONFIG_PROTECT_MASK"))
118 ENVTREE[envnode[1]] = ENVTREE[envnode[1]] " " $0
119 else
120 ENVTREE[envnode[1]] = ENVTREE[envnode[1]] ":" $0
121 } else
122 ENVTREE[envnode[1]] = $0
123 } else
124 ENVTREE[envnode[1]] = $0
125 }
126 }
127
128 close(ENVFILES[count])
129 }
130
131 for (x in ENVTREE)
132 print "export " x "=\"" ENVTREE[x] "\"" >> (ENVCACHE)
133
134 for (x in ENVTREE) {
135
136 # Print this a second time to make sure all variables
137 # are expanded ..
138 print "export " x "=\"" ENVTREE[x] "\"" >> (ENVCACHE)
139 print "echo \"" x "=${" x "}\"" >> (ENVCACHE)
140 }
141
142 close (ENVCACHE)
143
144 unlink(SHPROFILE)
145 unlink(CSHPROFILE)
146
147 # Add warning header for SHPROFILE
148 print "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update." > (SHPROFILE)
149 print "# DO NOT EDIT THIS FILE. CHANGES TO STARTUP PROFILES" >> (SHPROFILE)
150 print "# GO INTO /etc/profile NOT /etc/profile.env" >> (SHPROFILE)
151 print "" >> (SHPROFILE)
152
153 # Add warning header for CSHPROFILE
154 print "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update." > (CSHPROFILE)
155 print "# DO NOT EDIT THIS FILE. CHANGES TO STARTUP PROFILES" >> (CSHPROFILE)
156 print "# GO INTO /etc/csh.cshrc NOT /etc/csh.env" >> (CSHPROFILE)
157 print "" >> (CSHPROFILE)
158
159
160 pipe = "bash " ENVCACHE
161 while ((pipe | getline) > 0) {
162
163 sub(/=/, "='")
164 sub(/$/, "'")
165
166 print "export " $0 >> (SHPROFILE)
167
168 sub(/=/, " ")
169
170 print "setenv " $0 >> (CSHPROFILE)
171 }
172
173 close(pipe)
174 close(SHPROFILE)
175 close(CSHPROFILE)
176 }
177
178
179 # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20