#/bin/sh
# author:sunboyu@gmail.com
# qq:176300676 msn:sunboyu@gmail.com
# http://www.sunboyu.cn


# CHANGE SOURCE
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
cd /etc/yum.repos.d/
wget http://mirrors.sohu.com/help/CentOS-Base-sohu.repo
mv /etc/yum.repos.d/CentOS-Base-sohu.repo /etc/yum.repos.d/CentOS-Base.repo

yum -y install gcc gcc-c++ gcc4-c++ autoconf gd gd-devel libxml2 libxml2-devel \
zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses \
ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel \
libidn libidn-devel openssl openssl-devel expat expat-devel sqlite sqlite-devel \
png-devel jpeg-devel libtool libjpeg* libpng* freetype expat libtool \
expat-devel lrzsz patch make samba

# SAMBA CONFIG don't forget to add smb user by 'smbpasswd'
mv /etc/samba/smb.conf /etc/samba/smb.conf.bak
cp smb.conf mv /etc/samba/smb.conf
mkdir /home/public
mkdir /home/sunboyu
chown nobody:nobody /home/public
useradd -g nobody sunboyu
chown sunboyu:nobody /home/sunboyu
echo "service smb start">>/etc/rc.local




# MYSQL INSTALL
tar -zxvf mysql-5.0.22.tar.gz
cd mysql-5.0.22
groupadd mysql
useradd -g mysql mysql
./configure --prefix=/opt/mysql-5.0.22 \
--without-debug \
--enable-thread-safe-client \
--enable-local-infile \
--enable-largefile \
--with-charset=utf8 \
--with-collation=utf8_general_ci \
--with-extra-charsets=complex \
--with-pic \
--with-mysqld-libs \
--with-comment \
--with-query-cache \
--with-bench \
--with-big-tables \
--with-innodb \
--with-mysqld-use=mysql \
--with-mysqld-ldflags=-rdynamic \
--with-low-memory
make && make install
cp ./support-files/my-medium.cnf /etc/my.cnf
cp ./support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
/opt/mysql-5.0.22/bin/mysql_install_db	--user=mysql &
cd ..
echo "/opt/mysql-5.0.22/bin/mysqld_safe --user=mysql &">>/etc/rc.local



# Libmcrypt INSTALL
tar -zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure && make && make install
cd ..

# MHASH INSTALL
tar -zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure && make && make install
cd ..

# PHP INSTALL
groupadd www
useradd -g www www
tar -zxvf php-5.2.6.tar.gz
gzip -cd php-5.2.6-fpm-0.5.9.diff.gz | patch -d php-5.2.6 -p1
cd php-5.2.6
./configure --prefix=/opt/php-5.2.6 \
--enable-cli \
--enable-cgi \
--enable-fastcgi \
--enable-bcmath \
--enable-force-cgi-redirect \
--enable-discard-path \
--enable-path-info-check \
--with-openssl \
--with-pcre-regex \
--enable-calendar \
--enable-dom \
--enable-ftp \
--with-openssl-dir=/usr/local/ssl \
--enable-gd-jis-conv \
--enable-hash \
--with-mcrypt \
--with-iconv \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-pdo \
--enable-posix \
--enable-libxml \
--enable-simplexml \
--with-sqlite \
--enable-tokenizer \
--enable-xmlreader \
--enable-xmlwriter \
--enable-sockets \
--with-zlib \
--with-gd \
--with-jpeg-dir=/usr/lib/libjpeg.so \
--with-zlib-dir=/usr/lib/libz.so \
--with-mime-magic \
--with-mysql=/opt/mysql-5.0.22 \
--with-pdo-mysql=/opt/mysql-5.0.22 \
--with-pdo-sqlite \
--enable-posix \
--enable-soap \
--with-mhash \
--enable-pcntl \
--with-iconv \
--enable-fpm \
--with-freetype-dir \
--with-curl \
--with-curlwrappers
make && make install
cp php.ini-dist /opt/php-5.2.6/lib/php.ini
mv /opt/php-5.2.6/etc/php-fpm.conf /opt/php-5.2.6/etc/php-fpm.conf.bak
cp php-fpm.conf /opt/php-5.2.6/etc/php-fpm.conf
/opt/php-5.2.6/sbin/php-fpm start
cd ..
echo "/opt/php-5.2.6/sbin/php-fpm start">>/etc/rc.local

# PCRE INSTALL	
tar -zxvf pcre-7.8.tar.gz
cd pcre-7.8
./configure && make && make install
cd ..

# NGINX INSTALL
tar -zxvf nginx-1.0.5.tar.gz
cd nginx-1.0.5
./configure --user=www --group=www --prefix=/opt/nginx-1.0.5 --with-http_stub_status_module --with-http_ssl_module
make && make install
mv /opt/nginx-1.0.5/conf/nginx.conf /opt/nginx-1.0.5/conf/nginx.conf.bak
cp nginx.conf /opt/nginx-1.0.5/conf/nginx.conf
cp config.conf /opt/nginx-1.0.5/conf/config.conf
cp php.conf /opt/nginx-1.0.5/conf/php.conf
echo "/opt/nginx-1.0.5/sbin/nginx">>/etc/rc.local
