当前位置:文档之家› mysql自动化安装脚本

mysql自动化安装脚本

#! /usr/bin/ksh

#--common condiction.

set_system_type()

{

if [ -z "$UTYPE" ]; then

UTYPE=Generic

if [ -s /usr/bin/uname ]; then UTYPE=`/usr/bin/uname`; fi

if [ -s /bin/uname ]; then UTYPE=`/bin/uname`; fi if [ -d /var/sadm/pkg/UnixWare ]; then UTYPE=UnixWare; fi fi

if [ "$UTYPE" = "SunOS" ]; then

PROCESSTYPE=`uname -p`

if [ "$PROCESSTYPE" = "i386" ]; then

UTYPE="SunOS SOLARISX86"

fi

fi

}

my_host_name()

{

if [ "$UTYPE" = "" ]; then

echo "UTYPE is null.";

exit_install 1

fi

if [ "$UTYPE" = "AIX" ]; then

MY_HOST_NAME=`uname -n`;

elif [ "$UTYPE" = "BSD/OS" ]; then

MY_HOST_NAME=`uname -n`;

elif [ "$UTYPE" = "FreeBSD" ]; then

MY_HOST_NAME=`uname -n`;

elif [ "$UTYPE" = "HP-UX" ]; then

MY_HOST_NAME=`uname -n`;

elif [ "$UTYPE" = "Linux" ]; then

MY_HOST_NAME=`uname -n`;

elif [ "$UTYPE" = "SCO" ]; then

MY_HOST_NAME=`uname -n`;

elif [ "$UTYPE" = "SunOS" ]; then

MY_HOST_NAME=`uname -n`;

elif [ "$UTYPE" = "SunOS SOLARISX86" ]; then

MY_HOST_NAME=`uname -n`;

elif [ "$UTYPE" = "OSF1" ]; then

MY_HOST_NAME=`uname -n`;

elif [ "$UTYPE" = "UnixWare" ]; then

MY_HOST_NAME=`uname -n`;

elif [ "$UTYPE" = "Tandem" ]; then

MY_HOST_NAME=`uname -n`;

else

echo "unknown UTYPE '$UTYPE'.";

exit_install 1

fi

}

my_host_ip()

{

if [ "$UTYPE" != "" ]; then

if [ "$UTYPE" = "AIX" ]; then

MY_HOST_IP=`cat /etc/hosts | grep ${MY_HOST_NAME} | awk '{print $1}'` elif [ "$UTYPE" = "BSD/OS" ]; then

MY_HOST_IP=`cat /etc/hosts | grep ${MY_HOST_NAME} | awk '{print $1}'` elif [ "$UTYPE" = "FreeBSD" ]; then

MY_HOST_IP=`cat /etc/hosts | grep ${MY_HOST_NAME} | awk '{print $1}'` elif [ "$UTYPE" = "HP-UX" ]; then

MY_HOST_IP=`cat /etc/hosts | grep ${MY_HOST_NAME} | awk '{print $1}'` elif [ "$UTYPE" = "Linux" ]; then

MY_HOST_IP=`cat /etc/hosts | grep ${MY_HOST_NAME} | awk '{print $1}'` elif [ "$UTYPE" = "SCO" ]; then

MY_HOST_IP=`cat /etc/hosts | grep ${MY_HOST_NAME} | awk '{print $1}'` elif [ "$UTYPE" = "SunOS" ]; then

MY_HOST_IP=`cat /etc/hosts | grep ${MY_HOST_NAME} | awk '{print $1}'` elif [ "$UTYPE" = "SunOS SOLARISX86" ]; then

MY_HOST_IP=`cat /etc/hosts | grep ${MY_HOST_NAME} | awk '{print $1}'` elif [ "$UTYPE" = "OSF1" ]; then

MY_HOST_IP=`cat /etc/hosts | grep ${MY_HOST_NAME} | awk '{print $1}'` elif [ "$UTYPE" = "UnixWare" ]; then

MY_HOST_IP=`cat /etc/hosts | grep ${MY_HOST_NAME} | awk '{print $1}'` elif [ "$UTYPE" = "Tandem" ]; then

MY_HOST_IP=`cat /etc/hosts | grep ${MY_HOST_NAME} | awk '{print $1}'` fi

fi

}

#$1:hostname

host_ip()

