Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 456 - (show annotations) (download) (as text)
Sun Apr 1 01:26:34 2007 UTC (17 years, 1 month ago) by niro
Original Path: trunk/mage/usr/lib/mage/env-rebuild.sh
File MIME type: application/x-sh
File size: 2854 byte(s)
fixed env-rebuild, do not include comments

1 #!/bin/sh
2
3 # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/env-rebuild.sh,v 1.12 2007-04-01 01:26:34 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 PRELINK_PATH PRELINK_PATH_MASK OMF_DIR"
20 #SPECIALVARS="KDEDIRS PATH LDPATH MANPATH INFODIR INFOPATH ROOTPATH CLASSPATH"
21
22 # secure tmp dir
23 if [ -x /bin/mktemp ]
24 then
25 TMPDIR="$(/bin/mktemp -d -p /var/tmp)"
26 else
27 TMPDIR="/var/tmp/tmp.$$"
28 install -d ${TMPDIR}
29 fi
30
31 echo -en "\n>>>> Rebuilding environment... "
32
33 # clean existing conf files
34 :> ${P}/etc/ld.so.conf
35 :> ${P}/etc/profile.env
36
37 # gets everything in /etc/env.d
38 for file in ${P}/etc/env.d/*
39 do
40 # abort if "empty"
41 [[ ${file} = ${P}/etc/env.d/\* ]] && continue
42
43 # reads content of every file
44 while read path
45 do
46 # abort if empty or an comment
47 case "${path}" in
48 \#*|"") continue ;;
49 esac
50
51 # writes LDPATH to ${P}/etc/ld.so.conf,
52 # anything else to ${P}/etc/profile.env
53 if [[ ${path%%=*} = LDPATH ]]
54 then
55 #substitudes " from $path if exists
56 path="${path//\"}" #}" <--- make code readable again :)
57 echo "${path##*=}" >> ${P}/etc/ld.so.conf
58 else
59 # checks if var exists in specialvars
60 for i in ${SPECIALVARS}
61 do
62 [[ ${path%%=*} = ${i} ]] && SPECVAR="yes"
63 done
64
65 if [[ ${SPECVAR} = yes ]]
66 then
67 if [[ ${path%%=*} = CONFIG_PROTECT ]] || [[ ${path%%=*} = CONFIG_PROTECT_MASK ]]
68 then
69 # CONFIG_PROTECTS has as delimiter not ':' but ' '
70 path="${path//\"}" #}" <--- make code readable again :)
71 echo -n "${path##*=} " >> ${TMPDIR}/${path%%=*}
72 unset SPECVAR
73 else
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 fi
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 *