#/bin/sh
#
# freemoe-build-node-setup
# Boot up Debian Lenny (in this case Amazon EC2 image ami-dcf615b5)
#
# wget http://gitorious.org/freemoe/freemoe/blobs/raw/master/bin/freemoe-build-node-setup
#
# sh ./freemoe-build-node-setup

set -x

apt-get update

apt-get -y install git-core ntp
git clone git://gitorious.org/freemoe/freemoe.git
cp freemoe/servers/fog/obra-node-gitconfig /root/.gitconfig
cp freemoe/servers/fog/gitignore /etc/.gitignore
cd /etc/
git init
chmod og-rwx .git
git add .
git commit -a -m "obra node initial commit"
apt-get update && apt-get -y dist-upgrade
git add .
git commit -a -m "obra node apt-get dist-upgrade"
apt-get -y install build-essential debian-keyring autoconf automake1.9 libtool flex bison  autoconf2.13 ncftp libncurses5-dev vim exuberant-ctags vim-scripts fakeroot debhelper python-central python-setuptools sudo python-m2crypto python-boto
git add .
git commit -a -m "obra node install build utils"

echo "vm.vdso_enabled = 0" >> /etc/sysctl.conf
sysctl -p
git add .
git commit -a -m "vm.vdso_enabled = 0 in sysctl.conf for /scratchbox"

cd
wget http://repository.maemo.org/stable/fremantle/maemo-scratchbox-install_5.0.sh http://repository.maemo.org/stable/fremantle/maemo-sdk-install_5.0.sh
sh maemo-scratchbox-install_5.0.sh 

mkdir /root/DEBS
cd /root/DEBS

wget \
	http://obra.freemoe.org/toolz/euca2ools_1.1-3_all.deb \
	http://obra.freemoe.org/toolz/python-minideblib_0.6.21.29_all.deb \
	http://obra.freemoe.org/toolz/sbdmock_0.4.4_all.deb \
	http://obra.freemoe.org/toolz/python-boto_1.9b-2_all.deb \
	http://obra.freemoe.org/toolz/python-m2crypto_0.20.1-1_i386.deb

dpkg -i python-minideblib_0.6.21.29_all.deb \
	sbdmock_0.4.4_all.deb \
	python-boto_1.9b-2_all.deb python-m2crypto_0.20.1-1_i386.deb \
	sbdmock_0.4.4_all.deb \
	euca2ools_1.1-3_all.deb

useradd -m --groups sbox builder

/scratchbox/sbin/sbox_adduser builder

cp maemo-sdk-install_5.0.sh /home/builder/
mkdir ~builder/.sbdmock/
cp freemoe/servers/obra/sbdmock/* ~builder/.sbdmock/
chown -R builder:builder ~builder/.sbdmock

cd /home/builder/
su builder -c "sh maemo-sdk-install_5.0.sh -d"

exit 0

