Contents of /trunk/mage/usr/lib/mage/env-rebuild.sh
Parent Directory | Revision Log
Revision 1570 -
(show annotations)
(download)
(as text)
Wed Dec 28 10:26:01 2011 UTC (12 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 2618 byte(s)
Wed Dec 28 10:26:01 2011 UTC (12 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 2618 byte(s)
-sanitized variable names and do not substitude everytime from new
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 | # substitudes " from $line if exists |
43 | 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 |
50 | echo "${value}" >> ${MROOT}/etc/ld.so.conf |
51 | else |
52 | # checks if var exists in specialvars |
53 | for i in ${SPECIALVARS} |
54 | do |
55 | [[ ${variable} = ${i} ]] && SPECVAR="yes" |
56 | done |
57 | |
58 | if [[ ${SPECVAR} = yes ]] |
59 | then |
60 | case ${variable} in |
61 | CONFIG_PROTECT*|XDG*) |
62 | # CONFIG_PROTECT*|XDG* have as delimiter not ':' but ' ' |
63 | echo -n "${value} " >> ${TMPDIR}/${variable} |
64 | unset SPECVAR |
65 | ;; |
66 | *) |
67 | # special vars are written to tmpfile |
68 | # to substitude them to one variable |
69 | echo -n "${value}:" >> ${TMPDIR}/${variable} |
70 | unset SPECVAR |
71 | ;; |
72 | esac |
73 | else |
74 | # all other vars go directly to /etc/profile.env |
75 | echo "export ${line}" >> ${MROOT}/etc/profile.env |
76 | fi |
77 | fi |
78 | done << EOF |
79 | $(cat ${file}) |
80 | EOF |
81 | |
82 | done |
83 | |
84 | # reads special vars tmp files and writes them to /etc/profile.env |
85 | for variable in ${SPECIALVARS} |
86 | do |
87 | if [ -f ${TMPDIR}/${variable} ] |
88 | then |
89 | # only OMF_DIR goes to /etc/scrollkeeper.conf |
90 | if [[ ${variable} = OMF_DIR ]] |
91 | then |
92 | echo "${variable}=$(< ${TMPDIR}/${variable})" > ${MROOT}/etc/scrollkeeper.conf |
93 | else |
94 | echo "export ${variable}=\"$(< ${TMPDIR}/${variable})\"" >> ${MROOT}/etc/profile.env |
95 | fi |
96 | rm ${TMPDIR}/${variable} |
97 | fi |
98 | done |
99 | |
100 | # rebuilds environment |
101 | ldconfig -r "${MROOT}" -f /etc/ld.so.conf -C /etc/ld.so.cache |
102 | [ -f ${MROOT}/etc/profile ] && source ${MROOT}/etc/profile |
103 | |
104 | # cleanups |
105 | [ -d ${TMPDIR} ] && rm -rf ${TMPDIR} |
106 | |
107 | echo -e "done.\n" |
Properties
Name | Value |
---|---|
svn:executable | * |