Last active
December 11, 2023 21:39
-
-
Save xoascf/f7268dafdac6678a3d1d644e416f0ef4 to your computer and use it in GitHub Desktop.
Automatic Wine installer for Debian-based distros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Automatic Wine installer for Debian-based distros - Amaro M. | |
Fmt='printf' | |
DVER="winehq-stable" | |
VER=${1:-$DVER} | |
SF="%s\n" | |
NEED_ROOT='This script must be run as root.' | |
NOT_VALID_BRANCH='“%s” is not a valid branch name.\n' | |
NOT_DEBIAN_BASED='Not a Debian-based distro.' | |
DEBIAN_UNSUPPORTED='Unsupported Debian-based distro.' | |
WINE_REPO_NOT_FOUND='Wine repository “%s” not found.\n' | |
APT_UPDATE_BAD='Fix the apt update issues first, then try again.' | |
WINE_VER_NOT_FOUND='“%s” was not found in the repositories, so it could not be installed.\n' | |
NO_WINE_FOUND='No official Wine package has been found in the repositories.' | |
AVAILABLE_PACKAGES='The following packages are available:' | |
TRY_THESE_PACKAGES='Try again with any of these packages.' | |
SCRIPT_FAILED="An error caused Wine to not be fully installed." | |
SCRIPT_SUCCESS="Wine was successfully installed." | |
case "${LANGUAGE:-$LANG}" in | |
es*) | |
NEED_ROOT='Este script debe ser ejecutado como root.' | |
NOT_VALID_BRANCH='«%s» no es un nombre de rama válido.\n' | |
NOT_DEBIAN_BASED='No es una distro basada en Debian.' | |
DEBIAN_UNSUPPORTED='Distro basada en Debian no soportada.' | |
WINE_REPO_NOT_FOUND='No se ha encontrado el repositorio de Wine «%s».\n' | |
APT_UPDATE_BAD='Corrija primero los problemas de apt update y vuelva a intentarlo.' | |
WINE_VER_NOT_FOUND='«%s» no se encontró en los repositorios, por lo que no se pudo instalar.\n' | |
NO_WINE_FOUND='No se ha encontrado ningun paquete oficial de Wine en los repositorios.' | |
AVAILABLE_PACKAGES='Están disponibles los siguientes paquetes:' | |
TRY_THESE_PACKAGES='Inténtelo de nuevo con cualquiera de estos paquetes.' | |
SCRIPT_FAILED='Un error hizo que Wine no se instalara completamente.' | |
SCRIPT_SUCCESS='Wine se ha instalado con éxito.' | |
;; | |
esac | |
# Error. | |
E() { | |
S=${2:-$SF} | |
$Fmt >&2 "$S" "$1" | |
} | |
# Fatal Error, must quit. | |
Q() { | |
E "$@" | |
exit 1 | |
} | |
[ "$(id -u)" -ne 0 ] && Q "$NEED_ROOT" | |
case "${VER}" in | |
"$DVER" | winehq-devel | winehq-staging) : ;; | |
*) Q "$VER" "$NOT_VALID_BRANCH" ;; | |
esac | |
! [ -f /etc/debian_version ] && Q "$NOT_DEBIAN_BASED" | |
case $(cat /etc/debian_version) in | |
*"buster"* | 10*) distro="buster" ;; | |
*"bullseye"* | 11*) distro="bullseye" ;; | |
*"bookworm"* | 12*) distro="bookworm" ;; | |
*"trixie"* | 13*) distro="trixie" ;; | |
*) Q "$DEBIAN_UNSUPPORTED" ;; | |
esac | |
wine_b="https://dl.winehq.org/wine-builds" | |
wine_b_url="$wine_b/debian/" | |
# Replace url and distro for Ubuntu-based distro. | |
case $(cat /etc/os-release) in | |
*"UBUNTU_CODENAME"*) | |
wine_b_url=$wine_b/ubuntu/ | |
. /etc/os-release | |
distro=$UBUNTU_CODENAME | |
;; | |
esac | |
# Validate repo. | |
wine_b_dists="$wine_b_url/dists/$distro/" | |
! wget --spider "$wine_b_dists" 2>/dev/null && Q "$wine_b_dists" "$WINE_REPO_NOT_FOUND" | |
sources_dir=/etc/apt/sources.list.d | |
apt -y update || Q "$APT_UPDATE_BAD" | |
dpkg --add-architecture i386 | |
KEYSDIR="/usr/share/keyrings" | |
KEYFILE="$KEYSDIR/winehq-archive-keyring.gpg" | |
mkdir -p "$KEYSDIR" | |
wget -qO - $wine_b/winehq.key | gpg --dearmor >"$KEYFILE" | |
echo "deb [signed-by=$KEYFILE] $wine_b_url $distro main " >$sources_dir/winehq.list | |
[ "$distro" = "buster" ] && echo "deb http://deb.debian.org/debian buster-backports main " >$sources_dir/buster-backports.list | |
apt -y update || Q "$APT_UPDATE_BAD" | |
if ! apt-cache show "$VER" >/dev/null 2>&1; then | |
E "$VER" "$WINE_VER_NOT_FOUND" | |
FOUNDREL="$(apt search -qq --names-only 'winehq-*' 2>/dev/null)" | |
if [ -z "$FOUNDREL" ]; then | |
Q "$NO_WINE_FOUND" | |
else | |
E "$AVAILABLE_PACKAGES" | |
E "$FOUNDREL" | |
E | |
Q "$TRY_THESE_PACKAGES" | |
fi | |
fi | |
apt -y install --install-recommends "$VER" || Q "$SCRIPT_FAILED" && $Fmt "$SF" "$SCRIPT_SUCCESS" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Probably I should use "DEBIAN_FRONTEND=noninteractive".