#!/bin/bash
# $Id: instmyth.sh,v 1.1 2003/02/17 02:58:55 jjr Exp $
set -x
CWD=$PWD
echo "Verifying lynx installed..."
up2date --solvedeps lynx

echo "Verifying ncftpget installed..."
up2date --solvedeps ncftpget

echo "Verifying perl installed..."
up2date --solvedeps perl

echo "Verfying MySQL and qt-MySQL..."
up2date --solvedeps mysql-server
up2date --solvedeps mysql-client
up2date --solvedeps qt
up2date --solvedeps qt-MySQL

echo "RH Lang Setup and Env/PATH/QTDIR ..."
perl -pi.$$ -e 's/LANG=.*/LANG=en_US/ if m/LANG=/ && !m/en_US/;' /etc/sysconfig/i18n

if [ ! -f /etc/profile.d/mythtv.sh ]
then
cat > /etc/profile.d/mythtv.sh<<EOF
QTDIR=/usr/lib/qt3
PATH=${PATH}:/usr/lib/qt3/bin:/home/mythtv
EOF
fi

echo "Verifying local/lib in LD_LIBS path..."
if grep "^/usr/local/lib" /etc/ld.so.conf
then	:
else	echo "/usr/local/lib" >> /etc/ld.so.conf
	ldconfig
fi


echo "Installing ALSA Driver/Lib/Utils"
ALSA_VER=0.9.0rc7
for mod in driver utils lib
do	if [ -d alsa-$mod-$ALSA_VER ] 
	then	cd alsa-$mod-$ALSA_VER
	else    ncftpget ftp://ftp.alsa-project.org/pub/$mod/alsa-$mod-$ALSA_VER.tar.bz2
		tar -xjf alsa-$mod-*.bz2
		rm alsa-$mod-$ALSA_VER.tar.bz2
		cd alsa-$mod-$ALSA_VER && ./configure
	fi
        make && make install
        cd $CWD
done

cd $CWD

echo "Creating conf.modules.new to use driver and adding alsasound to cfg..."
cat > /etc/conf.modules.new <<EOF
alias char-major-116 snd
alias snd-card-0 snd-XXX
#OSS/Free portion
alias char-major-14 sndcore
alias sound-slot-0 snd-card-0
#card #1
alias sound-service-0-0 snd-mixer-oss
alias sound-service-0-1 snd-seq-oss
alias sound-service-0-3 snd-pcm-oss
alias sound-service-0-8 snd-seq-oss
alias sound-service-0-13 snd-pcm-oss
EOF
chkconfig --add alsasound

echo "Verifying Lame Installation..."

LAME=lame-3.93.1

if	[ -d $LAME ]
then	cd $LAME
else	lynx -source http://unc.dl.sourceforge.net/sourceforge/lame/$LAME.tar.gz| tar -xzvf -
	cd $LAME && ./configure 
fi
make && make install
cd $CWD

echo "Verifying xmltv..."
XMLTV=xmltv-0.5.8
[ -d $XMLTV ] ||
  lynx -source http://unc.dl.sourceforge.net/sourceforge/xmltv/$XMLTV.tar.bz2 |
	tar xjf -
cd $XMLTV 
[ -f Makefile ] || perl Makefile.PL && make && make install

cd $CWD


echo "Verifying expat and expatlib and development..."
XPAT=expat-1.95.6-1
if rpm -q expat | grep $XPAT
then :
else lynx -source http://unc.dl.sourceforge.net/sourceforge/expat/$XPAT.i386.rpm > tmp.rpm
   rpm -Uhv tmp.rpm
   rm tmp.rpm
fi
#up2date --solvedeps expat
#up2date --solvedeps expat-devel
cd $CWD

echo "Installing/Updating Required Perl Modules..."
perl -e '{
use CPAN;
@INSTALL=qw/Compress::Zlib MD5 XML::Twig Date::Manip LWP XML::Writer/;
for (@INSTALL) {
  CPAN::Shell->install($_);
}}'


echo "Enabling MySQL..."
if [ -f /etc/rc.d/init.d/mysql ]
then	chkconfig --level 35 mysql on
	/etc/rc.d/init.d/mysql start
fi

echo "Verifying MythTV..."
MYTH_VER=0.7
if [ -d mythtv-$MYTH_VER ] 
then	cd mythtv-$MYTH_VER
else	lynx --source http://mythtv.org/mc/mythtv-$MYTH_VER.tar.bz2 | tar xjf -
	cd mythtv-$MYTH_VER
	./configure
fi
make && make install
 
cd $CWD
