Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 942 - (show annotations) (download) (as text)
Fri Nov 20 21:53:33 2009 UTC (14 years, 5 months ago) by niro
File MIME type: application/x-sh
File size: 2861 byte(s)
-support CONFIG_PROTECT target CONFIG_PROTECT_IGNORE to keep user/system modified config files, like passwd
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"
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 # abort if empty or an 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 if [[ ${path%%=*} = CONFIG_PROTECT ]] || [[ ${path%%=*} = CONFIG_PROTECT_MASK ]] || [[ ${path%%=*} = CONFIG_PROTECT_IGNORE ]]
67 then
68 # CONFIG_PROTECTS has as delimiter not ':' but ' '
69 path="${path//\"}" #}" <--- make code readable again :)
70 echo -n "${path##*=} " >> ${TMPDIR}/${path%%=*}
71 unset SPECVAR
72 else
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 fi
80 else
81 # all other vars go directly to /etc/profile.env
82 echo "export ${path}" >> ${P}/etc/profile.env
83 fi
84 fi
85 done << EOF
86 $(cat ${file})
87 EOF
88
89 done
90
91 # reads special vars tmp files and writes them to /etc/profile.env
92 for i in ${SPECIALVARS}
93 do
94 if [ -f ${TMPDIR}/${i} ]
95 then
96 # only OMF_DIR goes to /etc/scrollkeeper.conf
97 if [[ ${i} = OMF_DIR ]]
98 then
99 echo "${i}=$(cat ${TMPDIR}/${i})" > ${P}/etc/scrollkeeper.conf
100 else
101 echo "export ${i}=\"$(cat ${TMPDIR}/${i})\"" >> ${P}/etc/profile.env
102 fi
103 rm ${TMPDIR}/${i}
104 fi
105 done
106
107 # rebuilds environment
108 ldconfig -r "${P}" -f /etc/ld.so.conf -C /etc/ld.so.cache
109 [ -f ${P}/etc/profile ] && source ${P}/etc/profile
110
111 # cleanups
112 [ -d ${TMPDIR} ] && rm -rf ${TMPDIR}
113
114 echo -e "done.\n"

Properties

Name Value
svn:executable *