Nginx升级脚本

2011年4月15日 | 分类: Linux | 标签: , , , , , ,

特点:在原来的基础上添加检查输入的版本号是否存在功能,防止意外输错。
upgrade_nginxupgrade_nginx

wget http://www.yishanhome.com/wp-content/uploads/2011/04/upgrade_nginx.sh;sh upgrade_nginx.sh

#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
 
# Check if user is root
if [ $(id -u) != "0" ]; then
    echo "Error: You must be root to run this script, please use root to install lnmp"
    exit 1
fi
 
clear
echo "========================================================================="
echo "Upgrade Nginx for LNMP,  Written by Licess"
echo "========================================================================="
echo "LNMP is tool to auto-compile & install Nginx+MySQL+PHP on Linux "
echo ""
echo "For more information please visit http://www.lnmp.org"
echo ""
echo "Add check to download http://www.yishanhome.com"
echo "========================================================================="
 
nv=`/usr/local/nginx/sbin/nginx -v 2>&1`
old_nginx_version=`echo $nv | cut -c22-`
#echo $old_nginx_version
 
if [ "$1" != "--help" ]; then
 
#set nginx version
 
	nginx_version=""
	echo "Current Nginx Version:$old_nginx_version"
	echo "Please input nginx version you want:"
	echo "You can get version number from http://nginx.org/en/download.html"
check_source()
{
  echo "checking $1"
  httpvalue=`wget -nv --spider $1 2>&1|sed q|awk '{print $1}'`
  if [ -z $httpvalue ]; then
    echo "OK!"
  else
   echo -e '\033[0;31;1mError: NOT accessible, please You input nginx version!!\033[0m'
   input_nginx_version
  fi
}
input_nginx_version()
{
	read -p "(example: 0.8.54 ):" nginx_version
	if [ "$nginx_version" = "" ]; then
	echo -e '\033[0;31;1mError: You must input nginx version!!\033[0m'
		input_nginx_version
		else
check_source http://nginx.org/download/nginx-$nginx_version.tar.gz
	fi
}
input_nginx_version
	echo "==========================="
 
	echo "You want to upgrade nginx version to $nginx_version"
 
	echo "==========================="
 
	get_char()
	{
	SAVEDSTTY=`stty -g`
	stty -echo
	stty cbreak
	dd if=/dev/tty bs=1 count=1 2> /dev/null
	stty -raw
	stty echo
	stty $SAVEDSTTY
	}
	echo ""
	echo "Press any key to start...or Press Ctrl+c to cancel"
	char=`get_char`
 
echo "============================check files=================================="
if [ -s nginx-$nginx_version.tar.gz ]; then
  echo "nginx-$nginx_version.tar.gz [found]"
  else
  echo "Error: nginx-$nginx_version.tar.gz not found!!!download now......"
  wget -c http://nginx.org/download/nginx-$nginx_version.tar.gz
fi
echo "============================check files=================================="
 
 
tar zxvf nginx-$nginx_version.tar.gz
cd nginx-$nginx_version/
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6
make
 
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
cp objs/nginx /usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx -t
make upgrade
echo "Upgrade completed!"
echo "Program will display Nginx Version......"
/usr/local/nginx/sbin/nginx -v
cd ../
 
echo "========================================================================="
echo "You have successfully upgrade from $old_nginx_version to $nginx_version"
echo "========================================================================="
echo "LNMP is tool to auto-compile & install Nginx+MySQL+PHP on Linux "
echo "========================================================================="
echo ""
echo "For more information please visit http://www.lnmp.org/"
echo ""
echo "========================================================================="
fi

原文: LNMP一键安装包 自动无缝升级Nginx至任意版本 http://blog.licess.org/lnmp-upgrade-any-nginx-version/

目前还没有任何评论.

返回顶部