jianshu文章テスト

5157 ワード

テスト

#!/bin/bash
printfHead(){
    clear
    printf "***********************************************************

" printf "\t\tCmPanda MySQL InstallScript
" printf "\t\t Centos 6.X x64

" printf "***********************************************************

" } printfFoot(){ printf "***********************************************************

" printf "\t\tEnd Of Script - CmPanda

" printf "***********************************************************

" } checkYum(){ printf "Checking yum configured ...... " yum list *mysql* >& /dev/null if [ $? -eq 0 ] then yumRes=$(yum list *mysql*) if [[ "$yumRes" =~ .*mysql.*\..*64.* ]] && [[ "$yumRes" =~ .*mysql.*server.*\..*64.* ]] then echo -e "\033[32mSuccess\033[0m
Start update yum" yum -y update all checkMySQL else echo -e "\033[31mFail\033[0m" installAliYum fi else echo -e "\033[31mFail\033[0m" installAliYum fi } installAliYum(){ printf "Check wget com ...... " wget --help >& /dev/null if [ $? -ne 0 ] then echo -e "\033[31mFail
Not find wget com
\033[0m" printfFoot exit 0 fi echo -e "\033[32mSuccess\033[0m" while true do printf "Whether to install aliMirrors (Y/N)? " read res if [ "$res" = "Y" -o "$res" = "y" ] then break elif [ "$res" = "N" -o "$res" = "n" ] then printf "
" printfFoot exit 0 fi done echo -ne "Download aliyun yum.repos ...... " wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo >& /dev/null echo -ne "\033[32mSuccess\033[0m
Clean yum ...... " yum clean all > /dev/null echo -e "\033[32mSuccess\033[0m
MakeCache yum" yum makecache echo -e "Yum Update Done" checkYum } checkMySQL(){ echo " MySQL" mysqlres=$(yum list installed *mysql*) if [[ "$mysqlres" =~ .*mysql.*\..* ]] then echo -e "\033[33m MySQL \033[0m" while true do printf " (Y/N)? " read res if [ "$res" = "Y" -o "$res" = "y" ] then printf "Start remove MySQL ...... " removeMySQL break elif [ "$res" = "N" -o "$res" = "n" ] then echo printfFoot break fi done else printf " MySQL
" installMySQL fi } removeMySQL(){ #yum remove *mysql* > /dev/null yum remove -y *mysql* >& /dev/null echo -e "\033[32mSuccess\033[0m" installMySQL } installMySQL(){ printf "Start Install MySQL
" yum install -y mysql*server*x86_64 printf " , MySQL ...... " service mysqld restart >& /dev/null echo -e "\033[32mSuccess\033[0m" printf " MySQL Root : " read pwd printf " MySQL
MySQL ...... " mysqladmin -u root password $pwd service mysqld restart >& /dev/null echo -e "\033[32mSuccess\033[0m" while true do printf " MySQL (Y/N)? " read res if [ "$res" = "Y" -o "$res" = "y" ] then printf " MySQL ...... " cm1="grant all privileges on *.* to 'root'@'%' identified by '" cm2="' with grant option;" cm=$cm1${pwd}$cm2 mysql -h127.0.0.1 -uroot -p$pwd --port=3306 <& /dev/null echo -e "\033[32mSuccess\033[0m" break elif [ "$res" = "N" -o "$res" = "n" ] then break fi done while true do printf " MySQL (Y/N)? " read res if [ "$res" = "Y" -o "$res" = "y" ] then printf " MySQL ...... " chkconfig mysqld on echo -e "\033[32mSuccess\033[0m" break elif [ "$res" = "N" -o "$res" = "n" ] then break fi done printf "MySQL

" printfFoot } printfHead checkYum