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