Annotation of /trunk/mage/usr/lib/mage/env-rebuild.sh
Parent Directory | Revision Log
Revision 1565 -
(hide annotations)
(download)
(as text)
Wed Dec 28 10:11:19 2011 UTC (12 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 2727 byte(s)
Wed Dec 28 10:11:19 2011 UTC (12 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 2727 byte(s)
-fixed header
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 | ## | ||
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 | niro | 223 | # sets root path |
17 | P="${MROOT}" | ||
18 | niro | 1272 | 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 | niro | 24 | |
20 | niro | 259 | # secure tmp dir |
21 | if [ -x /bin/mktemp ] | ||
22 | niro | 24 | then |
23 | niro | 259 | TMPDIR="$(/bin/mktemp -d -p /var/tmp)" |
24 | else | ||
25 | TMPDIR="/var/tmp/tmp.$$" | ||
26 | niro | 285 | install -d ${TMPDIR} |
27 | niro | 24 | fi |
28 | |||
29 | niro | 259 | echo -en "\n>>>> Rebuilding environment... " |
30 | niro | 24 | |
31 | niro | 259 | # clean existing conf files |
32 | :> ${P}/etc/ld.so.conf | ||
33 | :> ${P}/etc/profile.env | ||
34 | |||
35 | niro | 223 | # gets everything in /etc/env.d |
36 | niro | 24 | for file in ${P}/etc/env.d/* |
37 | do | ||
38 | niro | 259 | # abort if "empty" |
39 | niro | 260 | [[ ${file} = ${P}/etc/env.d/\* ]] && continue |
40 | niro | 259 | |
41 | niro | 223 | # reads content of every file |
42 | niro | 24 | while read path |
43 | do | ||
44 | niro | 1272 | # ignore if empty or a comment |
45 | niro | 456 | case "${path}" in |
46 | \#*|"") continue ;; | ||
47 | esac | ||
48 | niro | 259 | |
49 | # writes LDPATH to ${P}/etc/ld.so.conf, | ||
50 | # anything else to ${P}/etc/profile.env | ||
51 | if [[ ${path%%=*} = LDPATH ]] | ||
52 | niro | 24 | then |
53 | niro | 259 | #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 | niro | 24 | then |
65 | niro | 1272 | 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 | niro | 259 | else |
82 | # all other vars go directly to /etc/profile.env | ||
83 | echo "export ${path}" >> ${P}/etc/profile.env | ||
84 | niro | 24 | fi |
85 | fi | ||
86 | done << EOF | ||
87 | niro | 223 | $(cat ${file}) |
88 | niro | 24 | EOF |
89 | |||
90 | done | ||
91 | |||
92 | niro | 223 | # reads special vars tmp files and writes them to /etc/profile.env |
93 | for i in ${SPECIALVARS} | ||
94 | niro | 24 | do |
95 | niro | 259 | if [ -f ${TMPDIR}/${i} ] |
96 | niro | 24 | then |
97 | niro | 55 | # only OMF_DIR goes to /etc/scrollkeeper.conf |
98 | if [[ ${i} = OMF_DIR ]] | ||
99 | then | ||
100 | niro | 259 | echo "${i}=$(cat ${TMPDIR}/${i})" > ${P}/etc/scrollkeeper.conf |
101 | niro | 55 | else |
102 | niro | 259 | echo "export ${i}=\"$(cat ${TMPDIR}/${i})\"" >> ${P}/etc/profile.env |
103 | niro | 55 | fi |
104 | niro | 259 | rm ${TMPDIR}/${i} |
105 | niro | 24 | fi |
106 | done | ||
107 | |||
108 | niro | 223 | # rebuilds environment |
109 | ldconfig -r "${P}" -f /etc/ld.so.conf -C /etc/ld.so.cache | ||
110 | niro | 259 | [ -f ${P}/etc/profile ] && source ${P}/etc/profile |
111 | niro | 24 | |
112 | niro | 259 | # cleanups |
113 | [ -d ${TMPDIR} ] && rm -rf ${TMPDIR} | ||
114 | |||
115 | niro | 24 | echo -e "done.\n" |
Properties
Name | Value |
---|---|
svn:executable | * |