#!/bin/sh

##################--------C o l o r  -------------##########################
# <colors>
	coloroff="\033[1;0m"	# standart color
	green="\033[1;32m"	# green
	white="\033[1;37m"	# white
	blue="\033[1;36m"	# blue
	red="\033[1;31m"	# red
	lilas="\033[1;35m"	# lilac
# </colors>


############################################################################

clear
echo "Homepage of this project:"
echo -e "http://gnormalize.sourceforge.net\n"
echo -e "This script will install ${blue}gnormalize${coloroff}, \
${green}Audio-CD${coloroff}, ${green}CDDB_get${coloroff}, ${green}MP3::Info${coloroff}, \
${green}mac${coloroff}, ${green}mppenc${coloroff}, ${green}mppdec${coloroff}, \
and ${green}wavegain${coloroff} in your system:"

ID=$(id)

case $ID in *\(root\)*)
     IDROOT=1
     ;;
esac

if [ "$IDROOT" != 1 ] ; 
then echo -e "\nYou must have permission access (superuser privilege) to install this programs.
Please, become root.\n"
     exit; 
fi


####################--------------Install------------########################

echo -e "\nInstall Audio-CD to play Audio CDs( you must have installed: libcdaudio,\
libcdaudio-devel, perl-devel )? Type (y/n): \c"

read resposta

machine=`uname -m`  # i586, i686, x86_32, x86_64
local=`pwd`  # save local path
cd packages  # enter the packages directory

if [ "$resposta" = "y" -o "$resposta" = "" ]
then     	 
	 echo -e "\n${lilas}Install Audio-CD:${coloroff}"
	 tar zxvf Audio-CD-0.04-changed.tar.gz
	 cd Audio-CD-0.04-changed
	 perl Makefile.PL
	 make && make install
	 if [ "$?" = "0" ]
	    then echo -e "\n${green}Sucess, Audio-CD installed.${coloroff}\n"
	    else echo -e "\n${red}Could not install Audio-CD.${coloroff}\n"
	 fi
	 cd ..
	 rm -rf Audio-CD-0.04-changed
	 	 	 
else     echo -e "\nNot install Audio-CD!\n"

fi


PACKINFO=`ls CDDB_get-*.tar.gz`
PACKDIR=`echo $PACKINFO|sed -e 's/\.tar\.gz//'`

echo -e "\nInstall $PACKINFO? Type (y/n): \c"
read resposta
if [ "$resposta" = "y" -o "$resposta" = "" ]
then       	 
	 echo -e "\n${lilas}Install $PACKINFO:${coloroff}"
	 tar -zxvf $PACKINFO
	 cd $PACKDIR
	 perl Makefile.PL
	 make && make install
	 if [ "$?" = "0" ]
	    then echo -e "\n${green}Sucess, $PACKINFO installed.${coloroff}\n"
	    else echo -e "\n${red}Could not install $PACKINFO.${coloroff}\n"
	 fi
	 cd ..
	 rm -rf $PACKDIR
	 	 	 
else     echo -e "\nNot install $PACKINFO!\n"
fi


PACKINFO=`ls MP3-Info-*.tar.gz`
PACKDIR=`echo $PACKINFO|sed -e 's/\.tar\.gz//'`

echo -e "\nInstall $PACKINFO? Type (y/n): \c"
read resposta
if [ "$resposta" = "y" -o "$resposta" = "" ]
then       	 
	 echo -e "\n${lilas}Install $PACKINFO:${coloroff}"
	 tar -zxvf $PACKINFO
	 cd $PACKDIR
	 perl Makefile.PL
	 make && make install
	 if [ "$?" = "0" ]
	    then echo -e "\n${green}Sucess, $PACKINFO installed.${coloroff}\n"
	    else echo -e "\n${red}Could not install $PACKINFO.${coloroff}\n"
	 fi
	 cd ..
	 rm -rf $PACKDIR
	 	 	 
else     echo -e "\nNot install $PACKINFO!\n"
fi


PACKINFO=`ls mac-*.tar.gz`
PACKDIR=`echo $PACKINFO|sed -e 's/\.tar\.gz//'`

echo -e "\nInstall $PACKINFO? Type (y/n): \c"
read resposta
if [ "$resposta" = "y" -o "$resposta" = "" ]
then       	 
	 echo -e "\n${lilas}Install $PACKINFO:${coloroff}"
	 tar -zxvf $PACKINFO
	 cd $PACKDIR
	 ./configure --prefix=/usr
	 make && make install
	 if [ "$?" = "0" ]
	    then echo -e "\n${green}Sucess, $PACKINFO installed.${coloroff}\n"
	    else echo -e "\n${red}Could not install $PACKINFO.${coloroff}\n"
	 fi
	 cd ..
	 rm -rf $PACKDIR
	 	 	 
else     echo -e "\nNot install $PACKINFO!\n"
fi


MPPENC=`ls mppenc-*.tar.bz2`
MPPENCDIR=`echo $MPPENC|sed -e 's/\.tar\.bz2//'`

echo -e "\nInstall $MPPENC (need 'cmake' to compile) and mppdec? Type (y/n): \c"
read resposta
if [ "$resposta" = "y" -o "$resposta" = "" ]
then       	 
	 echo -e "\n${lilas}Install $MPPENC:${coloroff}"
	 tar -jxvf $MPPENC
	 cd $MPPENCDIR
         cmake -DCMAKE_INSTALL_PREFIX:=/usr
 	 make && make install
	 
	 MPPENC_OUTPUT=`echo $?`
	 
	 cd ..
	 rm -rf $MPPENCDIR
	 	 
	 if [ $MPPENC_OUTPUT = "0" ]
	    then echo -e "\n${green}Sucess, MPC encoder installed from source code $MPPENC.${coloroff}\n"
	         echo -e "\n${lilas}Install MPC decoder from binary:${coloroff}"
		 
		 if [ $machine = "x86_64" ]
		    then cp -vf mppdec_x86_64 /usr/bin/mppdec; chmod 0755 /usr/bin/mppdec
		    else cp -vf mppdec /usr/bin/mppdec; chmod 0755 /usr/bin/mppdec
		 fi
		 
	    else echo -e "\n${red}Could not install MPC encoder from source code $MPPENC!${coloroff}\n"
	         echo -e "\n${lilas}Install MPC encoder and decoder from binary:${coloroff}"
		 
		 if [ $machine = "x86_64" ]
		    then cp -vf mppenc_x86_64 /usr/bin/mppenc; chmod 0755 /usr/bin/mppenc
		         cp -vf mppdec_x86_64 /usr/bin/mppdec; chmod 0755 /usr/bin/mppdec		    		    
		    else cp -vf mppenc /usr/bin/mppenc; chmod 0755 /usr/bin/mppenc
		         cp -vf mppdec /usr/bin/mppdec; chmod 0755 /usr/bin/mppdec
		 fi		 
	 fi	 	 	 	 	 	 
else     echo -e "\nNot install $MPPENC and mppdec!\n"
fi


PACKINFO=`ls WaveGain-*.tar.gz`
PACKDIR=`echo $PACKINFO|sed -e 's/\.tar\.gz//'`

echo -e "\nInstall $PACKINFO (with ReplayGain to normalize wave files)? Type (y/n): \c"
read resposta
if [ "$resposta" = "y" -o "$resposta" = "" ]
then       	 
	 echo -e "\n${lilas}Install $PACKINFO:${coloroff}"
	 tar -zxvf $PACKINFO
	 cd $PACKDIR
	 # ./configure --prefix=/usr
	 make && make install

         WAVEGAIN_OUTPUT=`echo $?`

         cd ..
	 rm -rf $PACKDIR

	 if [ $WAVEGAIN_OUTPUT = "0" ]
	    then echo -e "\n${green}Sucess, $PACKINFO installed.${coloroff}\n"
	    else echo -e "\n${red}Could not install $PACKINFO from source code.${coloroff}\n"
	         echo -e "\n${lilas}Install WaveGain from binary:${coloroff}"		 	    
	         if [ $machine = "x86_64" ]
		    then cp -vf wavegain_x86_64 /usr/bin/wavegain; chmod 0755 /usr/bin/wavegain
		    else cp -vf wavegain /usr/bin/wavegain; chmod 0755 /usr/bin/wavegain
	         fi		 
	 fi	 
	 	 	 
else     echo -e "\nNot install $PACKINFO!\n"
fi


cd .. # quit the packages directory
cd $local

echo -e "\nInstall ${blue}gnormalize${coloroff}? Type (y/n): \c"
read resposta
if [ "$resposta" = "y" -o "$resposta" = "" ]
then	 
	 echo -e "\n${lilas}Install gnormalize:${coloroff}"
	 
	 make install
	 
	 if [ "$?" = "0" ]
	    then echo -e "\n${green}Sucess, install finished.${coloroff}\n"
	    else echo -e "\n${red}Could not install gnormalize.${coloroff}\n"
	 fi
	 
else     echo -e "\nNot install!\n"
fi