{

if [ "$UTYPE" != "" ]; then

if [ "$UTYPE" = "AIX" ]; then

HOST_IP=`cat /etc/hosts | grep $1 | awk '{print $1}'` elif [ "$UTYPE" = "BSD/OS" ]; then

HOST_IP=`cat /etc/hosts | grep $1 | awk '{print $1}'` elif [ "$UTYPE" = "FreeBSD" ]; then

HOST_IP=`cat /etc/hosts | grep $1 | awk '{print $1}'` elif [ "$UTYPE" = "HP-UX" ]; then

HOST_IP=`cat /etc/hosts | grep $1 | awk '{print $1}'` elif [ "$UTYPE" = "Linux" ]; then

HOST_IP=`cat /etc/hosts | grep $1 | awk '{print $1}'` elif [ "$UTYPE" = "SCO" ]; then

HOST_IP=`cat /etc/hosts | grep $1 | awk '{print $1}'` elif [ "$UTYPE" = "SunOS" ]; then

HOST_IP=`cat /etc/hosts | grep $1 | awk '{print $1}'` elif [ "$UTYPE" = "SunOS SOLARISX86" ]; then

HOST_IP=`cat /etc/hosts | grep $1 | awk '{print $1}'` elif [ "$UTYPE" = "OSF1" ]; then

HOST_IP=`cat /etc/hosts | grep $1 | awk '{print $1}'` elif [ "$UTYPE" = "UnixWare" ]; then

HOST_IP=`cat /etc/hosts | grep $1 | awk '{print $1}'` elif [ "$UTYPE" = "Tandem" ]; then

HOST_IP=`cat /etc/hosts | grep $1 | awk '{print $1}'` else

HOST_IP=""

fi

fi

}

#$1:prompt

echo_prompt()

{

if [ "$UTYPE" = "AIX" ]; then

echo "$1\c";

elif [ "$UTYPE" = "BSD/OS" ]; then

echo "$1";

elif [ "$UTYPE" = "FreeBSD" ]; then

echo "$1";

elif [ "$UTYPE" = "HP-UX" ]; then

echo "$1\c";

elif [ "$UTYPE" = "Linux" ]; then

echo -n "$1";

elif [ "$UTYPE" = "SCO" ]; then

echo "$1";

elif [ "$UTYPE" = "SunOS" ]; then

echo "$1";

elif [ "$UTYPE" = "SunOS SOLARISX86" ]; then

echo "$1";

elif [ "$UTYPE" = "OSF1" ]; then

echo -n "$1";

elif [ "$UTYPE" = "UnixWare" ]; then

echo "$1";

elif [ "$UTYPE" = "Tandem" ]; then

echo "$1";

fi

}

my_host_attribute()

