Line 0
Link Here
|
|
|
1 |
#!/bin/bash |
2 |
# Daniel Casimiro <dan.casimiro@gmail.com> |
3 |
# |
4 |
|
5 |
# Emulates: hash[key]=value |
6 |
# * This function is from: |
7 |
# http://tldp.org/LDP/abs/html/contributed-scripts.html#HASHLIB |
8 |
# |
9 |
# Params: |
10 |
# 1 - hash |
11 |
# 2 - key |
12 |
# 3 - value |
13 |
function hash_set { |
14 |
eval "${Hash_config_varname_prefix}${1}_${2}=\"${3}\"" |
15 |
} |
16 |
|
17 |
# Emulates something similar to: |
18 |
# foreach($hash as $key => $value) { fun($key,$value); } |
19 |
# * This function is from: |
20 |
# http://tldp.org/LDP/abs/html/contributed-scripts.html#HASHLIB |
21 |
# |
22 |
# It is possible to write different variations of this function. |
23 |
# Here we use a function call to make it as "generic" as possible. |
24 |
# |
25 |
# Params: |
26 |
# 1 - hash |
27 |
# 2 - function name |
28 |
function hash_foreach { |
29 |
local keyname oldIFS="$IFS" |
30 |
IFS=' ' |
31 |
for i in $(eval "echo \${!${Hash_config_varname_prefix}${1}_*}"); do |
32 |
keyname=$(eval "echo \${i##${Hash_config_varname_prefix}${1}_}") |
33 |
eval "$2 $keyname \"\$$i\"" |
34 |
done |
35 |
IFS="$oldIFS" |
36 |
} |
37 |
|
38 |
# UnionFS requires different versions for different kernels. |
39 |
# This list is as of 27 October 2006. |
40 |
# Kernel Version Compatibility: |
41 |
# Kernel Version Unionfs Version |
42 |
# 2.4.x (x>19) 1.0.14 |
43 |
# 2.6.x (x<9) Not Supported |
44 |
# 2.6.9 - 2.6.15 1.1.5 |
45 |
# 2.6.16 1.2 |
46 |
# 2.6.17 1.3 |
47 |
# 2.6.18 1.4 |
48 |
# 2.6.newer CVS Snapshots |
49 |
|
50 |
# $1 unionfs version |
51 |
# $2 kernel version regular expression |
52 |
test_unionfs_version() { |
53 |
MYKV=`expr match "${KV}" $2` |
54 |
# this test can be improved... |
55 |
if [ ${MYKV} -gt 0 ]; then |
56 |
# The keys cannot contain '.', so underscores are substituted here. |
57 |
UNIONFS_VERSION=${1//_/.} |
58 |
fi |
59 |
} |
60 |
|
61 |
# set kernel versions regular expressions and unionfs versions in config file |
62 |
# build a hash that maps kernel version re's to unionfs version |
63 |
# for each hash key, use the value when the key regular expression evals |
64 |
# true when compared to ${BASEKV} |
65 |
get_unionfs_version() { |
66 |
# Do not support 2.4 kernels yet; just need another RE. |
67 |
# The hash is hard coded here, but it could be built from variables defined |
68 |
# in /etc/genkernel.conf |
69 |
hash_set unionfsversions 1_1_5 "2\.6\.\(\<1[0-5]\>\|9\)" |
70 |
hash_set unionfsversions 1_2 "2\.6\.16" |
71 |
hash_set unionfsversions 1_3 "2\.6\.17" |
72 |
hash_set unionfsversions 1_4 "2\.6\.18" |
73 |
|
74 |
# Unset the UNIONFS_VERSION that was set in /etc/genkernel.conf |
75 |
# This function could check if the variable is set, and then break |
76 |
# Or, it could use a different variable name |
77 |
UNIONFS_VERSION= |
78 |
hash_foreach unionfsversions test_unionfs_version |
79 |
|
80 |
if [ -z ${UNIONFS_VERSION} ]; then |
81 |
gen_die "${KV} is an invalid kernel for UNIONFS!" |
82 |
fi |
83 |
|
84 |
tmpunion=${UNIONFS_VERSION//./_} |
85 |
UNIONFS_COMPILE_FUNC=compile_unionfs_modules_${tmpunion:0:3} |
86 |
UNIONFS_COMPILE_UTILS_FUNC=compile_unionfs_utils_${tmpunion:0:3} |
87 |
} |
88 |
|
89 |
compile_unionfs_modules_1_1() { |
90 |
[ -f "${UNIONFS_SRCTAR}" ] || |
91 |
gen_die "Could not find unionfs source tarball: ${UNIONFS_SRCTAR}!" |
92 |
|
93 |
cd "${TEMP}" |
94 |
rm -rf ${UNIONFS_DIR} > /dev/null |
95 |
rm -rf unionfs > /dev/null |
96 |
mkdir -p unionfs |
97 |
/bin/tar -zxpf ${UNIONFS_SRCTAR} || |
98 |
gen_die 'Could not extract unionfs source tarball!' |
99 |
|
100 |
[ -d "${UNIONFS_DIR}" ] || |
101 |
gen_die 'Unionfs directory ${UNIONFS_DIR} is invalid!' |
102 |
cd "${UNIONFS_DIR}" |
103 |
print_info 1 'unionfs modules: >> Compiling...' |
104 |
echo "LINUXSRC=${KERNEL_DIR}" >> fistdev.mk |
105 |
echo 'TOPINC=-I$(LINUXSRC)/include' >> fistdev.mk |
106 |
echo "MODDIR= /lib/modules/${KV}" >> fistdev.mk |
107 |
echo "KERNELVERSION=${KV}" >> fistdev.mk |
108 |
# Fix for hardened/selinux systems to have extened attributes |
109 |
# per r2d2's request. Also add -DUNIONFS_UNSUPPORTED for 2.6.16 |
110 |
echo "EXTRACFLAGS=-DUNIONFS_XATTR -DFIST_SETXATTR_CONSTVOID -DUNIONFS_UNSUPPORTED" \ |
111 |
>> fistdev.mk |
112 |
# Here we do something really nasty and disable debugging, along with |
113 |
# change our default CFLAGS |
114 |
echo "UNIONFS_DEBUG_CFLAG=-DUNIONFS_NDEBUG" >> fistdev.mk |
115 |
echo "UNIONFS_OPT_CFLAG= -O2 -pipe" >> fistdev.mk |
116 |
|
117 |
if [ "${PAT}" -ge '6' ] |
118 |
then |
119 |
cd "${TEMP}" |
120 |
cd "${UNIONFS_DIR}" |
121 |
sed -i Makefile -e 's|-Werror||g' |
122 |
# Compile unionfs module within the unionfs |
123 |
# environment not within the kernelsrc dir |
124 |
make unionfs.ko || gen_die 'failed to compile unionfs' |
125 |
else |
126 |
gen_die 'unionfs is only supported on 2.6 targets' |
127 |
fi |
128 |
print_info 1 'unionfs: >> Copying to cache...' |
129 |
|
130 |
mkdir -p ${TEMP}/unionfs/lib/modules/${KV}/kernel/fs/unionfs |
131 |
|
132 |
if [ -f unionfs.ko ] |
133 |
then |
134 |
cp -f unionfs.ko ${TEMP}/unionfs/lib/modules/${KV}/kernel/fs/unionfs |
135 |
else |
136 |
cp -f unionfs.o ${TEMP}/unionfs/lib/modules/${KV}/kernel/fs/unionfs |
137 |
fi |
138 |
|
139 |
cd ${TEMP}/unionfs |
140 |
/bin/tar -cjf "${UNIONFS_MODULES_BINCACHE}" . || |
141 |
gen_die 'Could not create unionfs modules binary cache' |
142 |
|
143 |
cd "${TEMP}" |
144 |
rm -rf "${UNIONFS_DIR}" > /dev/null |
145 |
rm -rf unionfs > /dev/null |
146 |
} |
147 |
|
148 |
compile_unionfs_modules_1_2() { |
149 |
compile_unionfs_modules_1_1 |
150 |
} |
151 |
|
152 |
compile_unionfs_modules_1_3() { |
153 |
[ -f "${UNIONFS_SRCTAR}" ] || |
154 |
gen_die "Could not find unionfs source tarball: ${UNIONFS_SRCTAR}!" |
155 |
|
156 |
cd "${TEMP}" |
157 |
rm -rf ${UNIONFS_DIR} > /dev/null |
158 |
rm -rf unionfs* > /dev/null |
159 |
mkdir unionfs |
160 |
/bin/tar xzpf ${UNIONFS_SRCTAR} || |
161 |
gen_die 'Could not extract unionfs source tarball!' |
162 |
|
163 |
[ -d "${UNIONFS_DIR}" ] || |
164 |
gen_die 'Unionfs directory ${UNIONFS_DIR} is invalid!' |
165 |
cd "${UNIONFS_DIR}" |
166 |
print_info 1 'unionfs modules: >> Compiling...' |
167 |
echo "LINUXSRC=${KERNEL_DIR}" >> fistdev.mk |
168 |
echo 'TOPINC=-I$(LINUXSRC)/include' >> fistdev.mk |
169 |
echo "MODDIR= /lib/modules/${KV}" >> fistdev.mk |
170 |
echo "KVERS=${KV}" >> fistdev.mk |
171 |
echo "KERNELVERSION=${KV}" >> fistdev.mk |
172 |
# Fix for hardened/selinux systems to have extened attributes |
173 |
# per r2d2's request. Also add -DUNIONFS_UNSUPPORTED for 2.6.16 |
174 |
echo "EXTRACFLAGS=-DUNIONFS_XATTR -DFIST_SETXATTR_CONSTVOID -DUNIONFS_UNSUPPORTED" \ |
175 |
>> fistdev.mk |
176 |
# Here we do something really nasty and disable debugging, along with |
177 |
# change our default CFLAGS |
178 |
echo "UNIONFS_DEBUG_CFLAG=-DUNIONFS_NDEBUG" >> fistdev.mk |
179 |
echo "UNIONFS_OPT_CFLAG= -O2 -pipe" >> fistdev.mk |
180 |
|
181 |
if [ "${PAT}" -ge '6' ] |
182 |
then |
183 |
# ARCH is used by unionfs - and conflicts with genkernel |
184 |
ARCH_PUSH=${ARCH} |
185 |
unset ARCH |
186 |
#sed -i Makefile -e 's|-Werror||g' |
187 |
# Compile unionfs module within the unionfs |
188 |
# environment not within the kernelsrc dir |
189 |
make unionfs.ko || gen_die 'failed to compile unionfs' |
190 |
ARCH=${ARCH_PUSH} |
191 |
else |
192 |
gen_die 'unionfs is only supported on 2.6 targets' |
193 |
fi |
194 |
print_info 1 'unionfs: >> Copying to cache...' |
195 |
|
196 |
mkdir -p ${TEMP}/unionfs/lib/modules/${KV}/kernel/fs/unionfs |
197 |
|
198 |
if [ -f unionfs.ko ] |
199 |
then |
200 |
cp -f unionfs.ko ${TEMP}/unionfs/lib/modules/${KV}/kernel/fs/unionfs |
201 |
else |
202 |
cp -f unionfs.o ${TEMP}/unionfs/lib/modules/${KV}/kernel/fs/unionfs |
203 |
fi |
204 |
|
205 |
cd ${TEMP}/unionfs |
206 |
/bin/tar -cjf "${UNIONFS_MODULES_BINCACHE}" . || |
207 |
gen_die 'Could not create unionfs modules binary cache' |
208 |
|
209 |
cd "${TEMP}" |
210 |
rm -rf "${UNIONFS_DIR}" > /dev/null |
211 |
rm -rf unionfs* > /dev/null |
212 |
} |
213 |
|
214 |
compile_unionfs_modules_1_4() { |
215 |
compile_unionfs_modules_1_3 |
216 |
} |
217 |
|
218 |
# uniofs_utils |
219 |
compile_unionfs_utils_1_1() { |
220 |
if [ ! -f "${UNIONFS_BINCACHE}" ] |
221 |
then |
222 |
[ -f "${UNIONFS_SRCTAR}" ] || |
223 |
gen_die "Could not find unionfs source tarball: ${UNIONFS_SRCTAR}!" |
224 |
cd "${TEMP}" |
225 |
rm -rf ${UNIONFS_DIR} > /dev/null |
226 |
rm -rf unionfs > /dev/null |
227 |
mkdir -p unionfs/sbin |
228 |
/bin/tar -zxpf ${UNIONFS_SRCTAR} || |
229 |
gen_die 'Could not extract unionfs source tarball!' |
230 |
[ -d "${UNIONFS_DIR}" ] || |
231 |
gen_die 'Unionfs directory ${UNIONFS_DIR} is invalid!' |
232 |
cd "${UNIONFS_DIR}" |
233 |
print_info 1 'unionfs tools: >> Compiling...' |
234 |
sed -i Makefile -e 's|${CC} -o|${CC} -static -o|g' |
235 |
compile_generic utils utils |
236 |
|
237 |
print_info 1 'unionfs: >> Copying to cache...' |
238 |
strip uniondbg unionctl |
239 |
cp uniondbg ${TEMP}/unionfs/sbin/ || |
240 |
gen_die 'Could not copy the uniondbg binary to the tmp directory' |
241 |
cp unionctl ${TEMP}/unionfs/sbin/ || |
242 |
gen_die 'Could not copy the unionctl binary to the tmp directory' |
243 |
cd ${TEMP}/unionfs |
244 |
/bin/tar -cjf "${UNIONFS_BINCACHE}" . || |
245 |
gen_die 'Could not create unionfs tools binary cache' |
246 |
|
247 |
cd "${TEMP}" |
248 |
rm -rf "${UNIONFS_DIR}" > /dev/null |
249 |
rm -rf unionfs > /dev/null |
250 |
fi |
251 |
} |
252 |
|
253 |
compile_unionfs_utils_1_2() { |
254 |
compile_unionfs_utils_1_1 |
255 |
} |
256 |
|
257 |
compile_unionfs_utils_1_3() { |
258 |
if [ ! -f "${UNIONFS_BINCACHE}" ] |
259 |
then |
260 |
[ -f "${UNIONFS_SRCTAR}" ] || |
261 |
gen_die "Could not find unionfs source tarball: ${UNIONFS_SRCTAR}!" |
262 |
cd "${TEMP}" |
263 |
rm -rf ${UNIONFS_DIR} > /dev/null |
264 |
rm -rf unionfs > /dev/null |
265 |
mkdir -p unionfs/sbin |
266 |
/bin/tar -zxpf ${UNIONFS_SRCTAR} || |
267 |
gen_die 'Could not extract unionfs source tarball!' |
268 |
[ -d "${UNIONFS_DIR}" ] || |
269 |
gen_die 'Unionfs directory ${UNIONFS_DIR} is invalid!' |
270 |
cd "${UNIONFS_DIR}" |
271 |
print_info 1 'unionfs tools: >> Compiling...' |
272 |
sed -i utils/Makefile -e 's|${CC} -o|${CC} -static -o|g' |
273 |
sed -i Makefile -e 's|${CC} -o|${CC} -static -o|g' |
274 |
compile_generic utils utils |
275 |
|
276 |
print_info 1 'moving into utils directory...' |
277 |
cd utils |
278 |
|
279 |
print_info 1 'unionfs: >> Copying to cache...' |
280 |
strip uniondbg unionctl |
281 |
cp uniondbg ${TEMP}/unionfs/sbin/ || |
282 |
gen_die 'Could not copy the uniondbg binary to the tmp directory' |
283 |
cp unionctl ${TEMP}/unionfs/sbin/ || |
284 |
gen_die 'Could not copy the unionctl binary to the tmp directory' |
285 |
cd ${TEMP}/unionfs |
286 |
/bin/tar -cjf "${UNIONFS_BINCACHE}" . || |
287 |
gen_die 'Could not create unionfs tools binary cache' |
288 |
|
289 |
cd "${TEMP}" |
290 |
rm -rf "${UNIONFS_DIR}" > /dev/null |
291 |
rm -rf unionfs > /dev/null |
292 |
fi |
293 |
} |
294 |
|
295 |
compile_unionfs_utils_1_4() { |
296 |
compile_unionfs_utils_1_3 |
297 |
} |