1 |
#!/bin/sh |
#!/bin/sh |
2 |
|
|
3 |
# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/env-rebuild.sh,v 1.7 2005-06-01 15:48:11 niro Exp $ |
# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/env-rebuild.sh,v 1.9 2005-10-04 15:07:47 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 OMF_DIR" |
SPECIALVARS="KDEDIRS PATH CLASSPATH LDPATH MANPATH INFODIR INFOPATH ROOTPATH CONFIG_PROTECT CONFIG_PROTECT_MASK PRELINK_PATH PRELINK_PATH_MASK OMF_DIR" |
20 |
#SPECIALVARS="KDEDIRS PATH LDPATH MANPATH INFODIR INFOPATH ROOTPATH CLASSPATH" |
#SPECIALVARS="KDEDIRS PATH LDPATH MANPATH INFODIR INFOPATH ROOTPATH CLASSPATH" |
21 |
|
|
22 |
echo -en "\n>>>> Rebuilding environment... " |
# secure tmp dir |
23 |
|
if [ -x /bin/mktemp ] |
|
#deletes existing conf files |
|
|
if [ -f ${P}/etc/ld.so.conf ] |
|
24 |
then |
then |
25 |
rm ${P}/etc/ld.so.conf |
TMPDIR="$(/bin/mktemp -d -p /var/tmp)" |
26 |
|
else |
27 |
|
TMPDIR="/var/tmp/tmp.$$" |
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 |
46 |
|
[[ -z ${path} ]] && continue |
47 |
|
|
48 |
|
# writes LDPATH to ${P}/etc/ld.so.conf, |
49 |
|
# anything else to ${P}/etc/profile.env |
50 |
|
if [[ ${path%%=*} = LDPATH ]] |
51 |
then |
then |
52 |
#writes LDPATH to ${P}/etc/ld.so.conf, |
#substitudes " from $path if exists |
53 |
#anything else to ${P}/etc/profile.env |
path="${path//\"}" #}" <--- make code readable again :) |
54 |
if [ "${path%%=*}" == LDPATH ] |
echo "${path##*=}" >> ${P}/etc/ld.so.conf |
55 |
then |
else |
56 |
#substitudes " from $path if exists |
# checks if var exists in specialvars |
57 |
path="${path//\"}" |
for i in ${SPECIALVARS} |
58 |
echo "${path##*=}" >> ${P}/etc/ld.so.conf |
do |
59 |
else |
[[ ${path%%=*} = ${i} ]] && SPECVAR="yes" |
60 |
#checks if var exists in specialvars |
done |
|
for i in $SPECIALVARS |
|
|
do |
|
|
if [ "${path%%=*}" == "$i" ] |
|
|
then |
|
|
SPECVAR="yes" |
|
|
fi |
|
|
done |
|
61 |
|
|
62 |
if [ "$SPECVAR" == "yes" ] |
if [[ ${SPECVAR} = yes ]] |
63 |
|
then |
64 |
|
if [[ ${path%%=*} = CONFIG_PROTECT ]] || [[ ${path%%=*} = CONFIG_PROTECT_MASK ]] |
65 |
then |
then |
66 |
if [ "${path%%=*}" == "CONFIG_PROTECT" -o "${path%%=*}" == "CONFIG_PROTECT_MASK" ] |
# CONFIG_PROTECTS has as delimiter not ':' but ' ' |
67 |
then |
path="${path//\"}" #}" <--- make code readable again :) |
68 |
#CONFIG_PROTECTS has as delimiter not ':' but ' ' |
echo -n "${path##*=} " >> ${TMPDIR}/${path%%=*} |
69 |
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 |
|
70 |
else |
else |
71 |
#all other vars go directly to /etc/profile.env |
# special var are written to tmpfile |
72 |
echo "export $path" >> ${P}/etc/profile.env |
# to substitude them to one variable |
73 |
|
# substitudes " from $path if exists |
74 |
|
path="${path//\"}" #}" <--- make code readable again :) |
75 |
|
echo -n "${path##*=}:" >> ${TMPDIR}/${path%%=*} |
76 |
|
unset SPECVAR |
77 |
fi |
fi |
78 |
|
else |
79 |
|
# all other vars go directly to /etc/profile.env |
80 |
|
echo "export ${path}" >> ${P}/etc/profile.env |
81 |
fi |
fi |
82 |
fi |
fi |
83 |
done << EOF |
done << EOF |
84 |
$(cat $file) |
$(cat ${file}) |
85 |
EOF |
EOF |
86 |
|
|
87 |
done |
done |
88 |
|
|
89 |
#reads special vars tmp files and writes them to /etc/profile.env |
# reads special vars tmp files and writes them to /etc/profile.env |
90 |
for i in $SPECIALVARS |
for i in ${SPECIALVARS} |
91 |
do |
do |
92 |
if [ -f /var/tmp/${i} ] |
if [ -f ${TMPDIR}/${i} ] |
93 |
then |
then |
94 |
# only OMF_DIR goes to /etc/scrollkeeper.conf |
# only OMF_DIR goes to /etc/scrollkeeper.conf |
95 |
if [[ ${i} = OMF_DIR ]] |
if [[ ${i} = OMF_DIR ]] |
96 |
then |
then |
97 |
echo "${i}=`cat /var/tmp/${i}`" > ${P}/etc/scrollkeeper.conf |
echo "${i}=$(cat ${TMPDIR}/${i})" > ${P}/etc/scrollkeeper.conf |
98 |
else |
else |
99 |
echo "export ${i}=\"`cat /var/tmp/${i}`\"" >> ${P}/etc/profile.env |
echo "export ${i}=\"$(cat ${TMPDIR}/${i})\"" >> ${P}/etc/profile.env |
100 |
fi |
fi |
101 |
rm /var/tmp/${i} |
rm ${TMPDIR}/${i} |
102 |
fi |
fi |
103 |
done |
done |
104 |
|
|
105 |
#rebuilds environment |
# rebuilds environment |
106 |
ldconfig |
ldconfig -r "${P}" -f /etc/ld.so.conf -C /etc/ld.so.cache |
107 |
source ${P}/etc/profile |
[ -f ${P}/etc/profile ] && source ${P}/etc/profile |
108 |
|
|
109 |
|
# cleanups |
110 |
|
[ -d ${TMPDIR} ] && rm -rf ${TMPDIR} |
111 |
|
|
112 |
echo -e "done.\n" |
echo -e "done.\n" |