{

if [ "$UTYPE" = "AIX" ]; then

SAG_MY_PROFILE_NAME=".profile";

SAG_MY_PID_INDEX=2;

SAG_MY_ROOT_ACCOUNT_NAME="root";

ETC_SCFSS7_SC="config.service.bin.big";

ETC_WINFEP_SC="config.service.bin.big";

BIN_SMSAGENT_EXE_OS="${BIN_SMSAGENT_EXE}.${UTYPE}";

BIN_ISMAPAGENT_EXE_OS="${BIN_ISMAPAGENT_EXE}.${UTYPE}";

elif [ "$UTYPE" = "BSD/OS" ]; then

SAG_MY_PROFILE_NAME=".profile";

SAG_MY_PID_INDEX=1;

SAG_MY_ROOT_ACCOUNT_NAME="root";

ETC_SCFSS7_SC="config.service.bin.little";

ETC_WINFEP_SC="config.service.bin.little";

elif [ "$UTYPE" = "FreeBSD" ]; then

SAG_MY_PROFILE_NAME=".profile";

SAG_MY_PID_INDEX=1;

SAG_MY_ROOT_ACCOUNT_NAME="root";

ETC_SCFSS7_SC="config.service.bin.little";

ETC_WINFEP_SC="config.service.bin.little";

elif [ "$UTYPE" = "HP-UX" ]; then

SAG_MY_PROFILE_NAME=".profile";

SAG_MY_PID_INDEX=1;

SAG_MY_ROOT_ACCOUNT_NAME="root";

ETC_SCFSS7_SC="config.service.bin.big";

ETC_WINFEP_SC="config.service.bin.big";

BIN_SMSAGENT_EXE_OS="${BIN_SMSAGENT_EXE}.${UTYPE}";

BIN_ISMAPAGENT_EXE_OS="${BIN_ISMAPAGENT_EXE}.${UTYPE}";

elif [ "$UTYPE" = "Linux" ]; then

SAG_MY_PROFILE_NAME=".bash_profile";

SAG_MY_PID_INDEX=1;

SAG_MY_ROOT_ACCOUNT_NAME="root";

ETC_SCFSS7_SC="config.service.bin.little";

ETC_WINFEP_SC="config.service.bin.little";

BIN_SMSAGENT_EXE_OS="${BIN_SMSAGENT_EXE}.${UTYPE}";

BIN_ISMAPAGENT_EXE_OS="${BIN_ISMAPAGENT_EXE}.${UTYPE}"; elif [ "$UTYPE" = "SCO" ]; then

SAG_MY_PROFILE_NAME=".profile";

SAG_MY_PID_INDEX=1;

SAG_MY_ROOT_ACCOUNT_NAME="root";

ETC_SCFSS7_SC="config.service.bin.big";

ETC_WINFEP_SC="config.service.bin.big";

BIN_SMSAGENT_EXE_OS="${BIN_SMSAGENT_EXE}.${UTYPE}";

BIN_ISMAPAGENT_EXE_OS="${BIN_ISMAPAGENT_EXE}.${UTYPE}"; elif [ "$UTYPE" = "SunOS" ]; then

SAG_MY_PROFILE_NAME=".profile";

SAG_MY_PID_INDEX=1;

SAG_MY_ROOT_ACCOUNT_NAME="root";

ETC_SCFSS7_SC="config.service.bin.big";

ETC_WINFEP_SC="config.service.bin.big";

BIN_SMSAGENT_EXE_OS="${BIN_SMSAGENT_EXE}.${UTYPE}";

BIN_ISMAPAGENT_EXE_OS="${BIN_ISMAPAGENT_EXE}.${UTYPE}"; elif [ "$UTYPE" = "SunOS SOLARISX86" ]; then

SAG_MY_PROFILE_NAME=".profile";

SAG_MY_PID_INDEX=1;

SAG_MY_ROOT_ACCOUNT_NAME="root";

ETC_SCFSS7_SC="config.service.bin.big";

ETC_WINFEP_SC="config.service.bin.big";

BIN_SMSAGENT_EXE_OS="${BIN_SMSAGENT_EXE}";

BIN_ISMAPAGENT_EXE_OS="${BIN_ISMAPAGENT_EXE}";

elif [ "$UTYPE" = "OSF1" ]; then

SAG_MY_PROFILE_NAME=".profile";

SAG_MY_PID_INDEX=1;

SAG_MY_ROOT_ACCOUNT_NAME="root";

ETC_SCFSS7_SC="config.service.bin.little";

ETC_WINFEP_SC="config.service.bin.little";

BIN_SMSAGENT_EXE_OS="${BIN_SMSAGENT_EXE}.${UTYPE}";

BIN_ISMAPAGENT_EXE_OS="${BIN_ISMAPAGENT_EXE}.${UTYPE}"; elif [ "$UTYPE" = "UnixWare" ]; then

SAG_MY_PROFILE_NAME=".profile";

SAG_MY_PID_INDEX=1;

SAG_MY_ROOT_ACCOUNT_NAME="root";

ETC_SCFSS7_SC="config.service.bin.little";

ETC_WINFEP_SC="config.service.bin.little";

elif [ "$UTYPE" = "Tandem" ]; then

SAG_MY_PROFILE_NAME=".profile";

SAG_MY_PID_INDEX=1;

SAG_MY_ROOT_ACCOUNT_NAME="root";

ETC_SCFSS7_SC="config.service.bin.big";

ETC_WINFEP_SC="config.service.bin.big";

fi

}

set_install_dir()

{

CC_INSTALL_DIR=`pwd`;

if [ "${CC_INSTALL_DIR}" = "/" ]; then

CC_INSTALL_DIR=.

fi

}

reenter_install_dir()

{

if [ "${CC_INSTALL_DIR}" = "." ]; then

cd /

else

cd ${CC_INSTALL_DIR}

fi

}

set_install_account_name()

{

CC_INSTALL_ACCOUNT_NAME=`whoami`;

}

check_file_executable()

{

if [ ! -x $1 ]

then

echo "'$1' does not existed or is not executable.";

exit_install 1

fi

}

