#!/bin/sh

if [ ! -f zlib-1.1.4.tar.gz ]; then
	wget http://www.gzip.org/zlib/zlib-1.1.4.tar.gz
	tar xzvf zlib-1.1.4.tar.gz
	ln -sf zlib-1.1.4 zlib
	cd zlib-1.1.4
	./configure
	make
	cd ..
fi

if [ ! -f libpng-1.2.8.tar.gz ]; then
	wget http://downloads.planetmirror.com/pub/imagemagick/delegates/libpng-1.2.8.tar.gz
	tar xzvf libpng-1.2.8.tar.gz
	ln -sf libpng-1.2.8 libpng
	cd libpng-1.2.8
	make -f scripts/makefile.std CC=gcc ZLIBLIB=../zlib ZLIBINC=../zlib
	cd ..
fi

if [ ! -f gd-1.8.4.tar.gz ]; then
	wget http://www.boutell.com/gd/http/gd-1.8.4.tar.gz
	tar xzvf gd-1.8.4.tar.gz
	ln -sf gd-1.8.4 gd
	cd gd-1.8.4
	perl -i~ -p -e s/gd_jpeg.o//g Makefile            
	make INCLUDEDIRS="-I. -I../zlib -I../libpng" \
	     LIBDIRS="-L../zlib -L. -L../libpng" \
	     LIBS="-lgd -lpng -lz -lm" \
	     CFLAGS="-O -DHAVE_LIBPNG"
	cd ..
fi

if [ ! -f mrtg-2.13.2.tar.gz ]; then
	wget http://people.ee.ethz.ch/~oetiker/webtools/mrtg/pub/mrtg-2.13.2.tar.gz
	tar xzvf mrtg-2.13.2.tar.gz
	ln -sf mrtg-2.13.2 mrtg
	cd mrtg

	./configure --prefix=/usr/local/mrtg \
	            --with-gd=../gd      \
	            --with-z=../zlib     \
	            --with-png=../libpng
	make
	echo
	echo Go to mrtg/ directory and run make install
fi
