Magellan Linux

Contents of /trunk/mage/usr/lib/mage/env-rebuild.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1568 - (show annotations) (download) (as text)
Wed Dec 28 10:16:42 2011 UTC (12 years, 4 months ago) by niro
File MIME type: application/x-sh
File size: 2684 byte(s)
-use MROOT directly instead of P alias
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 # gets everything in /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 path
35 do
36 # ignore if empty or a comment
37 case "${path}" in
38 \#*|"") continue ;;
39 esac
40
41 # writes LDPATH to ${P}/etc/ld.so.conf,
42 # anything else to ${P}/etc/profile.env
43 if [[ ${path%%=*} = LDPATH ]]
44 then
45 #substitudes " from $path if exists
46 path="${path//\"}" #}" <--- make code readable again :)
47 echo "${path##*=}" >> ${MROOT}/etc/ld.so.conf
48 else
49 # checks if var exists in specialvars
50 for i in ${SPECIALVARS}
51 do
52 [[ ${path%%=*} = ${i} ]] && SPECVAR="yes"
53 done
54
55 if [[ ${SPECVAR} = yes ]]
56 then
57 case ${path%%=*} in
58 CONFIG_PROTECT*|XDG*)
59 # CONFIG_PROTECT*|XDG* have as delimiter not ':' but ' '
60 path="${path//\"}" #}" <--- make code readable again :)
61 echo -n "${path##*=} " >> ${TMPDIR}/${path%%=*}
62 unset SPECVAR
63 ;;
64 *)
65 # special var are written to tmpfile
66 # to substitude them to one variable
67 # substitudes " from $path if exists
68 path="${path//\"}" #}" <--- make code readable again :)
69 echo -n "${path##*=}:" >> ${TMPDIR}/${path%%=*}
70 unset SPECVAR
71 ;;
72 esac
73 else
74 # all other vars go directly to /etc/profile.env
75 echo "export ${path}" >> ${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 i in ${SPECIALVARS}
86 do
87 if [ -f ${TMPDIR}/${i} ]
88 then
89 # only OMF_DIR goes to /etc/scrollkeeper.conf
90 if [[ ${i} = OMF_DIR ]]
91 then
92 echo "${i}=$(cat ${TMPDIR}/${i})" > ${MROOT}/etc/scrollkeeper.conf
93 else
94 echo "export ${i}=\"$(cat ${TMPDIR}/${i})\"" >> ${MROOT}/etc/profile.env
95 fi
96 rm ${TMPDIR}/${i}
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 *