Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1272 - (hide 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 niro 24 #!/bin/sh
2    
3 niro 503 # $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 niro 24 #
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 niro 223 # sets root path
18     P="${MROOT}"
19 niro 1272 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 niro 24
21 niro 259 # secure tmp dir
22     if [ -x /bin/mktemp ]
23 niro 24 then
24 niro 259 TMPDIR="$(/bin/mktemp -d -p /var/tmp)"
25     else
26     TMPDIR="/var/tmp/tmp.$$"
27 niro 285 install -d ${TMPDIR}
28 niro 24 fi
29    
30 niro 259 echo -en "\n>>>> Rebuilding environment... "
31 niro 24
32 niro 259 # clean existing conf files
33     :> ${P}/etc/ld.so.conf
34     :> ${P}/etc/profile.env
35    
36 niro 223 # gets everything in /etc/env.d
37 niro 24 for file in ${P}/etc/env.d/*
38     do
39 niro 259 # abort if "empty"
40 niro 260 [[ ${file} = ${P}/etc/env.d/\* ]] && continue
41 niro 259
42 niro 223 # reads content of every file
43 niro 24 while read path
44     do
45 niro 1272 # ignore if empty or a comment
46 niro 456 case "${path}" in
47     \#*|"") continue ;;
48     esac
49 niro 259
50     # writes LDPATH to ${P}/etc/ld.so.conf,
51     # anything else to ${P}/etc/profile.env
52     if [[ ${path%%=*} = LDPATH ]]
53 niro 24 then
54 niro 259 #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 niro 24 then
66 niro 1272 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 niro 259 else
83     # all other vars go directly to /etc/profile.env
84     echo "export ${path}" >> ${P}/etc/profile.env
85 niro 24 fi
86     fi
87     done << EOF
88 niro 223 $(cat ${file})
89 niro 24 EOF
90    
91     done
92    
93 niro 223 # reads special vars tmp files and writes them to /etc/profile.env
94     for i in ${SPECIALVARS}
95 niro 24 do
96 niro 259 if [ -f ${TMPDIR}/${i} ]
97 niro 24 then
98 niro 55 # only OMF_DIR goes to /etc/scrollkeeper.conf
99     if [[ ${i} = OMF_DIR ]]
100     then
101 niro 259 echo "${i}=$(cat ${TMPDIR}/${i})" > ${P}/etc/scrollkeeper.conf
102 niro 55 else
103 niro 259 echo "export ${i}=\"$(cat ${TMPDIR}/${i})\"" >> ${P}/etc/profile.env
104 niro 55 fi
105 niro 259 rm ${TMPDIR}/${i}
106 niro 24 fi
107     done
108    
109 niro 223 # rebuilds environment
110     ldconfig -r "${P}" -f /etc/ld.so.conf -C /etc/ld.so.cache
111 niro 259 [ -f ${P}/etc/profile ] && source ${P}/etc/profile
112 niro 24
113 niro 259 # cleanups
114     [ -d ${TMPDIR} ] && rm -rf ${TMPDIR}
115    
116 niro 24 echo -e "done.\n"

Properties

Name Value
svn:executable *