#!/bin/bash
# WDlinux Control Panel,lamp,lnmp system install scripts
# Created by wdlinux QQ:12571192
# Url:http://www.wdlinux.cn
# Last Updated 2011.04.28
#
arch=i386
Aurl="http://dl.wdlinux.cn:5180/rpms"
if [[ `uname -m` == "x86_64" ]];then
        arch="x86_64"
fi

function in_finsh {
        echo
        echo "          configuration wdcdn install is finshed"
        echo "          wdcp visit http://ip:8080"
        echo "          more infomation please visit http://www.wdlinux.cn"
        echo
}

function in_check {
        if [[ $1 == 1 ]];then
                echo
                echo "============  $2 error  ============="
                echo
                exit 1
        else
                echo
                echo "============  $2 OK  =============="
                echo
                echo
        fi
}
echo 
echo "download....."
squid="squid-3.1.12-1.$arch.rpm"
wget -c $Aurl/$squid
in_check $? "down"
rpm -ivh $squid --nodeps --force
in_check $? "squid install"
echo "stop apache"
cf="/www/wdlinux/apache/conf/httpd.conf"
if [[ -f $cf ]];then
	service httpd stop
	sed -i 's/Listen/#Listen/g' $cf
	sed -i 's/NameVirtualHost/#NameVirtualHost/g' $cf
	sed -i 's|Include conf/def|#Include conf/def|g' $cf
	sed -i 's|Include conf/vhost|#Include conf/vhost|g' $cf
	service httpd start
else
	service nginxd stop
	cf="/www/wdlinux/nginx/conf/nginx.conf"
	sed -i '/listen/c\
	listen 8000;' $cf
	sed -i 's|include default|#include default|g' $cf
	sed -i 's|include vhost|#include vhost|g' $cf
	service nginxd start
fi
dbu=`grep dbuser /www/web/wdcp/data/db.inc.php | awk -F"'" '{print $2}'`
dbp=`grep dbpw /www/web/wdcp/data/db.inc.php | awk -F"'" '{print $2}'`
/www/wdlinux/mysql/bin/mysql -u$dbu -p"$dbp" wdcpdb < /www/web/wdcp/wd_cdn.sql
in_check $? "sql import"
service squid start
in_finsh
