/[baselayout]/trunk/sbin/rc-envupdate.sh.bash
Gentoo

Contents of /trunk/sbin/rc-envupdate.sh.bash

Parent Directory Parent Directory | Revision Log Revision Log


Revision 264 - (show annotations) (download)
Mon Nov 18 12:26:20 2002 UTC (11 years, 11 months ago) by azarah
File size: 2987 byte(s)
awk version of rc-envupdate.sh

1 #!/bin/bash
2 # Copyright 1999-2002 Gentoo Technologies, Inc.
3 # Distributed under the terms of the GNU General Public License, v2 or later
4 # Author: Martin Schlemmer <azarah@gentoo.org>
5 # $Header$
6
7
8 source /etc/init.d/functions.sh
9
10 if [ `id -u` -ne 0 ]
11 then
12 eerror "$0: must be root."
13 exit 1
14 fi
15
16 usage() {
17 cat << FOO
18 usage: rc-envupdate.sh
19
20 note:
21 This utility generates /etc/profile.env and /etc/csh.env
22 from the contents of /etc/env.d/
23
24 FOO
25 exit 1
26 }
27
28 parse_envd() {
29
30 >${svcdir}/varlist
31 >${svcdir}/vardata
32
33 local myenvd_files=""
34
35 #generate our variable list
36 for x in $(dolisting /etc/env.d/)
37 do
38 # Ignore backup files
39 if [ "$(echo ${x} | /bin/sed "s:\~$::")" = "${x}" -a \
40 "$(echo ${x} | /bin/sed "s:\.bak$::")" = "${x}" ]
41 then
42 myenvd_files="${myenvd_files} ${x}"
43 else
44 continue
45 fi
46
47 VARLIST="$(/bin/cat ${svcdir}/varlist)"
48 local variable=""
49 local value=""
50 if [ -f ${x} ] || ([ -L ${x} ] && [ -f $(/bin/readlink ${x}) ])
51 then
52 (/bin/awk '!/^#|^\t+#/ { gsub ( /=/, "\t" ) ; print $0 }' ${x}) | \
53 while read -r variable value
54 do
55 if [ "$(eval echo \${VARLIST/${variable}/})" = "${VARLIST}" -a \
56 -n "${variable}" -a -n "${value}" ]
57 then
58 if [ -n "${VARLIST}" ]
59 then
60 VARLIST="${VARLIST} ${variable}"
61 else
62 VARLIST="${variable}"
63 fi
64 echo "${VARLIST}" >${svcdir}/varlist
65 fi
66 done
67 fi
68 done
69
70 #clear the environment of stale variables
71 VARLIST="$(/bin/cat ${svcdir}/varlist)"
72 for x in ${VARLIST/LDPATH}
73 do
74 echo "export $(eval echo ${x})=\"\"" >> ${svcdir}/vardata
75 done
76
77 #now generate the the variable data
78 for x in ${myenvd_files}
79 do
80 source ${svcdir}/vardata
81 VARLIST="$(/bin/cat ${svcdir}/varlist)"
82 if [ -f ${x} ] || ([ -L ${x} ] && [ -f $(/bin/readlink ${x}) ])
83 then
84 (/bin/awk '!/^#|^\t+#/ { gsub ( /=/, "\t" ) ; print $0 }' ${x}) | \
85 while read -r variable value
86 do
87 if [ -n "${variable}" -a -n "${value}" ]
88 then
89 if [ -n "$(eval echo \${$variable})" ]
90 then
91 # $KDEDIR and $QTDIR should be set only to the highest
92 # env.d files's value ....
93 if [ "${variable}" != "KDEDIR" -a \
94 "${variable}" != "QTDIR" ]
95 then
96 eval ${variable}\="\${$variable}:\${value}"
97 else
98 eval ${variable}\="\${value}"
99 fi
100 else
101 eval ${variable}\="\${value}"
102 fi
103 fi
104
105 >${svcdir}/vardata
106 for y in ${VARLIST/LDPATH}
107 do
108 echo "export $(eval echo ${y})='$(eval echo \${$y})'" >> \
109 ${svcdir}/vardata
110 done
111 done
112 fi
113 done
114
115 #we do not want any '"' in here, else things will break
116 /bin/sed -e "s:\"::g" \
117 ${svcdir}/vardata >${svcdir}/profile.env
118 /bin/sed -e "s:export:setenv:g" -e "s:\=: :g" -e "s:\"::g" \
119 ${svcdir}/vardata >${svcdir}/csh.env
120
121 /bin/rm -f ${svcdir}/vardata ${svcdir}/varlist
122 /bin/mv -f ${svcdir}/profile.env /etc/profile.env
123 /bin/mv -f ${svcdir}/csh.env /etc/csh.env
124 }
125
126 if [ "$#" -ne 0 ]
127 then
128 usage
129 else
130 parse_envd
131 fi
132
133
134 # vim:ts=4

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20