[SHELL脚本练习]阿里云镜像PHP版本切换脚本

717次阅读

共计 2084 个字符,预计需要花费 6 分钟才能阅读完成。

#!/bin/bash
#2017-07-18
#Change PHP Version

. /etc/init.d/functions
clear
#Root test
[ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1

#Current Version
prefix=`cat /etc/init.d/php-fpm | grep ^prefix |awk -F "=" '{print $2}'`
VER=`${prefix}/bin/php -v  | head -1 | awk '{print $2}'`
cat <<EOF
----------------------------------------------------
|******        安畅网络|Anchnet.com     ***********|
|******           PHP Ver Change          *********|
----------------------------------------------------
PHP Version:

	1.PHP 5.4
	2.PHP 5.5
	3.PHP 5.6
	4.PHP 7.0
	5.PHP 7.1
EOF
echo -e "Current Version: \033[36m${VER}\033[0m"
read -p "Please Input The Version: " VERSION
case ${VERSION} in
	1)
		/etc/init.d/php-fpm stop &> /dev/null
		sed -i "s#`grep prefix=/ /etc/init.d/php-fpm`#prefix=/usr/local/php54#g" /etc/init.d/php-fpm
		sed -i "s#/usr/local/php[0-9][0-9]#/usr/local/php54#g" /etc/profile && source /etc/profile
		/etc/init.d/php-fpm start &> /dev/null
		[ $? -eq 0 ] && action "Change Version..." /bin/true
	;;
	2)
		/etc/init.d/php-fpm stop &> /dev/null
		sed -i "s#`grep prefix=/ /etc/init.d/php-fpm`#prefix=/usr/local/php55#g" /etc/init.d/php-fpm
		sed -i "s#/usr/local/php[0-9][0-9]#/usr/local/php55#g" /etc/profile && source /etc/profile
		/etc/init.d/php-fpm start &> /dev/null
		[ $? -eq 0 ] && action "Change Version..." /bin/true
	;;
	3)
		/etc/init.d/php-fpm stop &> /dev/null
		sed -i "s#`grep prefix=/ /etc/init.d/php-fpm`#prefix=/usr/local/php56#g" /etc/init.d/php-fpm
		sed -i "s#/usr/local/php[0-9][0-9]#/usr/local/php56#g" /etc/profile && source /etc/profile
		/etc/init.d/php-fpm start &> /dev/null
		[ $? -eq 0 ] && action "Change Version..." /bin/true
	;;
	4)
		/etc/init.d/php-fpm stop &> /dev/null
		sed -i "s#`grep prefix=/ /etc/init.d/php-fpm`#prefix=/usr/local/php70#g" /etc/init.d/php-fpm
		sed -i "s#/usr/local/php[0-9][0-9]#/usr/local/php70#g" /etc/profile && source /etc/profile
		/etc/init.d/php-fpm start &> /dev/null
		[ $? -eq 0 ] && action "Change Version..." /bin/true
	;;
	5)
		/etc/init.d/php-fpm stop &> /dev/null
		sed -i "s#`grep prefix=/ /etc/init.d/php-fpm`#prefix=/usr/local/php71#g" /etc/init.d/php-fpm
		sed -i "s#/usr/local/php[0-9][0-9]#/usr/local/php71#g" /etc/profile && source /etc/profile
		/etc/init.d/php-fpm start &> /dev/null
		[ $? -eq 0 ] && action "Change Version..." /bin/true
	;;
	*)
		echo -e "\033[31mError!Please Input Write Number.\033[0m"
esac

 

正文完
 
mervinwang
版权声明:本站原创文章,由 mervinwang 2017-08-08发表,共计2084字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
文章搜索