Linux Centos7 升级最新版OpenSSH-9.6p1 有脚本(支持离线)
立即下载
资源介绍:
包含升级的rpm文件
openssh-9.6p1.tar.gz
openssl-1.1.1q.tar.gz
zlib-1.3.tar.gz
以及升级脚本
sshupdate2.sh
#!/bin/bash
#
#########################################################
# Function :openssh-9.6p1 update #
# Platform :Centos7.X #
# Version :2.0 #
# Date :2022-05-01 #
#########################################################
clear
export LANG="en_US.UTF-8"
#修改1:此处的zlib原来的版本zlib-1.2提示下载失败,改完zlib-1.3可正常下载,openssl和openssh下载不同的版本在此处修改版本号即可
zlib_version="zlib-1.3"
openssl_version="openssl-1.1.1q"
openssh_version="openssh-9.6p1"
#安装包地址,这里存在一个问题,如果文件夹没有提前建好,后续执行脚本将报错
file="/opt"
#默认编译路径
default="/usr/local"
date_time=`date +%Y-%m-%d—%H:%M`
#安装目录
file_install="$file/openssh_install"
file_backup="$file/openssh_backup"
file_log="$file/openssh_log"
#修改2:为了解决文件夹不存在的问题,我这里添加了创建文件夹的脚本---start
if [ ! -d "$file_install" ]; then
mkdir "$file_install"
fi
if [ ! -d "$file_backup" ]; then
mkdir "$file_backup"
fi
if [ ! -d "$file_log" ]; then
mkdir "$file_log"
fi
if [ ! -d "$file_install/zlib" ]; then
mkdir "$file_install/zlib"
fi
#修改2:为了解决文件夹不存在的问题,我这里添加了创建文件夹的脚本---end
#源码包链接
zlib_download="https://www.zlib.net/$zlib_version.tar.gz"
openssl_download="https://www.openssl.org/source/$openssl_version.tar.gz"
openssh_download="https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/$openssh_version.tar.gz"
Install_make()
{
# Check if user is root
if [ $(id -u) != "0" ]; then
echo -e "\033[33m--------------------------------------------------------------- \033[0m"
echo -e " 当前用户为普通用户,必须使用root用户运行,脚本退出中......" "\033[31m Error\033[0m"
echo -e "\033[33m--------------------------------------------------------------- \033[0m"
echo ""
sleep 4
exit
fi
#判断是否安装wget
echo -e "\033[33m 正在安装Wget...... \033[0m"
sleep 2
echo ""
if ! type wget >/dev/null 2>&1; then
yum install -y wget
else
echo -e "\033[33m--------------------------------------------------------------- \033[0m"
echo -e " wget已经安装了:" "\033[32m Please continue\033[0m"
echo -e "\033[33m--------------------------------------------------------------- \033[0m"
echo ""
fi
#判断是否安装tar
echo -e "\033[33m 正在安装TAR...... \033[0m"
sleep 2
echo ""
if ! type tar >/dev/null 2>&1; then
yum install -y tar
else
echo ""
echo -e "\033[33m--------------------------------------------------------------- \033[0m"
echo -e " tar已经安装了:" "\033[32m Please continue\033[0m"
echo -e "\033[33m--------------------------------------------------------------- \033[0m"
fi
echo ""
#安装相关依赖包
echo -e "\033[33m 正在安装依赖包...... \033[0m"
sleep 3
echo ""
# yum install gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel pam-devel zlib-devel tcp_wrappers-devel tcp_wrappers
if [ $? -eq 0 ];then
echo ""
echo -e "\033[33m--------------------------------------------------------------- \033[0m"
echo -e " 安装软件依赖包成功 " "\033[32m Success\033[0m"
echo -e "\033[33m--------------------------------------------------------------- \033[0m"
else
echo -e "\033[33m--------------------------------------------------------------- \033[0m"
echo -e " 解压源码包失败,脚本退出中......" "\033[31m Error\033[0m"
echo -e "\033[33m--------------------------------------------------------------- \033[0m"
sleep 4
exit
fi
echo ""
}
Install_backup()
{
#创建文件(可修改)
mkdir -p $file_install
mkdir -p $file_backup
mkdir -p $file_log
mkdir -p $file_backup/zlib
mkdir -p $file_backup/ssl
mkdir -p $file_backup/ssh
mkdir -p $file_log/zlib
mkdir -p $file_log/ssl
mkdir -p $file_log/ssh
#备份文件(可修改)
cp -rf /usr/bin/openssl $file_backup/ssl/openssl_$date_time.bak > /dev/null
cp -rf /etc/init.d/sshd $file_backup/ssh/sshd_$date_time.bak > /dev/null
cp -rf /etc/ssh $file_backup/ssh/ssh_$date_time.bak > /dev/null
cp -rf /usr/lib/systemd/system/sshd.service $file_backup/ssh/sshd_$date_time.service.bak > /dev/null
cp -rf /etc/pam.d/sshd.pam $file_backup/ssh/sshd_$date_time.pam.bak > /dev/null
}
Remove_openssh()
{
##并卸载原有的openssh(可修改)
rpm -e --nodeps `rpm -qa | grep openssh`
}
Install_tar()
{
#下载的源码包,检查是否解压(可修改)
# if [ -e $file/$zlib_version.tar.gz ] && [ -e $file/$openssl_version.tar.gz ] && [ -e /$file/$openssh_version.tar.gz ];then
# echo -e " 下载软件源码包已存在 " "\033[32m Please continue\033[0m"
# else
# echo -e "\033[33m 未发现本地源码包,链接检查获取中........... \033[0m "
# echo ""
# cd $file
# wget --no-check-certificate $zlib_download
# wget --no-check-certificate $openssl_download
# wget --no-check-certificate $openssh_download
# echo ""
# fi
#zlib
echo -e "\033[33m 正在下载Zlib软件包...... \033[0m"
sleep 3
echo ""
if [ -e $file/$zlib_version.tar.gz ] ;then
echo -e " 下载软件源码包已存在 " "\033[32m Please continue\033[0m"
else
echo -e "\033[33m 未发现zlib本地源码包,链接检查获取中........... \033[0m "
sleep 1
echo ""
cd $file
wget --no-check-certificate $zlib_download
echo ""
fi
#openssl
echo -e "\033[33m 正在下载Openssl软件包...... \033[0m"
sleep 3
echo ""
if [ -e $file/$openssl_version.tar.gz ] ;then
echo -e " 下载软件源码包已存在 " "\033[32m Please continue\033[0m"
else
echo -e "\033[33m 未发现openssl本地源码包,链接检查获取中........... \033[0m "
echo ""
sleep 1
cd $file
wget --no-check-certificate $openssl_download
echo ""
fi
#openssh
echo -e "\033[33m 正在下载Openssh软件包...... \033[0m"
sleep 3
echo ""
if [ -e /$file/$openssh_version.tar.gz ];then
echo -e " 下载软件源码包已存在 " "\033[32m Please continue\033[0m"
else
echo -e "\033[33m 未发现openssh本地源码包,链接检查获取中........... \033[0m "
echo ""
sleep 1
cd $file
wget --no-check-certificate $openssh_download
fi
}
echo ""
echo ""
#安装zlib
Install_zlib(){
echo -e "\033[33m 1.1-正在解压Zlib软件包...... \033[0m"
sleep 3
echo ""
cd $file && mkdir -p $file_install && tar -xzf zlib*.tar.gz -C $file_install > /dev/null
if [ -d $file_install/$zilb_version ];then
echo -e "\033[33m--------------------------------------------------------------- \033[0m"
echo -e " zilb解压源码包成功" "\033[32m Success\033[0m"
echo -e "\033[33m--------------------------------------------------------------- \033[0m"
echo ""
else
echo -e "\033[33m--------------------------------------------------------------- \033[0m"
echo -e " zilb解压源码包失败,脚本退出中......" "\033[31m Error\033[0m"
echo -e "\033[33m--------------------------------------------------------------- \033[0m"
echo ""
sleep 4
exit
fi
echo -e "\033[33m 1.2-正在编译安装Zlib服务.............. \033[0m"
sleep 3
echo ""
#这里原脚本写法:cd $file_install/zlib*,我遇到了cd目录失败问题,将此处修改如下
cd $file_install/$zlib_version
echo -e "$pwd"
./configure --prefix=$default/$zlib_version > $file_log/zlib/zlib_configure_$date_time.txt #> /dev/null 2>&1
if [ $? -eq 0 ];then
echo -e "\033[33m make... \033[0m"
make > /dev/null 2>&1
echo $?
echo -e "\033[33m make test... \033[0m"
make test > /dev/null 2>&1
echo $?
echo -e "\033[33m make install... \033[0m"
make install > /dev/null 2>&1
echo $?
else
echo -e "\033[33m--------------------------------------------------------------- \033[0m"
echo -e " 编译安装压缩库失败,脚本退出中..." "\033[31m Error\033[0m"
echo -e "\033[33m-------------