Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *