add scripts

This commit is contained in:
2025-11-08 10:28:02 -05:00
parent 718d82aabc
commit 299f39d3f2
7 changed files with 717 additions and 0 deletions

112
prepare-openwrt-env.sh Normal file
View File

@@ -0,0 +1,112 @@
#!/bin/bash
# Automatically prepare OpenWRT build dependencies for Debian/Ubuntu
# Supports both x86_64 and arm64
# Detects Ubuntu 22.04, 24.04, Debian 12/13 and newer
# Author: Zhe Yuan
set -e
umask 022
echo "========================================"
echo " OpenWRT Build Environment Preparation"
echo "========================================"
# --- Detect architecture ---
ARCH=$(uname -m)
echo "[INFO] Detected architecture: $ARCH"
# --- Detect OS version ---
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO="$ID"
VERSION_ID="${VERSION_ID:-unknown}"
else
echo "[ERROR] Cannot detect system version (no /etc/os-release)"
exit 1
fi
echo "[INFO] Detected distribution: $DISTRO $VERSION_ID"
# --- Determine if Python 3.12+ is installed (no distutils) ---
PY_VER=$(python3 -V 2>/dev/null | awk '{print $2}' | cut -d. -f1,2)
HAS_DISTUTILS=$(apt-cache search python3-distutils 2>/dev/null | grep -c distutils || true)
# --- Base packages (common to all) ---
COMMON_PACKAGES="build-essential clang flex bison g++ gawk \
gettext git libssl-dev rsync swig unzip zlib1g-dev file wget"
# --- Determine specific package set ---
if [[ "$ARCH" == "x86_64" || "$ARCH" == "amd64" ]]; then
echo "[INFO] Preparing environment for x86_64."
if [[ "$VERSION_ID" == "24.04" || ( "$DISTRO" == "debian" && "${VERSION_ID%%.*}" -ge 13 ) ]]; then
echo "[INFO] Detected new environment (Python 3.12+, no python3-distutils)."
EXTRA_PACKAGES="gcc-multilib g++-multilib libncurses5-dev python3-setuptools"
else
echo "[INFO] Detected older Ubuntu/Debian (with python3-distutils)."
EXTRA_PACKAGES="gcc-multilib g++-multilib libncurses-dev python3-distutils python3-setuptools"
fi
INSTALL_PACKAGES="$COMMON_PACKAGES $EXTRA_PACKAGES"
elif [[ "$ARCH" == "aarch64" || "$ARCH" == "arm64" ]]; then
echo "[INFO] Preparing environment for ARM64."
# Note: arm64 has no native multilib; install cross multilib packages
MULTILIB_PACKAGES="
gcc-multilib-i686-linux-gnu gcc-multilib-s390x-linux-gnu \
gcc-multilib-x86-64-linux-gnu gcc-multilib-x86-64-linux-gnux32 \
g++-multilib-i686-linux-gnu g++-multilib-s390x-linux-gnu \
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"
if [[ "$VERSION_ID" == "24.04" || ( "$DISTRO" == "debian" && "${VERSION_ID%%.*}" -ge 13 ) ]]; then
EXTRA_PACKAGES="libncurses5-dev python3-setuptools"
else
EXTRA_PACKAGES="libncurses-dev python3-distutils python3-setuptools"
fi
INSTALL_PACKAGES="$COMMON_PACKAGES $EXTRA_PACKAGES $MULTILIB_PACKAGES golang"
else
echo "[WARN] Unknown architecture: $ARCH"
echo "[WARN] Attempting to use x86_64 package list."
INSTALL_PACKAGES="$COMMON_PACKAGES gcc-multilib g++-multilib libncurses-dev python3-setuptools"
fi
# --- Display package list ---
echo
echo "========================================"
echo "📦 Packages to install:"
echo "$INSTALL_PACKAGES"
echo "========================================"
echo
echo "[INFO] Updating APT repositories..."
sudo apt update -y
echo "[INFO] Installing packages..."
sudo apt install -y $INSTALL_PACKAGES
# --- Post installation notice ---
echo
echo "========================================"
echo "✅ OpenWRT build environment setup complete!"
echo "========================================"
echo
if [[ "$ARCH" == "x86_64" || "$ARCH" == "amd64" ]]; then
echo "👉 [NOTE] Go language is optional on x86_64."
echo " If you plan to compile packages requiring Go (e.g. firewall4, netifd), install it manually:"
echo " sudo apt install golang -y"
else
echo "👉 [INFO] Go language installed for ARM64 cross compilation."
fi
echo
echo "⚙️ After running 'make menuconfig', set Go toolchain path if required:"
echo " Example: /usr/lib/go-1.18"
echo
echo "👉 Next step:"
echo " ./prepare-openwrt.sh # to clone and set up OpenWRT source"
echo