check_file_exist()

{

if [ ! -f $1 ]

then

echo "'$1' does not existed.";

exit_install 1

else

echo "'$1' existed.";

fi

}

exit_install()

{

echo "install program exit."

exit $1

}

system_specific_base()

{

if [ "$UTYPE" = "AIX" ]; then

SYS_ENV_EXTSHM=`cat /etc/profile | grep EXTSHM=ON | wc -l`

if [ $SYS_ENV_EXTSHM -lt 1 ]; then

echo "

EXTSHM=ON

export EXTSHM

" >> /etc/profile;

fi

fi

}

#$1:username

enter_user_indown_exit()

{

if [ -d ${SAG_ACCOUNT_BASE_DIR}/$1 ]; then

su - $1;

echo " --prepare execute $HOME/${SAG_CIN_SCF_BASE_DIR}/bin/indown"

$HOME/${SAG_CIN_SCF_BASE_DIR}/bin/indown;

$HOME/${SAG_CIN_SCF_BASE_DIR}/bin/indown;

echo " --finished $HOME/${SAG_CIN_SCF_BASE_DIR}/bin/indown, exit from $1"

exit;

fi

}

#$1:username

enter_user_ininit_exit()

{

if [ -d ${SAG_ACCOUNT_BASE_DIR}/$1 ]; then

su - $1;

ininit;

exit;

fi

}

#$1:filename $2:directory $3:target_base_dir $4:basename $5:target_filename

file_exist_then_copy()

{

tfilename=$1;

if [ "$5" != "" ]; then

tfilename=$5;

fi

if [ -f ${SAG_INSTALL_DIR}/$4/$2/$1 ]; then

if [ -f $3/${SAG_CIN_SCF_BASE_DIR}/$2/${tfilename} ]; then

cp ${SAG_INSTALL_DIR}/$4/$2/$1 $3/${SAG_CIN_SCF_BASE_DIR}/$2/${tfilename};

echo "patch '${SAG_INSTALL_DIR}/$4/$2/$1' existed, updated on-line '$3/${SAG_CIN_SCF_BASE_DIR}/$2/${tfilename}' successfully.";

else

echo "on-line '$3/${SAG_CIN_SCF_BASE_DIR}/$2/${tfilename}' does not existed, can't update!!";

fi

else

echo "patch '${SAG_INSTALL_DIR}/$4/$2/$1' does not existed, ignored.";

fi

}

welcome()

{

echo "welcome to use mysql install program."

}

create_account_directory()

{

if [ ! -d ${SAG_ACCOUNT_BASE_DIR} ]; then

mkdir ${SAG_ACCOUNT_BASE_DIR};

fi

}

#$1:directory

create_directory()

{

if [ ! -d $1 ]; then

mkdir $1;

fi

}

# $1:username $2:all users lies's group $3:baseDir

add_user()

{

echo " -- add user $1 ...";

echo " -- system $UTYPE";

if [ "$UTYPE" = "AIX" ]; then

useradd -c $1 -d $3/$1 -m -g $2 -s /bin/sh $1;

elif [ "$UTYPE" = "BSD/OS" ]; then

useradd -c $1 -d $3/$1 -m -g $2 -p -s /bin/sh $1;

elif [ "$UTYPE" = "FreeBSD" ]; then

useradd -c $1 -d $3/$1 -m -g $2 -p -s /bin/sh $1;

elif [ "$UTYPE" = "HP-UX" ]; then

useradd -c $1 -d $3/$1 -m -g $2 -s /bin/sh $1;

elif [ "$UTYPE" = "Linux" ]; then

useradd -c $1 -d $3/$1 -m -g $2 -s /bin/bash $1;

elif [ "$UTYPE" = "SCO" ]; then

useradd -c $1 -d $3/$1 -m -g $1 -p -s /bin/sh $1;

elif [ "$UTYPE" = "SunOS" ]; then

useradd -c $1 -d $3/$1 -m -g $2 -s /bin/sh $1;

elif [ "$UTYPE" = "SunOS SOLARISX86" ]; then useradd -c $1 -d $3/$1 -m -g $2 -p -s /bin/sh $1;

elif [ "$UTYPE" = "OSF1" ]; then

useradd -c $1 -d $3/$1 -m -g $2 -p -s /bin/sh $1;

elif [ "$UTYPE" = "UnixWare" ]; then

useradd -c $1 -d $3/$1 -m -g $2 -p -s /bin/sh $1;

elif [ "$UTYPE" = "Tandem" ]; then

useradd -c $1 -d $3/$1 -m -g $2 -p -s /bin/sh $1;

fi

if [ $? -ne 0 ]; then

echo " -- add user $1 failure[$?].";

exit_install 1

else

echo " -- add user $1 success.";

fi

}

