/[baselayout]/trunk/src/awk/genenviron.awk
Gentoo

Contents of /trunk/src/awk/genenviron.awk

Parent Directory Parent Directory | Revision Log Revision Log


Revision 484 - (show annotations) (download)
Wed Apr 21 17:09:18 2004 UTC (15 years, 1 month ago) by vapier
File size: 4200 byte(s)
update copyright years

1 # Copyright 1999-2004 Gentoo Technologies, Inc.
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header$
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:INFODIR:INFOPATH:ROOTPATH:CONFIG_PROTECT:CONFIG_PROTECT_MASK:PRELINK_PATH:PRELINK_PATH_MASK"
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
91 if (envnode[1] in ENVTREE) {
92
93 DOSPECIAL = 0
94
95 for (x in SPECIALS) {
96
97 # Is this a special variable ?
98 if (envnode[1] == SPECIALS[x])
99 DOSPECIAL = 1
100 }
101
102 if (DOSPECIAL) {
103 split(ENVTREE[envnode[1]], tmpstr, ":")
104
105 # Check that we do not add dups ...
106 NODUPS = 1
107 for (x in tmpstr)
108 if (tmpstr[x] == $0)
109 NODUPS = 0
110
111 if (NODUPS)
112 # Once again, "CONFIG_PROTECT" and "CONFIG_PROTECT_MASK"
113 # are handled differently ...
114 if ((envnode[1] == "CONFIG_PROTECT") || (envnode[1] == "CONFIG_PROTECT_MASK"))
115 ENVTREE[envnode[1]] = ENVTREE[envnode[1]] " " $0
116 else
117 ENVTREE[envnode[1]] = ENVTREE[envnode[1]] ":" $0
118 } else
119 ENVTREE[envnode[1]] = $0
120 } else
121 ENVTREE[envnode[1]] = $0
122 }
123 }
124
125 close(ENVFILES[count])
126 }
127
128 for (x in ENVTREE)
129 print "export " x "=\"" ENVTREE[x] "\"" >> (ENVCACHE)
130
131 for (x in ENVTREE) {
132
133 # Print this a second time to make sure all variables
134 # are expanded ..
135 print "export " x "=\"" ENVTREE[x] "\"" >> (ENVCACHE)
136 print "echo \"" x "=${" x "}\"" >> (ENVCACHE)
137 }
138
139 close (ENVCACHE)
140
141 unlink(SHPROFILE)
142 unlink(CSHPROFILE)
143
144 # Add warning header for SHPROFILE
145 print "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update." > (SHPROFILE)
146 print "# DO NOT EDIT THIS FILE. CHANGES TO STARTUP PROFILES" >> (SHPROFILE)
147 print "# GO INTO /etc/profile NOT /etc/profile.env" >> (SHPROFILE)
148 print "" >> (SHPROFILE)
149
150 # Add warning header for CSHPROFILE
151 print "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update." > (CSHPROFILE)
152 print "# DO NOT EDIT THIS FILE. CHANGES TO STARTUP PROFILES" >> (CSHPROFILE)
153 print "# GO INTO /etc/csh.cshrc NOT /etc/csh.env" >> (CSHPROFILE)
154 print "" >> (CSHPROFILE)
155
156
157 pipe = "bash " ENVCACHE
158 while ((pipe | getline) > 0) {
159
160 sub(/=/, "='")
161 sub(/$/, "'")
162
163 print "export " $0 >> (SHPROFILE)
164
165 sub(/=/, " ")
166
167 print "setenv " $0 >> (CSHPROFILE)
168 }
169
170 close(pipe)
171 close(SHPROFILE)
172 close(CSHPROFILE)
173 }
174
175
176 # vim:ts=4

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20