#! /bin/bash
#mv /root/cpan/mysql-mmm-* /root
pathname="/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/DBD"
cpanpath=/root/cpan
echo "/usr/local/mysql/lib/mysql/" >> /etc/ld.so.conf
ldconfig
file1="DBD-mysql-4.020.tar.gz"
file2="perl-DBI-1.52-2.el5.i386.rpm"
ls $cpanpath > /root/file
while read i
do
        file3=$(rpm -qa perl-DBI |awk -F "1" '{print $1}')
        if [ "$file3" != "perl-DBI-" ]
        then
                rpm -ivh $cpanpath/$i
                sleep 2
#                mv /root/cpan/perl-DBI* /root
        else
                if [ -d $pathname ]
                then
                        tar xf $cpanpath/$i -C /tmp && cd /tmp/$(echo $i |awk -F ".tar" '{print $1}')

                        perl Makefile.PL && make test && make install
                        mv $cpanpath/$i /root
                else
                        if [ "$i" = "$file1" ]
                        then
                                tar xf $cpanpath/$i -C /tmp && cd /tmp/$(echo $i |awk -F ".tar" '{print $1}')
                                perl Makefile.PL --mysql_config=/usr/local/mysql/bin/mysql_config --with-mysql=/usr/local/mysql && make test && make install  && mv $cpanpath/$i /root
                                continue
                        fi
                fi
        fi

done < /root/file

for j in `ls /root/cpan`
do
         tar xf $cpanpath/$j -C /tmp && cd /tmp/$(echo $j |awk -F ".tar" '{print $1}')
         perl Makefile.PL && make test && make install
         mv $cpanpath/$j /root
done

tar xf /root/mysql-mmm* -C /tmp && cd /tmp/mysql-mmm* && make install
rm -rf /root/file