v1.1.0: 新增多系统支持和统一包管理器
主要更新: - 新增支持 Rocky Linux、AlmaLinux、Fedora、openSUSE - 实现统一包管理器检测机制 (APT/YUM/DNF/Zypper) - 优化系统识别逻辑,增加自动检测后备方案 - 完善阿里云镜像源配置,支持更多Linux发行版 - 重构所有系统相关代码,使用PKG_MANAGER变量统一管理 - 添加 install_nodejs_dnf/zypper 和 install_nginx_dnf/zypper 函数 - 更新 deploy_certbot 函数支持所有包管理器 技术改进: - detect_os(): 增强系统检测,自动识别包管理器类型 - configure_aliyun_mirror(): 支持8种主流Linux发行版镜像配置 - install_dependencies(): 统一使用PKG_MANAGER进行依赖安装 - 消除所有OS特定case语句,提高代码可维护性 支持的系统: - Ubuntu/Debian (APT) - CentOS 7/8, RHEL 7/8/9 (YUM/DNF) - Rocky Linux 8/9 (DNF) - AlmaLinux 8/9 (DNF) - Fedora 35+ (DNF) - openSUSE Leap (Zypper)
This commit is contained in:
232
install.sh
232
install.sh
@@ -3,7 +3,7 @@
|
|||||||
################################################################################
|
################################################################################
|
||||||
# 玩玩云 (WanWanYun) - 一键部署脚本
|
# 玩玩云 (WanWanYun) - 一键部署脚本
|
||||||
# 项目地址: https://gitee.com/yu-yon/vue-driven-cloud-storage
|
# 项目地址: https://gitee.com/yu-yon/vue-driven-cloud-storage
|
||||||
# 版本: v1.0.1
|
# 版本: v1.1.0
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
@@ -73,10 +73,71 @@ detect_os() {
|
|||||||
. /etc/os-release
|
. /etc/os-release
|
||||||
OS=$ID
|
OS=$ID
|
||||||
OS_VERSION=$VERSION_ID
|
OS_VERSION=$VERSION_ID
|
||||||
|
OS_NAME=$NAME
|
||||||
else
|
else
|
||||||
print_error "无法检测操作系统"
|
print_error "无法检测操作系统"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 统一操作系统标识和包管理器检测
|
||||||
|
case $OS in
|
||||||
|
ubuntu)
|
||||||
|
PKG_MANAGER="apt"
|
||||||
|
;;
|
||||||
|
debian)
|
||||||
|
PKG_MANAGER="apt"
|
||||||
|
;;
|
||||||
|
centos)
|
||||||
|
if [[ "${OS_VERSION%%.*}" -ge 8 ]]; then
|
||||||
|
PKG_MANAGER="dnf"
|
||||||
|
else
|
||||||
|
PKG_MANAGER="yum"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
rhel|redhat)
|
||||||
|
OS="rhel"
|
||||||
|
if [[ "${OS_VERSION%%.*}" -ge 8 ]]; then
|
||||||
|
PKG_MANAGER="dnf"
|
||||||
|
else
|
||||||
|
PKG_MANAGER="yum"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
rocky|rockylinux)
|
||||||
|
OS="rocky"
|
||||||
|
PKG_MANAGER="dnf"
|
||||||
|
;;
|
||||||
|
almalinux|alma)
|
||||||
|
OS="almalinux"
|
||||||
|
PKG_MANAGER="dnf"
|
||||||
|
;;
|
||||||
|
fedora)
|
||||||
|
PKG_MANAGER="dnf"
|
||||||
|
;;
|
||||||
|
opensuse|opensuse-leap|opensuse-tumbleweed)
|
||||||
|
OS="opensuse"
|
||||||
|
PKG_MANAGER="zypper"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
# 自动检测包管理器作为后备方案
|
||||||
|
print_warning "未识别的操作系统: $OS,尝试自动检测包管理器"
|
||||||
|
if command -v apt-get &> /dev/null; then
|
||||||
|
PKG_MANAGER="apt"
|
||||||
|
print_info "检测到APT包管理器"
|
||||||
|
elif command -v dnf &> /dev/null; then
|
||||||
|
PKG_MANAGER="dnf"
|
||||||
|
print_info "检测到DNF包管理器"
|
||||||
|
elif command -v yum &> /dev/null; then
|
||||||
|
PKG_MANAGER="yum"
|
||||||
|
print_info "检测到YUM包管理器"
|
||||||
|
elif command -v zypper &> /dev/null; then
|
||||||
|
PKG_MANAGER="zypper"
|
||||||
|
print_info "检测到Zypper包管理器"
|
||||||
|
else
|
||||||
|
print_error "无法检测到支持的包管理器"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# 检测系统架构
|
# 检测系统架构
|
||||||
@@ -219,16 +280,91 @@ deb http://mirrors.aliyun.com/debian-security $(lsb_release -cs)-security main c
|
|||||||
EOF
|
EOF
|
||||||
print_success "阿里云源配置完成"
|
print_success "阿里云源配置完成"
|
||||||
;;
|
;;
|
||||||
centos|rhel)
|
centos)
|
||||||
# CentOS配置
|
# 备份并配置CentOS阿里云源
|
||||||
|
if [[ -f /etc/yum.repos.d/CentOS-Base.repo ]]; then
|
||||||
if [[ ! -f /etc/yum.repos.d/CentOS-Base.repo.bak ]]; then
|
if [[ ! -f /etc/yum.repos.d/CentOS-Base.repo.bak ]]; then
|
||||||
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
|
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
CENTOS_VERSION="${OS_VERSION%%.*}"
|
||||||
|
if [[ "$CENTOS_VERSION" == "7" ]]; then
|
||||||
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
|
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
|
||||||
|
elif [[ "$CENTOS_VERSION" == "8" ]]; then
|
||||||
|
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
|
||||||
|
sed -i 's/mirrors.cloud.aliyuncs.com/mirrors.aliyun.com/g' /etc/yum.repos.d/CentOS-Base.repo
|
||||||
|
fi
|
||||||
|
|
||||||
yum clean all
|
yum clean all
|
||||||
yum makecache
|
yum makecache
|
||||||
print_success "阿里云源配置完成"
|
print_success "阿里云源配置完成"
|
||||||
;;
|
;;
|
||||||
|
rhel)
|
||||||
|
# RHEL使用EPEL和阿里云镜像
|
||||||
|
print_info "配置RHEL阿里云镜像源..."
|
||||||
|
yum install -y epel-release
|
||||||
|
print_success "阿里云源配置完成"
|
||||||
|
;;
|
||||||
|
rocky)
|
||||||
|
# 备份并配置Rocky Linux阿里云源
|
||||||
|
if [[ -d /etc/yum.repos.d ]]; then
|
||||||
|
mkdir -p /etc/yum.repos.d/backup
|
||||||
|
cp /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/ 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
|
||||||
|
-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' \
|
||||||
|
-i.bak /etc/yum.repos.d/rocky*.repo
|
||||||
|
|
||||||
|
dnf clean all
|
||||||
|
dnf makecache
|
||||||
|
print_success "阿里云源配置完成"
|
||||||
|
;;
|
||||||
|
almalinux)
|
||||||
|
# 备份并配置AlmaLinux阿里云源
|
||||||
|
if [[ -d /etc/yum.repos.d ]]; then
|
||||||
|
mkdir -p /etc/yum.repos.d/backup
|
||||||
|
cp /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/ 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
|
||||||
|
-e 's|^# baseurl=https://repo.almalinux.org|baseurl=https://mirrors.aliyun.com|g' \
|
||||||
|
-i.bak /etc/yum.repos.d/almalinux*.repo
|
||||||
|
|
||||||
|
dnf clean all
|
||||||
|
dnf makecache
|
||||||
|
print_success "阿里云源配置完成"
|
||||||
|
;;
|
||||||
|
fedora)
|
||||||
|
# 备份并配置Fedora阿里云源
|
||||||
|
if [[ -d /etc/yum.repos.d ]]; then
|
||||||
|
mkdir -p /etc/yum.repos.d/backup
|
||||||
|
cp /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/ 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
sed -e 's|^metalink=|#metalink=|g' \
|
||||||
|
-e 's|^#baseurl=http://download.example/pub/fedora/linux|baseurl=https://mirrors.aliyun.com/fedora|g' \
|
||||||
|
-i.bak /etc/yum.repos.d/fedora*.repo /etc/yum.repos.d/fedora-updates*.repo
|
||||||
|
|
||||||
|
dnf clean all
|
||||||
|
dnf makecache
|
||||||
|
print_success "阿里云源配置完成"
|
||||||
|
;;
|
||||||
|
opensuse)
|
||||||
|
# 配置openSUSE阿里云源
|
||||||
|
print_info "配置openSUSE阿里云镜像源..."
|
||||||
|
zypper mr -da
|
||||||
|
zypper ar -fcg https://mirrors.aliyun.com/opensuse/distribution/leap/\$releasever/repo/oss/ aliyun-oss
|
||||||
|
zypper ar -fcg https://mirrors.aliyun.com/opensuse/distribution/leap/\$releasever/repo/non-oss/ aliyun-non-oss
|
||||||
|
zypper ar -fcg https://mirrors.aliyun.com/opensuse/update/leap/\$releasever/oss/ aliyun-update-oss
|
||||||
|
zypper ar -fcg https://mirrors.aliyun.com/opensuse/update/leap/\$releasever/non-oss/ aliyun-update-non-oss
|
||||||
|
zypper ref
|
||||||
|
print_success "阿里云源配置完成"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
print_warning "当前系统($OS)暂不支持阿里云镜像源自动配置,使用官方源"
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
################################################################################
|
################################################################################
|
||||||
@@ -238,18 +374,32 @@ EOF
|
|||||||
install_dependencies() {
|
install_dependencies() {
|
||||||
print_step "正在安装依赖环境..."
|
print_step "正在安装依赖环境..."
|
||||||
|
|
||||||
case $OS in
|
case $PKG_MANAGER in
|
||||||
ubuntu|debian)
|
apt)
|
||||||
apt-get update
|
apt-get update
|
||||||
apt-get install -y curl wget git unzip
|
apt-get install -y curl wget git unzip lsb-release
|
||||||
install_nodejs_apt
|
install_nodejs_apt
|
||||||
install_nginx_apt
|
install_nginx_apt
|
||||||
;;
|
;;
|
||||||
centos|rhel)
|
yum)
|
||||||
yum install -y curl wget git unzip
|
yum install -y curl wget git unzip redhat-lsb-core
|
||||||
install_nodejs_yum
|
install_nodejs_yum
|
||||||
install_nginx_yum
|
install_nginx_yum
|
||||||
;;
|
;;
|
||||||
|
dnf)
|
||||||
|
dnf install -y curl wget git unzip redhat-lsb-core
|
||||||
|
install_nodejs_dnf
|
||||||
|
install_nginx_dnf
|
||||||
|
;;
|
||||||
|
zypper)
|
||||||
|
zypper install -y curl wget git unzip lsb-release
|
||||||
|
install_nodejs_zypper
|
||||||
|
install_nginx_zypper
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
print_error "不支持的包管理器: $PKG_MANAGER"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
install_pm2
|
install_pm2
|
||||||
@@ -311,6 +461,60 @@ install_nginx_yum() {
|
|||||||
print_success "Nginx 安装完成"
|
print_success "Nginx 安装完成"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
install_nodejs_dnf() {
|
||||||
|
if command -v node &> /dev/null; then
|
||||||
|
NODE_VER=$(node -v | cut -d'v' -f2 | cut -d'.' -f1)
|
||||||
|
if [[ $NODE_VER -ge 18 ]]; then
|
||||||
|
print_success "Node.js 已安装: $(node -v)"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_info "正在安装 Node.js ${NODE_VERSION}.x..."
|
||||||
|
curl -fsSL https://rpm.nodesource.com/setup_${NODE_VERSION}.x | bash -
|
||||||
|
dnf install -y nodejs
|
||||||
|
print_success "Node.js 安装完成: $(node -v)"
|
||||||
|
}
|
||||||
|
|
||||||
|
install_nginx_dnf() {
|
||||||
|
if command -v nginx &> /dev/null; then
|
||||||
|
print_success "Nginx 已安装: $(nginx -v 2>&1 | cut -d'/' -f2)"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_info "正在安装 Nginx..."
|
||||||
|
dnf install -y nginx
|
||||||
|
systemctl enable nginx
|
||||||
|
print_success "Nginx 安装完成"
|
||||||
|
}
|
||||||
|
|
||||||
|
install_nodejs_zypper() {
|
||||||
|
if command -v node &> /dev/null; then
|
||||||
|
NODE_VER=$(node -v | cut -d'v' -f2 | cut -d'.' -f1)
|
||||||
|
if [[ $NODE_VER -ge 18 ]]; then
|
||||||
|
print_success "Node.js 已安装: $(node -v)"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_info "正在安装 Node.js ${NODE_VERSION}.x..."
|
||||||
|
# openSUSE使用官方仓库的Node.js
|
||||||
|
zypper install -y nodejs${NODE_VERSION}
|
||||||
|
print_success "Node.js 安装完成: $(node -v)"
|
||||||
|
}
|
||||||
|
|
||||||
|
install_nginx_zypper() {
|
||||||
|
if command -v nginx &> /dev/null; then
|
||||||
|
print_success "Nginx 已安装: $(nginx -v 2>&1 | cut -d'/' -f2)"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_info "正在安装 Nginx..."
|
||||||
|
zypper install -y nginx
|
||||||
|
systemctl enable nginx
|
||||||
|
print_success "Nginx 安装完成"
|
||||||
|
}
|
||||||
|
|
||||||
install_pm2() {
|
install_pm2() {
|
||||||
if command -v pm2 &> /dev/null; then
|
if command -v pm2 &> /dev/null; then
|
||||||
print_success "PM2 已安装: $(pm2 -v)"
|
print_success "PM2 已安装: $(pm2 -v)"
|
||||||
@@ -510,13 +714,19 @@ deploy_certbot() {
|
|||||||
print_step "使用 Certbot 部署SSL证书..."
|
print_step "使用 Certbot 部署SSL证书..."
|
||||||
|
|
||||||
# 安装certbot
|
# 安装certbot
|
||||||
case $OS in
|
case $PKG_MANAGER in
|
||||||
ubuntu|debian)
|
apt)
|
||||||
apt-get install -y certbot python3-certbot-nginx
|
apt-get install -y certbot python3-certbot-nginx
|
||||||
;;
|
;;
|
||||||
centos|rhel)
|
yum)
|
||||||
yum install -y certbot python3-certbot-nginx
|
yum install -y certbot python3-certbot-nginx
|
||||||
;;
|
;;
|
||||||
|
dnf)
|
||||||
|
dnf install -y certbot python3-certbot-nginx
|
||||||
|
;;
|
||||||
|
zypper)
|
||||||
|
zypper install -y certbot python3-certbot-nginx
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# 申请证书
|
# 申请证书
|
||||||
|
|||||||
Reference in New Issue
Block a user