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