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