From 6153a7fe076ad3ff0cb1794ea3b9062c61358936 Mon Sep 17 00:00:00 2001 From: Ahmed Abdelhalim Date: Wed, 27 May 2026 12:57:47 +0200 Subject: Update the ubuntu hack scripts to download the mac drivers Co-assisted-by: Claude AI --- hacks/ubuntu/install-wl.sh | 16 +++------- hacks/ubuntu/mac-drivers.sh | 77 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 63 insertions(+), 30 deletions(-) diff --git a/hacks/ubuntu/install-wl.sh b/hacks/ubuntu/install-wl.sh index 04e1768..cf023e1 100755 --- a/hacks/ubuntu/install-wl.sh +++ b/hacks/ubuntu/install-wl.sh @@ -5,17 +5,9 @@ set -euo pipefail # Must be run with access to the debs downloaded by mac-drivers.sh. # gcc/make/binutils are extracted from the downloaded debs — not assumed pre-installed. # -# Usage: bash install-wl.sh +# Usage: bash install-wl.sh -usage() { - echo "Usage: $0 " - echo " debs-dir: directory containing broadcom-sta-dkms and linux-headers debs" - exit 1 -} - -[[ $# -ne 1 ]] && usage - -DEBS_DIR="$1" +DEBS_DIR="$(dirname "$0")" KERNEL_VERSION="$(uname -r)" if [[ ! -d "$DEBS_DIR" ]]; then @@ -49,7 +41,9 @@ sudo KBUILD_NOPEDANTIC=1 make \ echo "Unloading conflicting modules..." sudo rmmod wl 2>/dev/null || true -sudo rmmod b43 ssb bcma brcmfmac brcmutil 2>/dev/null || true +for mod in b43 ssb bcma brcmfmac brcmutil; do + sudo rmmod "$mod" 2>/dev/null || true +done echo "Loading wl.ko..." sudo insmod "$SRC_DIR/wl.ko" diff --git a/hacks/ubuntu/mac-drivers.sh b/hacks/ubuntu/mac-drivers.sh index 248e9c0..43f8282 100755 --- a/hacks/ubuntu/mac-drivers.sh +++ b/hacks/ubuntu/mac-drivers.sh @@ -2,18 +2,19 @@ set -euo pipefail usage() { - echo "Usage: $0 " + echo "Usage: $0 " echo " kernel-version: output of 'uname -r' on target machine" - echo " Example: $0 6.11.0-17-generic" + echo " Example: $0 noble 6.11.0-17-generic" + echo " Example: $0 resolute 7.0.0-15-generic" exit 1 } -[[ $# -ne 1 ]] && usage +[[ $# -ne 2 ]] && usage -KERNEL_VERSION="$1" -OUTPUT_DIR="/tmp/bcmwl-drivers" +DISTRO="$1" +KERNEL_VERSION="$2" +OUTPUT_DIR="/tmp/bcmwl-drivers-${KERNEL_VERSION}" BASE_URL="http://archive.ubuntu.com/ubuntu" -DISTRO="noble" INDEX_DIR=$(mktemp -d) cleanup() { rm -rf "$INDEX_DIR"; } @@ -22,8 +23,11 @@ fetch_index() { local pocket="$1" component="$2" local dest="${INDEX_DIR}/${pocket}-${component}.txt" echo "Fetching ${pocket}/${component} index..." >&2 - curl -fsSL "${BASE_URL}/dists/${pocket}/${component}/binary-amd64/Packages.gz" \ - | gzip -d > "$dest" + if ! curl -fsSL "${BASE_URL}/dists/${pocket}/${component}/binary-amd64/Packages.gz" \ + | gzip -d > "$dest"; then + echo "ERROR: failed to fetch ${BASE_URL}/dists/${pocket}/${component} (HTTP 404? wrong distro name?)" >&2 + exit 1 + fi echo "$dest" } @@ -57,40 +61,75 @@ download_pkg() { curl -fL -o "${OUTPUT_DIR}/${deb}" "${BASE_URL}/${filename}" } +require_pkg() { + local pkg_name="$1" + local filename="" + for index in "${INDEXES[@]}"; do + filename=$(pkg_filename "$index" "$pkg_name") + [[ -n "$filename" ]] && break + done + if [[ -z "$filename" ]]; then + echo "ERROR: required package $pkg_name not found in any index" >&2 + exit 1 + fi + local deb + deb=$(basename "$filename") + if [[ -f "${OUTPUT_DIR}/${deb}" ]]; then + echo " (cached) $deb" + return 0 + fi + echo "Downloading $deb..." + curl -fL -o "${OUTPUT_DIR}/${deb}" "${BASE_URL}/${filename}" +} + # Create out directory and configure trap signal mkdir -p "$OUTPUT_DIR" trap cleanup EXIT # Fetch indexes main_index=$(fetch_index "$DISTRO" "main") +restricted_index=$(fetch_index "$DISTRO" "restricted") main_updates=$(fetch_index "${DISTRO}-updates" "main") restricted_updates=$(fetch_index "${DISTRO}-updates" "restricted") -INDEXES=("$main_updates" "$main_index" "$restricted_updates") +INDEXES=("$main_updates" "$restricted_updates" "$main_index" "$restricted_index") + +# Auto-discover gcc version from distro's gcc metapackage +GCC_VER=$(pkg_field "$main_index" "gcc" "Depends" \ + | grep -o 'gcc-[0-9]*' | head -1 | cut -d- -f2 || true) +if [[ -z "$GCC_VER" ]]; then + echo "ERROR: cannot determine gcc version from index" >&2 + exit 1 +fi +echo "Detected gcc version: $GCC_VER" # Kernel headers -download_pkg "linux-headers-${KERNEL_VERSION}" +require_pkg "linux-headers-${KERNEL_VERSION}" -# Auto-discover base headers from Depends: field -BASE_HEADERS_PKG=$(pkg_field "$main_updates" "linux-headers-${KERNEL_VERSION}" "Depends" \ - | grep -o 'linux-hwe-[^ ,)]*' | head -1) +# Auto-discover base headers from Depends: field (search all indexes) +BASE_HEADERS_PKG="" +for index in "${INDEXES[@]}"; do + BASE_HEADERS_PKG=$(pkg_field "$index" "linux-headers-${KERNEL_VERSION}" "Depends" \ + | grep -o 'linux-headers-[0-9][^ ,)]*\|linux-hwe-[^ ,)]*' | head -1 || true) + [[ -n "$BASE_HEADERS_PKG" ]] && break +done if [[ -n "$BASE_HEADERS_PKG" ]]; then echo "Base headers: $BASE_HEADERS_PKG" download_pkg "$BASE_HEADERS_PKG" fi # Broadcom source -download_pkg "broadcom-sta-dkms" +require_pkg "broadcom-sta-dkms" # Build tools (not pre-installed on Ubuntu live ISO) echo "Downloading build tools..." for pkg in \ make \ - gcc-13-base \ - cpp-13-x86-64-linux-gnu cpp-13 cpp-x86-64-linux-gnu cpp \ - gcc-13-x86-64-linux-gnu gcc-13 gcc-x86-64-linux-gnu gcc \ + gcc-${GCC_VER}-base \ + cpp-${GCC_VER}-x86-64-linux-gnu cpp-${GCC_VER} cpp-x86-64-linux-gnu cpp \ + gcc-${GCC_VER}-x86-64-linux-gnu gcc-${GCC_VER} gcc-x86-64-linux-gnu gcc \ binutils-common libsframe1 libbinutils libctf-nobfd0 libctf0 \ libjansson4 libgprofng0 binutils-x86-64-linux-gnu binutils \ - libcc1-0 libisl23 libmpfr6 libmpc3 libgcc-13-dev lto-disabled-list; do + libcc1-0 libisl23 libmpfr6 libmpc3 libgcc-${GCC_VER}-dev lto-disabled-list; do download_pkg "$pkg" done @@ -98,4 +137,4 @@ done cp "$(dirname "$0")/install-wl.sh" "$OUTPUT_DIR/" chmod +x "$OUTPUT_DIR/install-wl.sh" echo "" -echo "Downloaded to $OUTPUT_DIR:" +echo "Downloaded to $OUTPUT_DIR" -- cgit v1.2.3