Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *