#!/bin/sh

echo "Installing required packages"
for i in `apt-get -y install \
	build-essential \
	linux-headers-amd64 \
	iptables-persistent \
	gdm3 \
	vlc \
	firefox-esr \
	transmission \
	enlightenment \
	redsocks \
	tor \
	rsync \
	unbound \
	vim-tiny` 
do
	echo -n .
done
echo " Done"


echo "Removing unused packages"
for i in `apt-get -y remove --purge nano`; do echo -n "."; done
echo " Done"


echo "Mounting VirtualBox VM guest additions CD..."
mount /dev/cdrom /mnt
echo "Compiling VM additions..."
for i in `cd /mnt && ./VBoxLinuxAdditions.run`; do echo -n "."; done
echo " Done"

echo "Unmounting CD..."
cd -
umount /mnt

echo "Copying static configs"
cd static && rsync -av . /

echo "Disabling IPv6"
echo net.ipv6.conf.all.disable_ipv6=1     >> /etc/sysctl.conf
echo net.ipv6.conf.default.disable_ipv6=1 >> /etc/sysctl.conf

for INSTUSER in `cd /home && ls -d *`
do
	echo "Installing non-root setup for $INSTUSER"
	cp -R user/* /home/${INSTUSER}/
	chown -R ${INSTUSER}:${INSTUSER} /home/${INSTUSER}/
	echo "Disable bash_history for user ${INSTUSER}"
	rm -f /home/${INSTUSER}/.bash_history
	ln -s /dev/null /home/${INSTUSER}/.bash_history
done

echo "Disable bash_history for root"
rm -f /root/.bash_history
ln -s /dev/null /root/.bash_history

echo "Cleaning apt/pkg"
apt-get clean

echo "Cleaning syslog"
/etc/init.d/rsyslog stop
find /var/log -type f -print0 | xargs -0 rm

echo "Setup complete, please reboot to make it active"
