|
|
|
#!/bin/bash |
|
# Daniel Casimiro <dan.casimiro@gmail.com> |
|
# |
|
|
|
# Emulates: hash[key]=value |
|
# * This function is from: |
|
# http://tldp.org/LDP/abs/html/contributed-scripts.html#HASHLIB |
|
# |
|
# Params: |
|
# 1 - hash |
|
# 2 - key |
|
# 3 - value |
|
function hash_set { |
|
eval "${Hash_config_varname_prefix}${1}_${2}=\"${3}\"" |
|
} |
|
|
|
# Emulates something similar to: |
|
# foreach($hash as $key => $value) { fun($key,$value); } |
|
# * This function is from: |
|
# http://tldp.org/LDP/abs/html/contributed-scripts.html#HASHLIB |
|
# |
|
# It is possible to write different variations of this function. |
|
# Here we use a function call to make it as "generic" as possible. |
|
# |
|
# Params: |
|
# 1 - hash |
|
# 2 - function name |
|
function hash_foreach { |
|
local keyname oldIFS="$IFS" |
|
IFS=' ' |
|
for i in $(eval "echo \${!${Hash_config_varname_prefix}${1}_*}"); do |
|
keyname=$(eval "echo \${i##${Hash_config_varname_prefix}${1}_}") |
|
eval "$2 $keyname \"\$$i\"" |
|
done |
|
IFS="$oldIFS" |
|
} |
|
|
|
# UnionFS requires different versions for different kernels. |
|
# This list is as of 27 October 2006. |
|
# Kernel Version Compatibility: |
|
# Kernel Version Unionfs Version |
|
# 2.4.x (x>19) 1.0.14 |
|
# 2.6.x (x<9) Not Supported |
|
# 2.6.9 - 2.6.15 1.1.5 |
|
# 2.6.16 1.2 |
|
# 2.6.17 1.3 |
|
# 2.6.18 1.4 |
|
# 2.6.newer CVS Snapshots |
|
|
|
# $1 unionfs version |
|
# $2 kernel version regular expression |
|
test_unionfs_version() { |
|
MYKV=`expr match "${KV}" $2` |
|
# this test can be improved... |
|
if [ ${MYKV} -gt 0 ]; then |
|
# The keys cannot contain '.', so underscores are substituted here. |
|
UNIONFS_VERSION=${1//_/.} |
|
fi |
|
} |
|
|
|
# set kernel versions regular expressions and unionfs versions in config file |
|
# build a hash that maps kernel version re's to unionfs version |
|
# for each hash key, use the value when the key regular expression evals |
|
# true when compared to ${BASEKV} |
|
get_unionfs_version() { |
|
# Do not support 2.4 kernels yet; just need another RE. |
|
# The hash is hard coded here, but it could be built from variables defined |
|
# in /etc/genkernel.conf |
|
hash_set unionfsversions 1_1_5 "2\.6\.\(\<1[0-5]\>\|9\)" |
|
hash_set unionfsversions 1_2 "2\.6\.16" |
|
hash_set unionfsversions 1_3 "2\.6\.17" |
|
hash_set unionfsversions 1_4 "2\.6\.18" |
|
|
|
# Unset the UNIONFS_VERSION that was set in /etc/genkernel.conf |
|
# This function could check if the variable is set, and then break |
|
# Or, it could use a different variable name |
|
UNIONFS_VERSION= |
|
hash_foreach unionfsversions test_unionfs_version |
|
|
|
if [ -z ${UNIONFS_VERSION} ]; then |
|
gen_die "${KV} is an invalid kernel for UNIONFS!" |
|
fi |
|
|
|
tmpunion=${UNIONFS_VERSION//./_} |
|
UNIONFS_COMPILE_FUNC=compile_unionfs_modules_${tmpunion:0:3} |
|
UNIONFS_COMPILE_UTILS_FUNC=compile_unionfs_utils_${tmpunion:0:3} |
|
} |
|
|
|
compile_unionfs_modules_1_1() { |
|
[ -f "${UNIONFS_SRCTAR}" ] || |
|
gen_die "Could not find unionfs source tarball: ${UNIONFS_SRCTAR}!" |
|
|
|
cd "${TEMP}" |
|
rm -rf ${UNIONFS_DIR} > /dev/null |
|
rm -rf unionfs > /dev/null |
|
mkdir -p unionfs |
|
/bin/tar -zxpf ${UNIONFS_SRCTAR} || |
|
gen_die 'Could not extract unionfs source tarball!' |
|
|
|
[ -d "${UNIONFS_DIR}" ] || |
|
gen_die 'Unionfs directory ${UNIONFS_DIR} is invalid!' |
|
cd "${UNIONFS_DIR}" |
|
print_info 1 'unionfs modules: >> Compiling...' |
|
echo "LINUXSRC=${KERNEL_DIR}" >> fistdev.mk |
|
echo 'TOPINC=-I$(LINUXSRC)/include' >> fistdev.mk |
|
echo "MODDIR= /lib/modules/${KV}" >> fistdev.mk |
|
echo "KERNELVERSION=${KV}" >> fistdev.mk |
|
# Fix for hardened/selinux systems to have extened attributes |
|
# per r2d2's request. Also add -DUNIONFS_UNSUPPORTED for 2.6.16 |
|
echo "EXTRACFLAGS=-DUNIONFS_XATTR -DFIST_SETXATTR_CONSTVOID -DUNIONFS_UNSUPPORTED" \ |
|
>> fistdev.mk |
|
# Here we do something really nasty and disable debugging, along with |
|
# change our default CFLAGS |
|
echo "UNIONFS_DEBUG_CFLAG=-DUNIONFS_NDEBUG" >> fistdev.mk |
|
echo "UNIONFS_OPT_CFLAG= -O2 -pipe" >> fistdev.mk |
|
|
|
if [ "${PAT}" -ge '6' ] |
|
then |
|
cd "${TEMP}" |
|
cd "${UNIONFS_DIR}" |
|
sed -i Makefile -e 's|-Werror||g' |
|
# Compile unionfs module within the unionfs |
|
# environment not within the kernelsrc dir |
|
make unionfs.ko || gen_die 'failed to compile unionfs' |
|
else |
|
gen_die 'unionfs is only supported on 2.6 targets' |
|
fi |
|
print_info 1 'unionfs: >> Copying to cache...' |
|
|
|
mkdir -p ${TEMP}/unionfs/lib/modules/${KV}/kernel/fs/unionfs |
|
|
|
if [ -f unionfs.ko ] |
|
then |
|
cp -f unionfs.ko ${TEMP}/unionfs/lib/modules/${KV}/kernel/fs/unionfs |
|
else |
|
cp -f unionfs.o ${TEMP}/unionfs/lib/modules/${KV}/kernel/fs/unionfs |
|
fi |
|
|
|
cd ${TEMP}/unionfs |
|
/bin/tar -cjf "${UNIONFS_MODULES_BINCACHE}" . || |
|
gen_die 'Could not create unionfs modules binary cache' |
|
|
|
cd "${TEMP}" |
|
rm -rf "${UNIONFS_DIR}" > /dev/null |
|
rm -rf unionfs > /dev/null |
|
} |
|
|
|
compile_unionfs_modules_1_2() { |
|
compile_unionfs_modules_1_1 |
|
} |
|
|
|
compile_unionfs_modules_1_3() { |
|
[ -f "${UNIONFS_SRCTAR}" ] || |
|
gen_die "Could not find unionfs source tarball: ${UNIONFS_SRCTAR}!" |
|
|
|
cd "${TEMP}" |
|
rm -rf ${UNIONFS_DIR} > /dev/null |
|
rm -rf unionfs* > /dev/null |
|
mkdir unionfs |
|
/bin/tar xzpf ${UNIONFS_SRCTAR} || |
|
gen_die 'Could not extract unionfs source tarball!' |
|
|
|
[ -d "${UNIONFS_DIR}" ] || |
|
gen_die 'Unionfs directory ${UNIONFS_DIR} is invalid!' |
|
cd "${UNIONFS_DIR}" |
|
print_info 1 'unionfs modules: >> Compiling...' |
|
echo "LINUXSRC=${KERNEL_DIR}" >> fistdev.mk |
|
echo 'TOPINC=-I$(LINUXSRC)/include' >> fistdev.mk |
|
echo "MODDIR= /lib/modules/${KV}" >> fistdev.mk |
|
echo "KVERS=${KV}" >> fistdev.mk |
|
echo "KERNELVERSION=${KV}" >> fistdev.mk |
|
# Fix for hardened/selinux systems to have extened attributes |
|
# per r2d2's request. Also add -DUNIONFS_UNSUPPORTED for 2.6.16 |
|
echo "EXTRACFLAGS=-DUNIONFS_XATTR -DFIST_SETXATTR_CONSTVOID -DUNIONFS_UNSUPPORTED" \ |
|
>> fistdev.mk |
|
# Here we do something really nasty and disable debugging, along with |
|
# change our default CFLAGS |
|
echo "UNIONFS_DEBUG_CFLAG=-DUNIONFS_NDEBUG" >> fistdev.mk |
|
echo "UNIONFS_OPT_CFLAG= -O2 -pipe" >> fistdev.mk |
|
|
|
if [ "${PAT}" -ge '6' ] |
|
then |
|
# ARCH is used by unionfs - and conflicts with genkernel |
|
ARCH_PUSH=${ARCH} |
|
unset ARCH |
|
#sed -i Makefile -e 's|-Werror||g' |
|
# Compile unionfs module within the unionfs |
|
# environment not within the kernelsrc dir |
|
make unionfs.ko || gen_die 'failed to compile unionfs' |
|
ARCH=${ARCH_PUSH} |
|
else |
|
gen_die 'unionfs is only supported on 2.6 targets' |
|
fi |
|
print_info 1 'unionfs: >> Copying to cache...' |
|
|
|
mkdir -p ${TEMP}/unionfs/lib/modules/${KV}/kernel/fs/unionfs |
|
|
|
if [ -f unionfs.ko ] |
|
then |
|
cp -f unionfs.ko ${TEMP}/unionfs/lib/modules/${KV}/kernel/fs/unionfs |
|
else |
|
cp -f unionfs.o ${TEMP}/unionfs/lib/modules/${KV}/kernel/fs/unionfs |
|
fi |
|
|
|
cd ${TEMP}/unionfs |
|
/bin/tar -cjf "${UNIONFS_MODULES_BINCACHE}" . || |
|
gen_die 'Could not create unionfs modules binary cache' |
|
|
|
cd "${TEMP}" |
|
rm -rf "${UNIONFS_DIR}" > /dev/null |
|
rm -rf unionfs* > /dev/null |
|
} |
|
|
|
compile_unionfs_modules_1_4() { |
|
compile_unionfs_modules_1_3 |
|
} |
|
|
|
# uniofs_utils |
|
compile_unionfs_utils_1_1() { |
|
if [ ! -f "${UNIONFS_BINCACHE}" ] |
|
then |
|
[ -f "${UNIONFS_SRCTAR}" ] || |
|
gen_die "Could not find unionfs source tarball: ${UNIONFS_SRCTAR}!" |
|
cd "${TEMP}" |
|
rm -rf ${UNIONFS_DIR} > /dev/null |
|
rm -rf unionfs > /dev/null |
|
mkdir -p unionfs/sbin |
|
/bin/tar -zxpf ${UNIONFS_SRCTAR} || |
|
gen_die 'Could not extract unionfs source tarball!' |
|
[ -d "${UNIONFS_DIR}" ] || |
|
gen_die 'Unionfs directory ${UNIONFS_DIR} is invalid!' |
|
cd "${UNIONFS_DIR}" |
|
print_info 1 'unionfs tools: >> Compiling...' |
|
sed -i Makefile -e 's|${CC} -o|${CC} -static -o|g' |
|
compile_generic utils utils |
|
|
|
print_info 1 'unionfs: >> Copying to cache...' |
|
strip uniondbg unionctl |
|
cp uniondbg ${TEMP}/unionfs/sbin/ || |
|
gen_die 'Could not copy the uniondbg binary to the tmp directory' |
|
cp unionctl ${TEMP}/unionfs/sbin/ || |
|
gen_die 'Could not copy the unionctl binary to the tmp directory' |
|
cd ${TEMP}/unionfs |
|
/bin/tar -cjf "${UNIONFS_BINCACHE}" . || |
|
gen_die 'Could not create unionfs tools binary cache' |
|
|
|
cd "${TEMP}" |
|
rm -rf "${UNIONFS_DIR}" > /dev/null |
|
rm -rf unionfs > /dev/null |
|
fi |
|
} |
|
|
|
compile_unionfs_utils_1_2() { |
|
compile_unionfs_utils_1_1 |
|
} |
|
|
|
compile_unionfs_utils_1_3() { |
|
if [ ! -f "${UNIONFS_BINCACHE}" ] |
|
then |
|
[ -f "${UNIONFS_SRCTAR}" ] || |
|
gen_die "Could not find unionfs source tarball: ${UNIONFS_SRCTAR}!" |
|
cd "${TEMP}" |
|
rm -rf ${UNIONFS_DIR} > /dev/null |
|
rm -rf unionfs > /dev/null |
|
mkdir -p unionfs/sbin |
|
/bin/tar -zxpf ${UNIONFS_SRCTAR} || |
|
gen_die 'Could not extract unionfs source tarball!' |
|
[ -d "${UNIONFS_DIR}" ] || |
|
gen_die 'Unionfs directory ${UNIONFS_DIR} is invalid!' |
|
cd "${UNIONFS_DIR}" |
|
print_info 1 'unionfs tools: >> Compiling...' |
|
sed -i utils/Makefile -e 's|${CC} -o|${CC} -static -o|g' |
|
sed -i Makefile -e 's|${CC} -o|${CC} -static -o|g' |
|
compile_generic utils utils |
|
|
|
print_info 1 'moving into utils directory...' |
|
cd utils |
|
|
|
print_info 1 'unionfs: >> Copying to cache...' |
|
strip uniondbg unionctl |
|
cp uniondbg ${TEMP}/unionfs/sbin/ || |
|
gen_die 'Could not copy the uniondbg binary to the tmp directory' |
|
cp unionctl ${TEMP}/unionfs/sbin/ || |
|
gen_die 'Could not copy the unionctl binary to the tmp directory' |
|
cd ${TEMP}/unionfs |
|
/bin/tar -cjf "${UNIONFS_BINCACHE}" . || |
|
gen_die 'Could not create unionfs tools binary cache' |
|
|
|
cd "${TEMP}" |
|
rm -rf "${UNIONFS_DIR}" > /dev/null |
|
rm -rf unionfs > /dev/null |
|
fi |
|
} |
|
|
|
compile_unionfs_utils_1_4() { |
|
compile_unionfs_utils_1_3 |
|
} |