Linux6.3升级zlib

#!/bin/bash
# 脚本适用于Linux6.3升级zlib版本, rpm包应与脚本同级

SCRIPT_DIR=`readlink -f $0|xargs dirname`
# 目标版本
REQ_USER="root"
REQ_PACKAGE="zlib-1.2.3-29.el6.x86_64.rpm"
REQ_LINUX_V="6.3"
REQ_ZLIB_V="zlib-1.2.3-27.el6.x86_64"
TARGET_ZLIB_V="zlib-1.2.3-29.el6.x86_64"

FLAG_USER=0
FLAG_PACKAGE=0
FLAG_LINUX_V=0
FLAG_ZLIB_V=0

# 环境获取
CUR_USER=`whoami`
# CUR_LINUX_V=`cat /etc/redhat-release|awk ‘{print $7}‘`
CUR_LINUX_V=`cat /etc/redhat-release|awk ‘{print $3}‘`
CUR_ZLIB_V=`rpm -qa |grep zlib`


# 前置条件检查
function checkENV(){
	## 判断用户
	## 判断rpm包是否存在
	## 判断系统版本
	## 判断系统已经安装的zlib包的版本
	echo "==CHECK=="
	if [[ $REQ_USER==$CUR_USER ]];then
		FLAG_PACKAGE=1
		echo "[OK] user is $CUR_USER"
	else
		echo "[ERROR] user is $CUR_USER, please use $REQ_USER"
	fi
	if [ -e "$REQ_PACKAGE" ] ;then
		FLAG_PACKAGE=1
		echo "[OK] $REQ_PACKAGE package exsited"
	else
		echo "[ERROR] Not have package $REQ_PACKAGE"
	fi

	if [[ $CUR_LINUX_V==$REQ_LINUX_V ]];then
		FLAG_LINUX_V=1
		echo "[OK] Linux version is $CUR_LINUX_V"
	else
		echo "[ERROR] Linux version is $CUR_LINUX_V,it‘s scripts only used for $REQ_LINUX_V"
	fi

	if [[ $CUR_ZLIB_V==$REQ_ZLIB_V ]];then
		FLAG_ZLIB_V=1
		echo "[OK] zlib version is $CUR_ZLIB_V"
	else
		echo "[ERROR] $CUR_ZLIB_V inappropriate"
	fi
}

# 升级过程
function execUpgrade(){
	## 记录脚本目录
	## cd到1ib64
	## 备份
	## 改软链接
	## 删除已有版本
	## 安装新版本
	## 确认版本
	## 改回软链接
	echo "==Upgrade=="
	cd /lib64
	cp libz.so.1.2.3 libz.so.1.2.3.bak
	ln -snf libz.so.1.2.3.bak libz.so.1
	rpm -e --nodeps zlib
	# rpm -ivh /root/test/zlib-1.2.3-29.el6.x86_64.rpm
	rpm -ivh "$SCRPT_DIR/zlib-1.2.3-29.el6.x86_64.rpm"
	
	if [[ -e "libz.so.1.2.3" ]]; then
		ln -snf libz.so.1.2.3 libz.so.1
	fi

	if [ `rpm -qa |grep zlib` == $TARGET_ZLIB_V ];then
		echo "==Upgrade Success=="
	else
		echo "[ERROR] Upgrade faild"
	fi
}

# 调用
checkENV

if [[ $FLAG_USER && $FLAG_PACKAGE && $FLAG_LINUX_V && $FLAG_ZLIB_V ]] ;then
	execUpgrade
fi

Linux6.3升级zlib

上一篇:树论基础


下一篇:在win10+Ubuntu双系统下,完美卸载Ubuntu