#!/bin/bash
#--------------------------------------------------------
#	Config
#--------------------------------------------------------
TRUECRYPT=truecrypt-4.3a-source-code
KERNEL=linux-source-2.6.22
COMPRESSION=bz2
TAROPT=j
#--------------------------------------------------------
#	Sanity
#--------------------------------------------------------
set -e -x
test "`id -u`" = '0'
#--------------------------------------------------------
#	Src directory
#--------------------------------------------------------
cd /usr/src
#--------------------------------------------------------
#	Unpack linux source if not already done
#--------------------------------------------------------
KERNEL_TAR=$KERNEL.tar.$COMPRESSION
if test ! -d "$KERNEL"
then
	test -f "$KERNEL_TAR"
	tar x${TAROPT}f "$KERNEL_TAR"
fi
#--------------------------------------------------------
#	Crate or update symbolic link
#--------------------------------------------------------
rm -f linux
ln -s "$KERNEL" linux
#--------------------------------------------------------
#	Get truecrypt source
#--------------------------------------------------------
TRUECRYPT_TAR=$TRUECRYPT.tar.gz
if test ! -f "$TRUECRYPT_TAR"
then
	wget "http://www.truecrypt.org/downloads/$TRUECRYPT_TAR"
fi
#--------------------------------------------------------
#	Unpack truecrypt source
#--------------------------------------------------------
if test ! -d "$TRUECRYPT"
then
	tar xzf "$TRUECRYPT_TAR"
fi
#--------------------------------------------------------
#	change into truecrypt
#--------------------------------------------------------
cd "$TRUECRYPT/Linux"
#--------------------------------------------------------
#	and build truecrypt
#--------------------------------------------------------
yes | ./build.sh
./install.sh</dev/null
#--------------------------------------------------------
#	done
#--------------------------------------------------------
echo Ok
exit 0

