#!/bin/bash

echo "Getting distributables..."

if [ ! -e buildtools.conf ]; then
    cp buildtools.conf.delivered buildtools.conf
fi
source buildtools.conf

if [ "$1" = "b" ]; then
	srcpath=$BUILD_SRC_PATH
elif [ "$1" = "d" ]; then
	srcpath=$DEV_SRC_PATH
else
	echo "Unknown system type parameter."
    echo "Must be b for build machine or d for dev system."
	exit 1
fi
rm -rf /mnt/custom/customcd/files/root/rescuebru/*
rm -rf /root/rescuebru/*
sleep 2
if [ "$1" = "b" ]; then
	ntpdate 0.pool.ntp.org
fi
rm -rf /mnt/custom/customcd/isoroot/RescueBRU_Documentation/*
rsync -rlptDvz --exclude=*.iso --exclude=*.md5 $srcpath /mnt/custom/
find /mnt/custom/customcd/isoroot/RescueBRU_Documentation/ -type f ! -name '*.pdf' ! -name '*.xls' -delete
mkdir -p /mnt/custom/rescuebru-src
rsync -rlptDvz --del --exclude=*.iso --exclude=*.md5 $srcpath /mnt/custom/rescuebru-src/
cp -Rv /mnt/custom/rescuebru-src /mnt/custom/customcd/isoroot
if [ ! -d "/root/rescuebru" ]; then
	mkdir /root/rescuebru
fi
chmod +x /mnt/custom/buildtools/*
chmod -x /mnt/custom/buildtools/*.conf /mnt/custom/buildtools/*.conf.delivered
cp -R /mnt/custom/customcd/files/root/rescuebru/* /root/rescuebru

rm -f /mnt/custom/customcd/files/root/.bash_history
rm -rf /mnt/custom/customcd/files/root/.config/geany

