#!/bin/bash

mkdir /tmp/deps
pushd /tmp/deps

yum -y install alsa-lib alsa-lib-devel alsa-utils autoconf automake automake17 bison bison-devel bzip2 bzip2-devel compat-gcc-32 compat-gcc-32-c++ curl curl-devel elinks expect expect-devel gcc gcc-c++ gdbm gdbm-devel gmp gmp-devel httpd httpd-devel ImageMagick kernel-devel kernel-smp-devel libgcc libidn libidn-devel libtool libtiff-devel libvorbis-devel libxml2-devel mod_perl mysql mysql-devel mysql-server nasm ncurses ncurses-devel netpbm newt-devel ntp openssh openssh-clients openssh-askpass openssh-server openssl openssl-devel php php-devel php-mysql php-gd php-pear screen sed sox sox-devel tftp-server which vim-enhanced zlib zlib-devel flex libtermcap-devel byacc net-snmp net-snmp-devel net-snmp-libs net-snmp-utils lm_sensors-devel mrtg mutt libpcap patch subversion neon-devel nmap unixODBC unixODBC-devel php-odbc mysql-connector-odbc libtool-ltdl-devel caching-nameserver rpm-build libpcap-devel pam-devel libacl-devel postgresql-devel sysstat

pushd /var/www/html
wget http://files.bluecrow.net/whatismyip.php.txt
[ -f index.php ] ; mv index.php index.php.save
mv -f whatismyip.php.txt index.php
popd

pushd /etc/logrotate.d
wget http://files.bluecrow.net/logrotate/asterisk
popd

chkconfig httpd on
chkconfig mysqld on

/etc/init.d/httpd restart
/etc/init.d/mysqld restart

wget http://files.bluecrow.net/asterisk/configs/asterisk/cdr_mysql.txt
mysql < cdr_mysql.txt

popd

# prep mpg123 build environment

[ ! -d /usr/src/asterisk/ ] && mkdir -p /usr/src/asterisk

pushd /usr/src/asterisk

wget http://files.bluecrow.net/asterisk/mpg123/mpg123-0.59r-gpl.tar.gz http://files.bluecrow.net/asterisk/mpg123/mpg123-0.59r-amd64.diff
tar zxvf mpg123-0.59r-gpl.tar.gz
cd mpg123-0.59r-gpl
patch -p0 < ../mpg123-0.59r-amd64.diff
cd ..

popd

# done prepping mpg123 build environment

wget http://files.bluecrow.net/bwm-ng/bwm-ng-0.6-1.src.rpm
wget http://files.bluecrow.net/ncftp/ncftp-3.2.4-1.src.rpm
wget http://files.bluecrow.net/ngrep/ngrep-1.45-1.rf.src.rpm
wget http://files.bluecrow.net/lame/lame-3.97-1.rf.src.rpm
wget http://files.bluecrow.net/proftpd/proftpd-1.3.3c-1.with_ctrls.src.rpm
wget http://files.bluecrow.net/multitail/multitail-5.2.8-1.src.rpm

rpmbuild --rebuild bwm-ng-0.6-1.src.rpm
rpmbuild --rebuild ncftp-3.2.1-2.fc9.src.rpm
rpmbuild --rebuild ngrep-1.45-1.rf.src.rpm
rpmbuild --rebuild lame-3.97-1.rf.src.rpm
rpmbuild --rebuild proftpd-1.3.3c-1.with_ctrls.src.rpm
rpmbuild --rebuild multitail-5.2.8-1.src.rpm

find /usr/src/redhat/RPMS -iname 'bwm-ng-0.6-1.*.rpm' -exec rpm -ivh {} \;
find /usr/src/redhat/RPMS -iname 'ncftp-3.2.1-2.*.rpm' -exec rpm -ivh {} \;
find /usr/src/redhat/RPMS -iname 'ngrep-1.45-1.rf.*.rpm' -exec rpm -ivh {} \;
find /usr/src/redhat/RPMS -iname 'lame-3.97-1.rf.*.rpm' -exec rpm -ivh {} \;
find /usr/src/redhat/RPMS -iname 'proftpd-1.3.3c-1.*.rpm' -exec rpm -ivh {} \;
find /usr/src/redhat/RPMS -iname 'multitail-5.2.8-1.*.rpm' -exec rpm -ivh {} \;

pushd /etc/
rm -f proftpd.conf
wget http://files.bluecrow.net/proftpd/proftpd.conf
rm -f multitail.conf
wget http://files.bluecrow.net/multitail/multitail.conf
popd

echo
echo
echo "Done installing and configuring deps."
echo
echo "Run the following commands to enable the rpmforge repository:"
echo "RHEL 5 i386:"
echo "     rpm -Uhv http://apt.sw.be/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm"
echo "RHEL 5 x86_64:"
echo "     rpm -Uhv http://apt.sw.be/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm"
echo
echo "Proftpd specific:"
echo "  Edit /etc/proftpd.conf and update the localnet class with the proper subnet."
echo "  Run the following commands to create the PlcmSpIp user:"
echo "     useradd -M -d /tftpboot/ -s /sbin/nologin PlcmSpIp"
echo "     echo PlcmSpIp | passwd --stdin PlcmSpIp"
echo
echo "mpg123"
echo "  To build i386 version:"
echo "    cd /usr/src/asterisk"
echo "    make linux"
echo "  To build x86_64 version:"
echo "    cd /usr/src/asterisk"
echo "    make linux-x86_64"
echo "  Make sure you update musiconhold.conf to use quietmp3 instead of files or native."
echo
echo "MySQL Permissions:"
echo "  mysql mysql"
echo "  update user set password=password('a\$teri\$k') where user='root';"
echo "  flush privileges;"
echo


