#! /bin/sh

if ! [ $HOME = /root ]
	then echo -e "\e[31mYou must become root to run \e[32minstall\e[0m\nAborting";exit
fi 
which perl &> /dev/null
if ! [ $? = 0 ]
	then echo -e "\e[31mI can't find Perl in your PATH\e[0m\nAborting";exit
fi
if ! [ -e /usr/bin/perl ]
	then ln -s `which perl` /usr/bin/perl &> /dev/null
fi
which mplayer &> /dev/null
if ! [ $? = 0 ]
	then echo -e "\e[31mI can't find MPlayer in your PATH\e[0m\nAborting\n\nRead README where you can get MPlayer";exit
fi 
which make &> /dev/null
if ! [ $? = 0 ]
	then echo -e "\e[31mI can't find make in your PATH\e[0m\nAborting";exit
fi 
echo -e "\n\e[1m  Starting ....\e[0m";
echo
echo -e "\e[32m Audio::Mixer\e[0m"
echo -e "\e[32m MP3::Info\e[0m"
echo -e "\e[32m Term::ReadKey\e[0m"
echo -e "\e[32m Time::Hires\e[0m"
echo -e "\e[32m Cwd\e[0m"
echo -e "\e[32m Ogg::Vorbis::Header::PurePerl\e[0m"
echo -e "\e[32m Video::Info\e[0m"
echo -e "\e[32m Class::MakeMethods::Emulator\e[0m"

#if [ $mixer = 0 || $mp3 = 0 || 
tmp=1;
if [ $tmp = 1 ]
	then echo -e -n "\n The perl-module(s) above have to be installed.\n Press \e[32mEnter\e[0m to proceed or \e[31mCtrl-C\e[0m to abort.\r"
	read
fi

	 	tar -xzf src/Audio-Mixer-0.7.tar.gz
		cd Audio-Mixer-0.7/
		perl Makefile.PL
		make
		make install
		cd ..
		rm -r -f Audio-Mixer-0.7/
		tar -xzf src/MP3-Info-1.11.tar.gz
		cd MP3-Info-1.11/
		perl Makefile.PL
		make
		make install
		cd ..
		rm -r -f MP3-Info-1.11/
	 	tar -xzf src/TermReadKey-2.21.tar.gz
		cd TermReadKey-2.21/
		perl Makefile.PL
		make
		make install
		cd ..
		rm -r -f TermReadKey-2.21/
	 	tar -xzf src/Time-HiRes-1.56.tar.gz
		cd Time-HiRes-1.56/
		perl Makefile.PL 
		make
		make install
		cd ..
		rm -r -f Time-HiRes-1.56/
	 	tar -xzf src/Cwd-2.18.tar.gz
		cd Cwd-2.18/
		perl Makefile.PL 
		make
		make install
		cd ..
		rm -r -f Cwd-2.18/
	 	tar -xzf src/Ogg-Vorbis-Header-PurePerl-0.07.tar.gz
		cd Ogg-Vorbis-Header-PurePerl-0.07/
		perl Makefile.PL 
		make
		make install
		cd ..
		rm -r -f Ogg-Vorbis-Header-PurePerl-0.07/
	 	tar -xzf src/Video-Info-0.991.tar.gz
		cd Video-Info-0.991/
		perl Makefile.PL 
		make
		make install
		cd ..
		rm -r -f Video-Info-0.991
	 	tar -xzf src/Class-MakeMethods-1.01.tar.gz
		cd Class-MakeMethods-1.01/
		perl Makefile.PL 
		make
		make install
		cd ..
		rm -r -f Class-MakeMethods-1.01

if  ! [ -d ~/.mplay ]
	then mkdir ~/.mplay
fi
if    [ -f ~/.mplay/playlist00 ]
	then mv -f ~/.mplay/playlist ~/.mplay/"playlist1"
fi
if  ! [ -d /usr/local/share/mplay ]
	then mkdir -p /usr/local/share/mplay
fi
if  ! [ -f ~/.mplay/mplayconf ]
	then cp -f help/mplayconf ~/.mplay/
fi

echo -e "\nCopy help files to /usr/local/share/mplay/";cp -f help/help* /usr/local/share/mplay/
echo -e "\nCopy manpage to /usr/local/man/man1/";cp -f help/mplay.1 /usr/local/man/man1/
echo "Copy mplay to /usr/local/bin/";cp mplay /usr/local/bin/
chmod +x /usr/local/bin/mplay
echo -e "\n\e[32mReady\n\e[0m\nNow you can run e.g.: \e[31mmplay \e[32m/path/to/some/*.mp3\e[0m\nAnd then press \e[31mh\e[0m to see the help.\nHave fun ...\n"
