Created
August 21, 2025 10:41
-
-
Save 0x61nas/30e524190ad6e3a5680825b6e37611ef to your computer and use it in GitHub Desktop.
This file contains hidden or 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/bash | |
| # Interactive script to install and customize Wine on Arch Linux | |
| # Based on ArchWiki: https://wiki.archlinux.org/title/Wine | |
| # Run as root or with sudo. Use at your own risk. | |
| set -euo pipefail | |
| # Variables | |
| LOG_FILE="$HOME/wine_install_$(date +%Y%m%d_%H%M%S).log" | |
| WINE_VARIANT="wine-staging" | |
| PREFIX_DIR="$HOME/.wine" | |
| DPI=144 | |
| SUDO=doas | |
| detect_prlevlege_tool() { | |
| if command -v sudo &> /dev/null; then | |
| SUDO=sudo | |
| elif command -v doas &> /dev/null; then | |
| SUDO=doas | |
| else | |
| SUDO='su -c' | |
| fi | |
| } | |
| # Detect package manager | |
| detect_pkg_manager() { | |
| if command -v paru &> /dev/null; then | |
| PKG_MANAGER="paru" | |
| log "Found AUR helper: paru" | |
| elif command -v yay &> /dev/null; then | |
| PKG_MANAGER="yay" | |
| log "Found AUR helper: yay" | |
| else | |
| PKG_MANAGER="pacman" | |
| log "No AUR helper found, using pacman" | |
| fi | |
| } | |
| # Logging function | |
| log() { | |
| echo "[$(date +%Y-%m-%d\ %H:%M:%S)] $1" | tee -a "$LOG_FILE" | |
| } | |
| # Function to install packages | |
| install_pkgs() { | |
| log "Installing packages: $@" | |
| case $PKG_MANAGER in | |
| "paru"|"yay") | |
| # AUR helpers - run as regular user, no sudo needed | |
| $PKG_MANAGER --sudo "$SUDO" -S --needed "$@" | |
| ;; | |
| "pacman") | |
| "$SUDO" pacman -S --needed "$@" | |
| ;; | |
| esac | |
| } | |
| # Start logging | |
| log "Starting Wine installation and customization" | |
| detect_prlevlege_tool | |
| # Detect package manager | |
| detect_pkg_manager | |
| log "Package manager: $PKG_MANAGER" | |
| read -r -p "Update Your System? [Y/n] " ans; ans=${ans,,}; ans=${ans:-y}; [[ $ans == y* ]] && \ | |
| install_pkgs -yyu | |
| # Prompt for Wine variant | |
| echo "Choose Wine variant to install:" | |
| echo "1) wine (development)" | |
| echo "2) wine-staging (testing)" | |
| echo "3) wine-stable (AUR, stable)" | |
| read -p "Enter choice (1-3): " wine_choice | |
| case $wine_choice in | |
| 1) WINE_VARIANT="wine"; log "Selected wine (development)" ;; | |
| 2) WINE_VARIANT="wine-staging"; log "Selected wine-staging (testing)" ;; | |
| 3) WINE_VARIANT="wine-stable"; log "Selected wine-stable (AUR)" ;; | |
| *) log "Invalid choice, defaulting to wine-staging"; WINE_VARIANT="wine-staging" ;; | |
| esac | |
| # Check if wine-stable is selected but no AUR helper is available | |
| if [ "$WINE_VARIANT" = "wine-stable" ] && [ "$PKG_MANAGER" = "pacman" ]; then | |
| echo "Warning: wine-stable requires an AUR helper but none was found." | |
| echo "Please install paru or yay first, or choose a different Wine variant." | |
| read -p "Do you want to install wine-staging instead? (y/n): " fallback_choice | |
| if [ "$fallback_choice" = "y" ]; then | |
| WINE_VARIANT="wine-staging" | |
| log "Falling back to wine-staging due to missing AUR helper" | |
| else | |
| log "Exiting: wine-stable selected but no AUR helper available" | |
| exit 1 | |
| fi | |
| fi | |
| # Prompt for Wine prefix | |
| read -p "Enter Wine prefix path (default: $HOME/.wine): " PREFIX_DIR | |
| PREFIX_DIR=${PREFIX_DIR:-$HOME/.wine} | |
| log "Wine prefix set to: $PREFIX_DIR" | |
| # Prompt for DPI setting | |
| read -p "Enter DPI for high-res displays (default: 144, press Enter to skip): " DPI | |
| DPI=${DPI:-144} | |
| log "DPI set to: $DPI" | |
| # Detect GPU and prompt for driver confirmation | |
| GPU=$(lspci | grep -E 'VGA|3D') | |
| if echo "$GPU" | grep -qi "nvidia"; then | |
| GPU_DRIVER="lib32-nvidia-utils" | |
| GPU_TYPE="NVIDIA" | |
| elif echo "$GPU" | grep -qi "amd"; then | |
| GPU_DRIVER="lib32-mesa" | |
| GPU_TYPE="AMD" | |
| elif echo "$GPU" | grep -qi "intel"; then | |
| GPU_DRIVER="lib32-mesa" | |
| GPU_TYPE="Intel" | |
| else | |
| GPU_DRIVER="" | |
| GPU_TYPE="Unknown" | |
| fi | |
| if [ -n "$GPU_DRIVER" ]; then | |
| read -p "Detected $GPU_TYPE GPU. Install $GPU_DRIVER? (y/n): " install_driver | |
| log "Detected $GPU_TYPE GPU, install $GPU_DRIVER: $install_driver" | |
| else | |
| log "Unknown GPU detected. Skipping graphics driver." | |
| install_driver="n" | |
| fi | |
| # Install Wine and essentials | |
| log "Installing Wine and essential packages" | |
| install_pkgs "$WINE_VARIANT" wine-gecko wine-mono winetricks zenity lib32-libcups lib32-gnutls lib32-libxrandr lib32-libxinerama | |
| # Install GPU driver if selected | |
| [ "$install_driver" = "y" ] && install_pkgs "$GPU_DRIVER" | |
| # Install sound (ALSA and Pulse) | |
| log "Installing sound packages" | |
| install_pkgs lib32-alsa-lib lib32-alsa-plugins lib32-libpulse lib32-openal | |
| # Other common dependencies | |
| log "Installing additional dependencies" | |
| install_pkgs giflib lib32-giflib libpng lib32-libpng libldap lib32-libldap gnutls lib32-gnutls mpg123 lib32-mpg123 openal lib32-openal v4l-utils lib32-v4l-utils libpulse lib32-libpulse libjpeg-turbo lib32-libjpeg-turbo gst-plugins-base-libs lib32-gst-plugins-base-libs vulkan-icd-loader lib32-vulkan-icd-loader | |
| # Create prefix if not exists | |
| if [ ! -d "$PREFIX_DIR" ]; then | |
| log "Creating Wine prefix at $PREFIX_DIR" | |
| env WINEPREFIX="$PREFIX_DIR" wineboot -u 2>&1 | tee -a "$LOG_FILE" | |
| fi | |
| # Link system fonts to Wine | |
| log "Linking system fonts to Wine prefix" | |
| cd "$PREFIX_DIR/drive_c/windows/Fonts" | |
| for font in /usr/share/fonts/**/*.{ttf,otf}; do | |
| ln -sf "$font" 2>> "$LOG_FILE" | |
| done | |
| # Enable font smoothing (ClearType RGB) | |
| log "Enabling font smoothing (ClearType RGB)" | |
| env WINEPREFIX="$PREFIX_DIR" winetricks fontsmooth=rgb 2>&1 | tee -a "$LOG_FILE" | |
| # Adjust DPI | |
| log "Setting DPI to $DPI" | |
| env WINEPREFIX="$PREFIX_DIR" wine reg add 'HKEY_CURRENT_USER\Control Panel\Desktop' /v LogPixels /t REG_DWORD /d "$DPI" /f 2>&1 | tee -a "$LOG_FILE" | |
| # Prompt for disabling file associations | |
| read -p "Disable Wine file associations? (y/n): " disable_assoc | |
| log "Disable Wine file associations: $disable_assoc" | |
| if [ "$disable_assoc" = "y" ]; then | |
| env WINEPREFIX="$PREFIX_DIR" wine reg add 'HKEY_CURRENT_USER\Software\Wine\FileOpenAssociations' /v Enable /t REG_SZ /d N /f 2>&1 | tee -a "$LOG_FILE" | |
| log "Removing Wine file associations" | |
| rm -f ~/.local/share/applications/wine-extension*.desktop 2>> "$LOG_FILE" | |
| rm -f ~/.local/share/icons/hicolor/*/*/application-x-wine-extension* 2>> "$LOG_FILE" | |
| rm -f ~/.local/share/mime/packages/x-wine* 2>> "$LOG_FILE" | |
| rm -f ~/.local/share/mime/application/x-wine-extension* 2>> "$LOG_FILE" | |
| update-desktop-database ~/.local/share/applications 2>&1 | tee -a "$LOG_FILE" | |
| update-mime-database ~/.local/share/mime 2>&1 | tee -a "$LOG_FILE" | |
| fi | |
| # Prevent Mono/Gecko prompts | |
| export WINEDLLOVERRIDES="mscoree=d;mshtml=d" | |
| log "Disabled Mono/Gecko prompts" | |
| # Enable CSMT | |
| log "Enabling CSMT" | |
| env WINEPREFIX="$PREFIX_DIR" wine reg add 'HKEY_CURRENT_USER\Software\Wine\Direct3D' /v csmt /t REG_DWORD /d 1 /f 2>&1 | tee -a "$LOG_FILE" | |
| # Setup for printing | |
| log "Setting up printing" | |
| env WINEPREFIX="$PREFIX_DIR" wineboot 2>&1 | tee -a "$LOG_FILE" | |
| # Prompt for creating Wine menu entries | |
| read -p "Create desktop menu entries for Wine utilities? (y/n): " create_menus | |
| log "Create desktop menu entries: $create_menus" | |
| if [ "$create_menus" = "y" ]; then | |
| log "Creating desktop menu entries" | |
| mkdir -p ~/.local/share/applications/wine | |
| cat > ~/.local/share/applications/wine/wine-browsedrive.desktop << EOF | |
| [Desktop Entry] | |
| Name=Browse C: Drive | |
| Exec=env WINEPREFIX="$PREFIX_DIR" wine winebrowser c: | |
| Type=Application | |
| Icon=folder-wine | |
| Categories=Wine; | |
| EOF | |
| cat > ~/.local/share/applications/wine/wine-uninstaller.desktop << EOF | |
| [Desktop Entry] | |
| Name=Uninstall Wine Software | |
| Exec=env WINEPREFIX="$PREFIX_DIR" wine uninstaller | |
| Type=Application | |
| Icon=wine-uninstaller | |
| Categories=Wine; | |
| EOF | |
| cat > ~/.local/share/applications/wine/wine-winecfg.desktop << EOF | |
| [Desktop Entry] | |
| Name=Configure Wine | |
| Exec=env WINEPREFIX="$PREFIX_DIR" winecfg | |
| Type=Application | |
| Icon=wine-winecfg | |
| Categories=Wine; | |
| EOF | |
| update-desktop-database ~/.local/share/applications 2>&1 | tee -a "$LOG_FILE" | |
| fi | |
| log "Wine installation and customization complete" | |
| echo "Wine installed and customized. Logs saved to $LOG_FILE. Run 'WINEPREFIX=$PREFIX_DIR winecfg' to configure further." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment