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