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