Magellan Linux

Annotation of /branches/mage-next/src/env-rebuild.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1570 - (hide annotations) (download) (as text)
Wed Dec 28 10:26:01 2011 UTC (12 years, 4 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/env-rebuild.sh
File MIME type: application/x-sh
File size: 2618 byte(s)
-sanitized variable names and do not substitude everytime from new
1 niro 1565 #!/bin/bash
2     # $Id$
3 niro 24 #
4     # rebuilds /etc/{ld.so.conf,profile.env} with given files from /etc/env.d
5     #
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 1568 :> ${MROOT}/etc/ld.so.conf
25     :> ${MROOT}/etc/profile.env
26 niro 259
27 niro 1569 # read everything from /etc/env.d
28 niro 1568 for file in ${MROOT}/etc/env.d/*
29 niro 24 do
30 niro 259 # abort if "empty"
31 niro 1568 [[ ${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     # substitudes " from $line if exists
43     path="${line//\"}" #}" <--- make code readable again :)
44     value="${line##*=}"
45    
46     # writes LDPATH to ${MROOT}/etc/ld.so.conf,
47     # anything else to ${MROOT}/etc/profile.env
48     if [[ ${variable} = LDPATH ]]
49 niro 24 then
50 niro 1570 echo "${value}" >> ${MROOT}/etc/ld.so.conf
51 niro 259 else
52     # checks if var exists in specialvars
53     for i in ${SPECIALVARS}
54     do
55 niro 1570 [[ ${variable} = ${i} ]] && SPECVAR="yes"
56 niro 259 done
57    
58     if [[ ${SPECVAR} = yes ]]
59 niro 24 then
60 niro 1570 case ${variable} in
61 niro 1272 CONFIG_PROTECT*|XDG*)
62     # CONFIG_PROTECT*|XDG* have as delimiter not ':' but ' '
63 niro 1570 echo -n "${value} " >> ${TMPDIR}/${variable}
64 niro 1272 unset SPECVAR
65     ;;
66     *)
67 niro 1570 # special vars are written to tmpfile
68 niro 1272 # to substitude them to one variable
69 niro 1570 echo -n "${value}:" >> ${TMPDIR}/${variable}
70 niro 1272 unset SPECVAR
71     ;;
72     esac
73 niro 259 else
74     # all other vars go directly to /etc/profile.env
75 niro 1570 echo "export ${line}" >> ${MROOT}/etc/profile.env
76 niro 24 fi
77     fi
78     done << EOF
79 niro 223 $(cat ${file})
80 niro 24 EOF
81    
82     done
83    
84 niro 223 # reads special vars tmp files and writes them to /etc/profile.env
85 niro 1570 for variable in ${SPECIALVARS}
86 niro 24 do
87 niro 1570 if [ -f ${TMPDIR}/${variable} ]
88 niro 24 then
89 niro 55 # only OMF_DIR goes to /etc/scrollkeeper.conf
90 niro 1570 if [[ ${variable} = OMF_DIR ]]
91 niro 55 then
92 niro 1570 echo "${variable}=$(< ${TMPDIR}/${variable})" > ${MROOT}/etc/scrollkeeper.conf
93 niro 55 else
94 niro 1570 echo "export ${variable}=\"$(< ${TMPDIR}/${variable})\"" >> ${MROOT}/etc/profile.env
95 niro 55 fi
96 niro 1570 rm ${TMPDIR}/${variable}
97 niro 24 fi
98     done
99    
100 niro 223 # rebuilds environment
101 niro 1568 ldconfig -r "${MROOT}" -f /etc/ld.so.conf -C /etc/ld.so.cache
102     [ -f ${MROOT}/etc/profile ] && source ${MROOT}/etc/profile
103 niro 24
104 niro 259 # cleanups
105     [ -d ${TMPDIR} ] && rm -rf ${TMPDIR}
106    
107 niro 24 echo -e "done.\n"

Properties

Name Value
svn:executable *