Last active
March 25, 2021 23:02
-
-
Save halkyon/ce9f6f7f008a7bf4f785961aa766734f to your computer and use it in GitHub Desktop.
Build an OpenWRT target with some extra packages, either using the OpenWRT image builder, or compile from git
This file contains 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
#!/usr/bin/env bash | |
set -euo pipefail | |
target=${1:-} | |
subtarget=${2:-} | |
profile=${3:-} | |
release=${4:-snapshot} | |
target_path=$(readlink -f "${5:-$(pwd)}") | |
packages="luci luci-base luci-mod-admin-full luci-proto-relay luci-app-statistics" | |
# set this to 0 to build from git instead (NOTE: release parameter will need to be a git revision!) | |
builder=0 | |
if [[ -z "$target" || -z "$subtarget" || -z "$profile" ]]; then | |
echo "usage: $0 target subtarget profile [release] [target_path]" | |
echo "example: $0 mvebu cortexa9 linksys_wrt1900acs 18.06.4 /tmp/mybuild" | |
exit 1 | |
fi | |
cores=$(nproc --all) | |
threads=$((cores+1)) | |
scratch=$(mktemp -d -t tmp.XXXXXXXXXXXXX) | |
function finish { | |
rm -rf "$scratch" | |
} | |
trap finish EXIT | |
cd "$scratch" | |
echo "Building OpenWRT $release for ${target}-${subtarget}-${profile}" | |
echo "Detected $cores cores, using $threads threads for build" | |
if [[ "$builder" == 1 ]]; then | |
echo "Downloading OpenWRT image builder..." | |
builder_archive="openwrt-imagebuilder-${target}-${subtarget}.Linux-x86_64.tar.xz" | |
builder_url="https://downloads.openwrt.org/releases/${release}/targets/${target}/${subtarget}/${builder_archive}" | |
if [[ "$release" == "snapshot" || "$release" == "master" ]]; then | |
builder_url="https://downloads.openwrt.org/snapshots/targets/${target}/${subtarget}/${builder_archive}" | |
fi | |
wget --quiet "$builder_url" | |
tar xf "$builder_archive" | |
cd "$(basename "$builder_archive" .tar.xz)" | |
make -j"$threads" image \ | |
PROFILE="$profile" \ | |
PACKAGES="$packages" | |
else | |
echo "Downloading from git..." | |
git clone --quiet https://github.com/openwrt/openwrt.git "$scratch" | |
git checkout --quiet "$release" | |
./scripts/feeds update -a | |
./scripts/feeds install -a | |
cat << EOF > .config | |
CONFIG_TARGET_${target}=y | |
CONFIG_TARGET_${target}_${subtarget}_DEVICE_${profile}=y | |
EOF | |
for package in $packages; do | |
echo "CONFIG_PACKAGE_${package}=y" >> .config | |
done | |
make defconfig | |
make download | |
make -j"$threads" | |
fi | |
cp -r "bin/targets/${target}/${subtarget}/." "$target_path" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment