From dbaca9e915f275433d8237bd39bea2a433cd1922 Mon Sep 17 00:00:00 2001 From: Jens Reyer Date: Sun, 11 Feb 2024 00:59:23 +0100 Subject: [PATCH] winetricks_get_file_arch: try workaround for wrapper scripts --- src/winetricks | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/src/winetricks b/src/winetricks index 65f855de2..266bf52aa 100755 --- a/src/winetricks +++ b/src/winetricks @@ -1078,14 +1078,58 @@ winetricks_get_file_arch() *) w_die "Unknown file arch: ${_W_lipo_output}" ;; esac else - # Assume ELF binaries for everything else + # Assume ELF binaries for everything else (or try workaround for some specific scripts) _W_ob_output="$(od -An -t x1 -j 0x12 -N 1 "${_W_file}" | tr -d "[:space:]")" case "${_W_ob_output}" in "3e") _W_file_arch="x86_64" ;; "03"|"06") _W_file_arch="i386" ;; "b7") _W_file_arch="aarch64" ;; "28") _W_file_arch="aarch32" ;; - *) w_die "Unknown file arch: ${_W_ob_output}";; + *) # wineserver and wine might be wrapper scripts, their binaries might be in Wine's bindir. + # Since wineboot often is a link next to wineserver (whose path we already know) pointing to + # wineapploader in Wine's bindir, we can use this to figure out Wine's bindir. + WINEBOOT_BIN="$(echo "${WINESERVER_BIN}"|sed 's,wineserver,wineboot,')" + + if [ -n "${READLINK_F}" ]; then + true + elif [ "$(uname -s)" = "Darwin" ]; then + # readlink exists on MacOS, but does not support "-f" on MacOS < 12.3 + # Use perl instead + READLINK_F="perl -MCwd=abs_path -le 'print abs_path readlink(shift);'" + else + READLINK_F="readlink -f" + fi + + if [ "$1" = "${WINESERVER_BIN}" ]; then + # wineserver in PATH might be a script calling a binary in Wine's bindir. + if [ -x "${WINEBOOT_BIN}" ]; then + WINE_BINDIR="$(dirname "$(${READLINK_F} "${WINEBOOT_BIN}" 2>/dev/null)" 2>/dev/null)" + # wineserver in Wine's bindir might be a script calling wineserver64 preferably over wineserver32 (Debian). + # Try these before testing wineserver itself + if [ -x "${WINE_BINDIR}/wineserver64" ]; then + _W_ob_output="$(od -An -t x1 -j 0x12 -N 1 "${WINE_BINDIR}/wineserver64" | tr -d "[:space:]")" + elif [ -x "${WINE_BINDIR}/wineserver32" ]; then + _W_ob_output="$(od -An -t x1 -j 0x12 -N 1 "${WINE_BINDIR}/wineserver32" | tr -d "[:space:]")" + elif [ -x "${WINE_BINDIR}/wineserver" ]; then + _W_ob_output="$(od -An -t x1 -j 0x12 -N 1 "${WINE_BINDIR}/wineserver" | tr -d "[:space:]")" + fi + fi + elif [ "$1" = "${WINE_BIN}" ]; then + # wine in PATH might be a script calling a binary in Wine's bindir. + if [ -x "${WINEBOOT_BIN}" ]; then + WINE_BINDIR="$(dirname "$(${READLINK_F} "${WINEBOOT_BIN}" 2>/dev/null)" 2>/dev/null)" + if [ -x "${WINE_BINDIR}/wine" ]; then + _W_ob_output="$(od -An -t x1 -j 0x12 -N 1 "${WINE_BINDIR}/wine" | tr -d "[:space:]")" + fi + fi + fi + case "${_W_ob_output}" in + "3e") _W_file_arch="x86_64" ;; + "03"|"06") _W_file_arch="i386" ;; + "b7") _W_file_arch="aarch64" ;; + "28") _W_file_arch="aarch32" ;; + *) w_die "Unknown file arch: ${_W_ob_output}" ;; + esac esac fi