#!/bin/sh
group=mysql
user=mysql
#create group if not exists
egrep "^$group" /etc/group >& /dev/null
if [ $? -ne 0 ]
then
groupadd $group
fi
#create user if not exists
egrep "^$user" /etc/passwd >& /dev/null
if [ $? -ne 0 ]
then
useradd -g $group $user
fi
sofeware_file="/home/sofeware"
get_mysql_url="http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz"
mysql_dir="/usr/local/webserver/mysql"
if [ -n "$1" ];then
get_mysql_url=$1
fi
if [ ! -d "${sofeware_file}" ];then
mkdir -p ${sofeware_file}
fi
cd ${sofeware_file}
mysql_file=$(find `dirname $sofeware_file` -name *mysql*.tar.gz)
if [ ! -e "${mysql_file}" ];then
wget ${get_mysql_url}
if [ $? -ne 0 ];then
read -p "Remote access failed, do you use default address access?(y/n)" name
if [ "y" = "$name" ];then
wget --no-check-certificate http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
if [ $? -ne 0 ]; then
echo "Remote access to tomcat installation package failed!"
exit 0
fi
else
exit 0
fi
fi
fi
mysql_file=$(find `dirname $sofeware_file` -name *mysql*.tar.gz)
if [ ! -d "${mysql_dir}" ];then
mkdir -p ${mysql_dir}
if [ $? -ne 0 ];then
exit 0
fi
tar zxvf ${mysql_file##*/} -C ${mysql_dir}
fi
wj_file=$(ls $mysql_dir/ -l| awk '/^d/{print $NF}')
wj_new_file=${mysql_dir}/${wj_file}
cd ${wj_new_file}
mkdir ./data/mysql
chown -R mysql:mysql .
./scripts/mysql_install_db --user=mysql --datadir=${wj_new_file}/data/mysql
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
cp support-files/my-default.cnf /etc/my.cnf
datadir="${wj_new_file}/data/mysql"
sed -i "46s#basedir=#basedir=${wj_new_file}#" /etc/init.d/mysqld
sed -i "47s#datadir=#datadir=${datadir}#" /etc/init.d/mysqld
chkconfig --add mysqld
service mysqld start