1 |
#!/bin/sh |
#!/bin/sh |
2 |
|
|
3 |
# version: 0.3.6-r10 |
# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/env-rebuild.sh,v 1.13 2007-07-01 00:35:29 niro Exp $ |
4 |
# |
# |
5 |
# rebuilds /etc/{ld.so.conf,profile.env} with given files from /etc/env.d |
# rebuilds /etc/{ld.so.conf,profile.env} with given files from /etc/env.d |
6 |
# |
# |
14 |
# |
# |
15 |
## |
## |
16 |
|
|
17 |
#sets root path |
# sets root path |
18 |
P="" |
P="${MROOT}" |
19 |
SPECIALVARS="KDEDIRS PATH CLASSPATH LDPATH MANPATH INFODIR INFOPATH ROOTPATH CONFIG_PROTECT CONFIG_PROTECT_MASK PRELINK_PATH PRELINK_PATH_MASK" |
SPECIALVARS="KDEDIRS PATH CLASSPATH LDPATH MANPATH INFODIR INFOPATH ROOTPATH CONFIG_PROTECT CONFIG_PROTECT_MASK CONFIG_PROTECT_IGNORE PRELINK_PATH PRELINK_PATH_MASK OMF_DIR LIBGL_DRIVERS_PATH" |
|
#SPECIALVARS="KDEDIRS PATH LDPATH MANPATH INFODIR INFOPATH ROOTPATH CLASSPATH" |
|
20 |
|
|
21 |
echo -en "\n>>>> Rebuilding environment... " |
# secure tmp dir |
22 |
|
if [ -x /bin/mktemp ] |
|
#deletes existing conf files |
|
|
if [ -f ${P}/etc/ld.so.conf ] |
|
23 |
then |
then |
24 |
rm ${P}/etc/ld.so.conf |
TMPDIR="$(/bin/mktemp -d -p /var/tmp)" |
25 |
|
else |
26 |
|
TMPDIR="/var/tmp/tmp.$$" |
27 |
|
install -d ${TMPDIR} |
28 |
fi |
fi |
29 |
|
|
30 |
if [ -f ${P}/etc/profile.env ] |
echo -en "\n>>>> Rebuilding environment... " |
31 |
then |
|
32 |
rm ${P}/etc/profile.env |
# clean existing conf files |
33 |
fi |
:> ${P}/etc/ld.so.conf |
34 |
|
:> ${P}/etc/profile.env |
35 |
|
|
36 |
#gets everything in /etc/env.d |
# gets everything in /etc/env.d |
37 |
for file in ${P}/etc/env.d/* |
for file in ${P}/etc/env.d/* |
38 |
do |
do |
39 |
#reads content of every file |
# abort if "empty" |
40 |
|
[[ ${file} = ${P}/etc/env.d/\* ]] && continue |
41 |
|
|
42 |
|
# reads content of every file |
43 |
while read path |
while read path |
44 |
do |
do |
45 |
if [ -n "$path" ] |
# abort if empty or an comment |
46 |
|
case "${path}" in |
47 |
|
\#*|"") continue ;; |
48 |
|
esac |
49 |
|
|
50 |
|
# writes LDPATH to ${P}/etc/ld.so.conf, |
51 |
|
# anything else to ${P}/etc/profile.env |
52 |
|
if [[ ${path%%=*} = LDPATH ]] |
53 |
then |
then |
54 |
#writes LDPATH to ${P}/etc/ld.so.conf, |
#substitudes " from $path if exists |
55 |
#anything else to ${P}/etc/profile.env |
path="${path//\"}" #}" <--- make code readable again :) |
56 |
if [ "${path%%=*}" == LDPATH ] |
echo "${path##*=}" >> ${P}/etc/ld.so.conf |
57 |
then |
else |
58 |
#substitudes " from $path if exists |
# checks if var exists in specialvars |
59 |
path="${path//\"}" |
for i in ${SPECIALVARS} |
60 |
echo "${path##*=}" >> ${P}/etc/ld.so.conf |
do |
61 |
else |
[[ ${path%%=*} = ${i} ]] && SPECVAR="yes" |
62 |
#checks if var exists in specialvars |
done |
|
for i in $SPECIALVARS |
|
|
do |
|
|
if [ "${path%%=*}" == "$i" ] |
|
|
then |
|
|
SPECVAR="yes" |
|
|
fi |
|
|
done |
|
63 |
|
|
64 |
if [ "$SPECVAR" == "yes" ] |
if [[ ${SPECVAR} = yes ]] |
65 |
|
then |
66 |
|
if [[ ${path%%=*} = CONFIG_PROTECT ]] || [[ ${path%%=*} = CONFIG_PROTECT_MASK ]] || [[ ${path%%=*} = CONFIG_PROTECT_IGNORE ]] |
67 |
then |
then |
68 |
if [ "${path%%=*}" == "CONFIG_PROTECT" -o "${path%%=*}" == "CONFIG_PROTECT_MASK" ] |
# CONFIG_PROTECTS has as delimiter not ':' but ' ' |
69 |
then |
path="${path//\"}" #}" <--- make code readable again :) |
70 |
#CONFIG_PROTECTS has as delimiter not ':' but ' ' |
echo -n "${path##*=} " >> ${TMPDIR}/${path%%=*} |
71 |
path="${path//\"}" |
unset SPECVAR |
|
echo -n "${path##*=} " >> /var/tmp/${path%%=*} |
|
|
unset SPECVAR |
|
|
else |
|
|
#special var are written to tmpfile |
|
|
# to substitude them to one variable |
|
|
#substitudes " from $path if exists |
|
|
path="${path//\"}" |
|
|
echo -n "${path##*=}:" >> /var/tmp/${path%%=*} |
|
|
unset SPECVAR |
|
|
fi |
|
72 |
else |
else |
73 |
#all other vars go directly to /etc/profile.env |
# special var are written to tmpfile |
74 |
echo "export $path" >> ${P}/etc/profile.env |
# to substitude them to one variable |
75 |
|
# substitudes " from $path if exists |
76 |
|
path="${path//\"}" #}" <--- make code readable again :) |
77 |
|
echo -n "${path##*=}:" >> ${TMPDIR}/${path%%=*} |
78 |
|
unset SPECVAR |
79 |
fi |
fi |
80 |
|
else |
81 |
|
# all other vars go directly to /etc/profile.env |
82 |
|
echo "export ${path}" >> ${P}/etc/profile.env |
83 |
fi |
fi |
84 |
fi |
fi |
85 |
done << EOF |
done << EOF |
86 |
$(cat $file) |
$(cat ${file}) |
87 |
EOF |
EOF |
88 |
|
|
89 |
done |
done |
90 |
|
|
91 |
#reads special vars tmp files and writes them to /etc/profile.env |
# reads special vars tmp files and writes them to /etc/profile.env |
92 |
for i in $SPECIALVARS |
for i in ${SPECIALVARS} |
93 |
do |
do |
94 |
if [ -f /var/tmp/${i} ] |
if [ -f ${TMPDIR}/${i} ] |
95 |
then |
then |
96 |
echo "export ${i}=\"`cat /var/tmp/${i}`\"" >> ${P}/etc/profile.env |
# only OMF_DIR goes to /etc/scrollkeeper.conf |
97 |
rm /var/tmp/${i} |
if [[ ${i} = OMF_DIR ]] |
98 |
|
then |
99 |
|
echo "${i}=$(cat ${TMPDIR}/${i})" > ${P}/etc/scrollkeeper.conf |
100 |
|
else |
101 |
|
echo "export ${i}=\"$(cat ${TMPDIR}/${i})\"" >> ${P}/etc/profile.env |
102 |
|
fi |
103 |
|
rm ${TMPDIR}/${i} |
104 |
fi |
fi |
105 |
done |
done |
106 |
|
|
107 |
#rebuilds environment |
# rebuilds environment |
108 |
ldconfig |
ldconfig -r "${P}" -f /etc/ld.so.conf -C /etc/ld.so.cache |
109 |
source ${P}/etc/profile |
[ -f ${P}/etc/profile ] && source ${P}/etc/profile |
110 |
|
|
111 |
|
# cleanups |
112 |
|
[ -d ${TMPDIR} ] && rm -rf ${TMPDIR} |
113 |
|
|
114 |
echo -e "done.\n" |
echo -e "done.\n" |