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