Wine
sh#!/bin/bashclear
# 显示欢迎信息
echo " \\ /"
echo " \\~~/ GenGen Wine 自动安装脚本"
echo " \\/ 10.0"
echo " | "
echo " __|__ "
echo
# 自动重试函数
retry() {
local max_attempts=5
local delay=3
local attempt=1
while [ $attempt -le $max_attempts ]; do
if "$@"; then
return 0
else
echo "⚠️ 命令失败(尝试 $attempt/$max_attempts):$*"
if [ $attempt -eq $max_attempts ]; then
echo "❌ 最终失败,退出。"
exit 1
fi
sleep $delay
((attempt++))
fi
done
}
# 设置非交互模式 & 简化输出
export DEBIAN_FRONTEND=noninteractive
APT_OPTS="-q -y"
# 1. 更新并安装基础依赖
retry sudo apt $APT_OPTS update
retry sudo apt $APT_OPTS install dirmngr ca-certificates software-properties-common apt-transport-https curl
# 2. 安装 apt-fast(若未安装)
if ! command -v apt-fast &> /dev/null; then
echo "📦 正在安装 apt-fast..."
# 预设 debconf 配置:选择 apt-get 作为后端,避免交互
echo "apt-fast apt-fast/maxdownloads string 5" | sudo debconf-set-selections
echo "apt-fast apt-fast/dlflag boolean true" | sudo debconf-set-selections
echo "apt-fast apt-fast/aptmanager string apt" | sudo debconf-set-selections
retry sudo add-apt-repository ppa:apt-fast/stable -y
sudo apt $APT_OPTS update
retry sudo apt $APT_OPTS install apt-fast
fi
# 3. 启用 i386 架构
retry sudo dpkg --add-architecture i386
# 4. 下载 WineHQ GPG 密钥
sudo wget -nc -O /usr/share/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key
# 5. 获取当前 Ubuntu 代号
CODENAME=$(lsb_release -sc)
if [ -z "$CODENAME" ]; then
echo "❌ 无法获取系统代号,请确保已安装 lsb-release"
retry sudo apt $APT_OPTS install lsb-release
CODENAME=$(lsb_release -sc)
fi
# 6. 添加清华大学 Wine 镜像源
echo "deb [arch=amd64,i386 signed-by=/usr/share/keyrings/winehq-archive.key] https://mirrors.tuna.tsinghua.edu.cn/wine-builds/ubuntu/ $CODENAME main" | sudo tee /etc/apt/sources.list.d/winehq.list >/dev/null
# 7. 更新 APT 缓存
retry sudo apt $APT_OPTS update
# 8. 安装 Wine Stable(使用 apt-fast)
retry sudo apt-fast $APT_OPTS --install-recommends install winehq-stable
# 9. 安装 GNOME 扩展(可选)
retry sudo apt-fast $APT_OPTS install gnome-shell-extension-top-icons-plus
# 10. 显示版本
wine --version
sleep 1
clear
echo "✅ 安装完成!"