judge_root()

{

if [ "${CC_INSTALL_ACCOUNT_NAME}" != "${ROOT_ACCOUNT_NAME}" ]; then echo "please execute this task in account '${ROOT_ACCOUNT_NAME}'!!";

exit;

fi

}

Mysql_install()

{

echo "Mysql_install";

echo ${CC_MYSQL_ACCOUNT};

echo ${CC_ACCOUNT_GROUP};

echo ${CC_BASE_DIR};

echo ""

echo "---- begin to create group ...";

groupadd ${CC_ACCOUNT_GROUP};

echo "---- begin to create account ...";

add_user ${CC_MYSQL_ACCOUNT} ${CC_ACCOUNT_GROUP} ${CC_BASE_DIR};

echo "---- end to create account ";

echo ""

cp ${CC_MYSQL_FILE}.tar.gz ${CC_BASE_DIR}/${CC_MYSQL_ACCOUNT}/;

gzip -d ${CC_BASE_DIR}/${CC_MYSQL_ACCOUNT}/${CC_MYSQL_FILE}.tar.gz;

tar xvf ${CC_BASE_DIR}/${CC_MYSQL_ACCOUNT}/${CC_MYSQL_FILE}.tar -C ${CC_BASE_DIR}/${CC_MYSQL_ACCOUNT};

rm ${CC_BASE_DIR}/${CC_MYSQL_ACCOUNT}/${CC_MYSQL_FILE}.tar;

echo "---- begin to complie mysql ...";

cd ${CC_BASE_DIR}/${CC_MYSQL_ACCOUNT}/${CC_MYSQL_FILE};

./configure -prefix=${CC_BASE_DIR}/${CC_MYSQL_ACCOUNT} --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static -with-extra-charsets=all

--with-plugins=all --with-pthread --enable-thread-safe-client --enable-local-infile;

make;

make install;

cd $CC_INSTALL_DIR;

cp ${CC_BASE_DIR}/${CC_MYSQL_ACCOUNT}/share/mysql/mysql.server ${CC_BASE_DIR}/${CC_MYSQL_ACCOUNT}/bin/mysql.server;

cp https://www.doczj.com/doc/869301101.html,f /etc/https://www.doczj.com/doc/869301101.html,f;

${CC_BASE_DIR}/${CC_MYSQL_ACCOUNT}/bin/mysql_install_db;

chmod 755 ${CC_BASE_DIR}/${CC_MYSQL_ACCOUNT};

chown -R ${CC_MYSQL_ACCOUNT} ${CC_BASE_DIR}/${CC_MYSQL_ACCOUNT};

chgrp -R ${CC_ACCOUNT_GROUP} ${CC_BASE_DIR}/${CC_MYSQL_ACCOUNT};

${CC_BASE_DIR}/${CC_MYSQL_ACCOUNT}/bin/mysql.server stop;

${CC_BASE_DIR}/${CC_MYSQL_ACCOUNT}/bin/mysql.server start;

#${CC_BASE_DIR}/${CC_MYSQL_ACCOUNT}/bin/mysqladmin -uroot -password 'root123';

${CC_BASE_DIR}/${CC_MYSQL_ACCOUNT}/bin/mysql -uroot < mysql.sql;

echo ""

echo "---- end to install program code";

}

main()

{

set_system_type;

welcome;

set_install_dir;

set_install_account_name;

judge_root;

my_host_name;

my_host_ip;

echo ${UTYPE};

echo ${MY_HOST_NAME};

echo ${MY_HOST_IP};

echo $CC_INSTALL_DIR;

echo $CC_INSTALL_ACCOUNT_NAME;

Mysql_install;

}

ROOT_ACCOUNT_NAME=root;

CC_ACCOUNT_GROUP=mysql

CC_MYSQL_ACCOUNT=mysql;

CC_BASE_DIR=/home;

CC_MYSQL_FILE=mysql-5.1.44;

main $*;

exit 1

相关主题
文本预览
相关文档 最新文档