Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *