update prepare env script

This commit is contained in:
2026-05-31 03:16:12 +00:00
parent b672fc8f8d
commit 759a0da17c
2 changed files with 53 additions and 11 deletions

View File

@@ -5,7 +5,7 @@ This repository contains shell scripts that streamline preparing, configuring, a
## Whats included ## Whats included
- prepare-openwrt-env.sh - prepare-openwrt-env.sh
- Installs required build dependencies via apt on Ubuntu 22.04/24.04 and Debian 12/13+. - Installs required build dependencies via apt on Ubuntu 22.04/24.04/26.04 and Debian 12/13+.
- Handles x86_64 and ARM64 differences (Python/distutils, multilib notes, Go on ARM64). - Handles x86_64 and ARM64 differences (Python/distutils, multilib notes, Go on ARM64).
- prepare-openwrt.sh - prepare-openwrt.sh
- Clones or updates the OpenWrt source repo. - Clones or updates the OpenWrt source repo.
@@ -29,7 +29,7 @@ This repository contains shell scripts that streamline preparing, configuring, a
- Fixes MAX macro naming collisions in multiple DAHDI modules for OpenWrt 24.10.4 builds. - Fixes MAX macro naming collisions in multiple DAHDI modules for OpenWrt 24.10.4 builds.
## System requirements ## System requirements
- OS: Ubuntu 22.04/24.04 or Debian 12/13+ (others may work with adjustments) - OS: Ubuntu 22.04/24.04/26.04 or Debian 12/13+ (others may work with adjustments)
- Architectures: x86_64/amd64 and aarch64/arm64 - Architectures: x86_64/amd64 and aarch64/arm64
- Tools: git, wget, curl, bash - Tools: git, wget, curl, bash
- Internet access for feeds and package downloads - Internet access for feeds and package downloads

View File

@@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# Automatically prepare OpenWRT build dependencies for Debian/Ubuntu # Automatically prepare OpenWRT build dependencies for Debian/Ubuntu
# Supports both x86_64 and arm64 # Supports both x86_64 and arm64
# Detects Ubuntu 22.04, 24.04, Debian 12/13 and newer # Detects Ubuntu 22.04, 24.04, 26.04, Debian 12/13 and newer
# Author: Zhe Yuan # Author: Zhe Yuan
set -e set -e
@@ -27,21 +27,55 @@ fi
echo "[INFO] Detected distribution: $DISTRO $VERSION_ID" echo "[INFO] Detected distribution: $DISTRO $VERSION_ID"
# --- Determine if Python 3.12+ is installed (no distutils) --- # --- Version helpers ---
PY_VER=$(python3 -V 2>/dev/null | awk '{print $2}' | cut -d. -f1,2) version_ge() {
HAS_DISTUTILS=$(apt-cache search python3-distutils 2>/dev/null | grep -c distutils || true) local current="${1:-unknown}"
local minimum="$2"
if [[ "$current" == "unknown" ]]; then
return 1
fi
if command -v dpkg >/dev/null 2>&1; then
dpkg --compare-versions "$current" ge "$minimum"
else
[[ "$(printf '%s\n%s\n' "$minimum" "$current" | sort -V | head -n1)" == "$minimum" ]]
fi
}
IS_UBUNTU_24_OR_NEWER=false
IS_UBUNTU_26_OR_NEWER=false
IS_DEBIAN_13_OR_NEWER=false
if [[ "$DISTRO" == "ubuntu" ]] && version_ge "$VERSION_ID" "24.04"; then
IS_UBUNTU_24_OR_NEWER=true
fi
if [[ "$DISTRO" == "ubuntu" ]] && version_ge "$VERSION_ID" "26.04"; then
IS_UBUNTU_26_OR_NEWER=true
fi
if [[ "$DISTRO" == "debian" ]] && version_ge "$VERSION_ID" "13"; then
IS_DEBIAN_13_OR_NEWER=true
fi
# --- Base packages (common to all) --- # --- Base packages (common to all) ---
COMMON_PACKAGES="build-essential clang flex bison g++ gawk \ COMMON_PACKAGES="build-essential clang flex bison g++ gawk \
gettext git libssl-dev rsync swig unzip zlib1g-dev file wget" gettext git libssl-dev rsync swig unzip zlib1g-dev file wget bzip2"
# --- Determine specific package set --- # --- Determine specific package set ---
if [[ "$ARCH" == "x86_64" || "$ARCH" == "amd64" ]]; then if [[ "$ARCH" == "x86_64" || "$ARCH" == "amd64" ]]; then
echo "[INFO] Preparing environment for x86_64." echo "[INFO] Preparing environment for x86_64."
if [[ "$VERSION_ID" == "24.04" || ( "$DISTRO" == "debian" && "${VERSION_ID%%.*}" -ge 13 ) ]]; then if [[ "$IS_UBUNTU_26_OR_NEWER" == "true" ]]; then
echo "[INFO] Detected new environment (Python 3.12+, no python3-distutils)." echo "[INFO] Detected Ubuntu 26.04+ (no python3-distutils; OpenWrt docs use libncurses-dev)."
EXTRA_PACKAGES="gcc-multilib g++-multilib glibc-source libncurses-dev python3-setuptools"
elif [[ "$IS_UBUNTU_24_OR_NEWER" == "true" ]]; then
echo "[INFO] Detected Ubuntu 24.04+ (Python 3.12+, no python3-distutils)."
EXTRA_PACKAGES="gcc-multilib g++-multilib libncurses5-dev python3-setuptools" EXTRA_PACKAGES="gcc-multilib g++-multilib libncurses5-dev python3-setuptools"
elif [[ "$IS_DEBIAN_13_OR_NEWER" == "true" ]]; then
echo "[INFO] Detected Debian 13+ (no python3-distutils)."
EXTRA_PACKAGES="gcc-multilib g++-multilib libncurses-dev python3-setuptools"
else else
echo "[INFO] Detected older Ubuntu/Debian (with python3-distutils)." echo "[INFO] Detected older Ubuntu/Debian (with python3-distutils)."
EXTRA_PACKAGES="gcc-multilib g++-multilib libncurses-dev python3-distutils python3-setuptools" EXTRA_PACKAGES="gcc-multilib g++-multilib libncurses-dev python3-distutils python3-setuptools"
@@ -60,8 +94,12 @@ elif [[ "$ARCH" == "aarch64" || "$ARCH" == "arm64" ]]; then
g++-multilib-x86-64-linux-gnu g++-multilib-x86-64-linux-gnux32 \ g++-multilib-x86-64-linux-gnu g++-multilib-x86-64-linux-gnux32 \
libc6-dev-i386-amd64-cross libc6-dev-i386-cross libc6-dev-i386-x32-cross" libc6-dev-i386-amd64-cross libc6-dev-i386-cross libc6-dev-i386-x32-cross"
if [[ "$VERSION_ID" == "24.04" || ( "$DISTRO" == "debian" && "${VERSION_ID%%.*}" -ge 13 ) ]]; then if [[ "$IS_UBUNTU_26_OR_NEWER" == "true" ]]; then
EXTRA_PACKAGES="glibc-source libncurses-dev python3-setuptools"
elif [[ "$IS_UBUNTU_24_OR_NEWER" == "true" ]]; then
EXTRA_PACKAGES="libncurses5-dev python3-setuptools" EXTRA_PACKAGES="libncurses5-dev python3-setuptools"
elif [[ "$IS_DEBIAN_13_OR_NEWER" == "true" ]]; then
EXTRA_PACKAGES="libncurses-dev python3-setuptools"
else else
EXTRA_PACKAGES="libncurses-dev python3-distutils python3-setuptools" EXTRA_PACKAGES="libncurses-dev python3-distutils python3-setuptools"
fi fi
@@ -71,8 +109,12 @@ elif [[ "$ARCH" == "aarch64" || "$ARCH" == "arm64" ]]; then
else else
echo "[WARN] Unknown architecture: $ARCH" echo "[WARN] Unknown architecture: $ARCH"
echo "[WARN] Attempting to use x86_64 package list." echo "[WARN] Attempting to use x86_64 package list."
if [[ "$IS_UBUNTU_26_OR_NEWER" == "true" ]]; then
INSTALL_PACKAGES="$COMMON_PACKAGES gcc-multilib g++-multilib glibc-source libncurses-dev python3-setuptools"
else
INSTALL_PACKAGES="$COMMON_PACKAGES gcc-multilib g++-multilib libncurses-dev python3-setuptools" INSTALL_PACKAGES="$COMMON_PACKAGES gcc-multilib g++-multilib libncurses-dev python3-setuptools"
fi fi
fi
# --- Display package list --- # --- Display package list ---
echo echo