###
### grab the tarball and unpack it
###

VERS=1.14.2
wget http://www.busybox.net/downloads/busybox-$VERS.tar.gz
tar -xzf busybox-$VERS.tar.gz

###
### make a blank configuration file, then tailor it, then remake
###

cd busybox-$VERS
make allnoconfig
CONF_HEADERS="INSTALL_NO_USR \
	FALSE \
	HTTPD \
	FEATURE_HTTPD_SETUID \
	FEATURE_HTTPD_BASIC_AUTH \
	FEATURE_HTTPD_CGI \
	FEATURE_HTTPD_ENCODE_URL_STR"
for STR in $CONF_HEADERS; do 
  sed -i "s/# CONFIG_$STR is not set/CONFIG_$STR=y/" .config
done
make

###
### install and copy binaries to /tmp
###

sudo make install
mkdir -p /tmp/httpd/usr/local/httpd/bin
mkdir -p /tmp/httpd/usr/local/httpd/sbin
sudo cp -p _install/bin/busybox /tmp/httpd/usr/local/httpd/bin/
sudo cp -pP _install/bin/false /tmp/httpd/usr/local/httpd/bin/
sudo cp -pP _install/sbin/httpd /tmp/httpd/usr/local/httpd/sbin/
cd -

###
### make .tce
###

cd /tmp/httpd
find usr -not -type d > ../busybox-httpd.filelist
tar czf busybox-httpd.tce --numeric-owner -T ../busybox-httpd.filelist 
advdef -z4 busybox-httpd.tce
cd -
mv /tmp/httpd/busybox-httpd.tce .
md5sum busybox-httpd.tce > busybox-httpd.tce.md5.txt

###
### make .tce
###

mkfs.cramfs /tmp/httpd busybox-httpd.tcz
md5sum busybox-httpd.tcz > busybox-httpd.tcz.md5.txt
