Compare commits

...

17 Commits

Author SHA1 Message Date
b5199d5682 Remove index update 2025-07-28 00:29:33 -04:00
35ec2993cc Remove worktree dir before add 2025-07-27 22:53:32 -04:00
e4838f361e Cleanup dependency arrays 2025-07-27 22:46:40 -04:00
f32b8c84b0 Update dependencies 2025-07-27 22:39:31 -04:00
f34953b3cc Fix for missing worktree metadata 2025-07-27 22:22:55 -04:00
e91394ee00 Add --depends to README 2025-07-27 21:29:26 -04:00
a40ac543e9 Use default CFLAGS 2025-07-27 00:05:03 -04:00
06a3209046 Use CFLAGS in make 2025-07-26 21:39:58 -04:00
5ef6d2dc0f Use CFLAGS var 2025-07-26 19:39:53 -04:00
36c0786255 Use -std=c17 for gcc15 2025-07-26 00:43:03 -04:00
25e66b3d19 Update openwrt default to 24.10.2 2025-07-25 19:25:30 -04:00
aa24a58aae Roll verbose into debug 2025-04-22 20:13:12 -04:00
7298fca349 User serial compilation for --debug 2025-04-22 16:58:06 -04:00
7191e10f91 Use n-1 cores 2025-04-22 16:55:43 -04:00
e80dddf9a7 Update default release 2025-04-21 16:48:51 -04:00
481e2e2277 Update print_help() 2025-02-22 17:21:03 -05:00
de84a404f0 Update default release 2025-02-22 17:06:32 -05:00
3 changed files with 79 additions and 74 deletions

View File

@@ -1,6 +1,6 @@
# openwrtbuilder # openwrtbuilder
Sanely build and deploy OpenWRT images using the Image Builder or from source code. Build and deploy OpenWRT images using convenient profiles.
## Usage ## Usage
@@ -15,6 +15,7 @@ Sanely build and deploy OpenWRT images using the Image Builder or from source co
--source --source
Build image from source, not from Image Builder Build image from source, not from Image Builder
Allows make config options to be passed in profile Allows make config options to be passed in profile
Uses git worktree for multi-profile deduplication
--ssh-upgrade HOST --ssh-upgrade HOST
Example: root@192.168.1.1 Example: root@192.168.1.1
--ssh-backup SSH_PATH --ssh-backup SSH_PATH
@@ -24,6 +25,9 @@ Sanely build and deploy OpenWRT images using the Image Builder or from source co
--reset --reset
Cleanup all source and output files Cleanup all source and output files
Can be combined with -p to reset a specific profile Can be combined with -p to reset a specific profile
--depends
Force dependency installation
Ignores .dependencies files
--yes,-y --yes,-y
Assume yes for all questions (automatic mode) Assume yes for all questions (automatic mode)
--debug,-d --debug,-d

View File

@@ -1,18 +1,18 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Builds and deploys OpenWRT images # Builds and deploys OpenWRT images
# Copyright 2022-24 Bryan C. Roessler # Copyright 2022-25 Bryan C. Roessler
# Apache 2.0 License # Apache 2.0 License
# See README.md and ./profiles for device configuration # See README and profiles for device configuration
# Set default release # Set default release
: "${RELEASE:="24.10.0-rc5"}" : "${RELEASE:="24.10.2"}"
# @internal # @internal
print_help() { print_help() {
debug "${FUNCNAME[0]}" debug "${FUNCNAME[0]}"
cat <<-'EOF' cat <<-'EOF'
Build and deploy OpenWRT images Build and deploy OpenWRT images using convenient profiles.
USAGE: USAGE:
openwrtbuilder [OPTION [VALUE]]... -p PROFILE [-p PROFILE]... openwrtbuilder [OPTION [VALUE]]... -p PROFILE [-p PROFILE]...
@@ -24,6 +24,8 @@ print_help() {
Default: location of openwrtbuilder script Default: location of openwrtbuilder script
--source --source
Build image from source, not from Image Builder Build image from source, not from Image Builder
Allows make config options to be passed in profile
Uses git worktree for multi-profile deduplication
--ssh-upgrade HOST --ssh-upgrade HOST
Examples: root@192.168.1.1, root@router.lan Examples: root@192.168.1.1, root@router.lan
--ssh-backup SSH_PATH --ssh-backup SSH_PATH
@@ -32,17 +34,17 @@ print_help() {
Example: /dev/sdX Example: /dev/sdX
--reset --reset
Cleanup all source and output files Cleanup all source and output files
--depends
Force dependency installation
--yes,-y --yes,-y
Assume yes for all questions (automatic mode) Assume yes for all questions (automatic mode)
--verbose
Make make or imagebuilder noisier
--debug,-d --debug,-d
--help,-h --help,-h
EXAMPLES EXAMPLES
./openwrtbuilder -p r4s -r snapshot ./openwrtbuilder -p r4s -r snapshot
./openwrtbuilder -p ax6000 -r 23.05.0-rc3 --source --debug ./openwrtbuilder -p ax6000 -r 23.05.0-rc3 --source --debug
./openwrtbuilder -p rpi4 -r 22.03.3 --flash /dev/sdX ./openwrtbuilder -p rpi4 -r 24.10.0 --flash /dev/sdX
./openwrtbuilder -p linksys -r snapshot --ssh-upgrade root@192.168.1.1 ./openwrtbuilder -p linksys -r snapshot --ssh-upgrade root@192.168.1.1
EOF EOF
} }
@@ -124,10 +126,10 @@ init() {
parse_input() { parse_input() {
debug "${FUNCNAME[0]}" "$*" debug "${FUNCNAME[0]}" "$*"
declare -ga PROFILES declare -ga PROFILES
declare -g RESET=0 FROM_SOURCE=0 YES=0 VERBOSE=0 DEBUG=0 declare -gi RESET=0 FROM_SOURCE=0 YES=0 DEBUG=0 FORCE_DEPENDS=0
declare -g USER_RELEASE SSH_UPGRADE_PATH SSH_BACKUP_PATH FLASH_DEV declare -g USER_RELEASE SSH_UPGRADE_PATH SSH_BACKUP_PATH FLASH_DEV
local long_opts='release:,version:,profile:,buildroot:,source,' local long_opts='release:,version:,profile:,buildroot:,source,'
long_opts+='ssh-upgrade:,ssh-backup:,flash:,reset,yes,verbose,debug,help' long_opts+='ssh-upgrade:,ssh-backup:,flash:,reset,depends,yes,debug,help'
if _input=$(getopt -o +r:v:p:b:sf:ydh -l $long_opts -- "$@"); then if _input=$(getopt -o +r:v:p:b:sf:ydh -l $long_opts -- "$@"); then
eval set -- "$_input" eval set -- "$_input"
@@ -141,8 +143,8 @@ parse_input() {
--ssh-backup) shift; SSH_BACKUP_PATH="$1" ;; --ssh-backup) shift; SSH_BACKUP_PATH="$1" ;;
--flash|-f) shift; FLASH_DEV="$1" ;; --flash|-f) shift; FLASH_DEV="$1" ;;
--reset) RESET=1 ;; --reset) RESET=1 ;;
--depends) FORCE_DEPENDS=1 ;;
--yes|-y) YES=1 ;; --yes|-y) YES=1 ;;
--verbose) VERBOSE=1 ;;
--debug|-d) echo "Debugging on"; DEBUG=1 ;; --debug|-d) echo "Debugging on"; DEBUG=1 ;;
--help|-h) print_help; exit 0 ;; --help|-h) print_help; exit 0 ;;
--) shift; break ;; --) shift; break ;;
@@ -166,70 +168,70 @@ install_dependencies() {
lock_file="$BUILD_ROOT/.dependencies_ib" lock_file="$BUILD_ROOT/.dependencies_ib"
fi fi
if [[ ! -f $lock_file ]]; then if ((FORCE_DEPENDS)) || [[ ! -f $lock_file ]]; then
if ((FROM_SOURCE)); then if ((FROM_SOURCE)); then
# For building from source code # For building from source code see:
# https://openwrt.org/docs/guide-developer/toolchain/install-buildsystem # https://openwrt.org/docs/guide-developer/toolchain/install-buildsystem
case "$ID" in case "$ID" in
fedora|centos) fedora|centos)
pkg_list+=( pkg_list+=(
bash-completion
bzip2 bzip2
clang # for qosify
diffutils
gcc gcc
gcc-c++ gcc-c++
git git
llvm15-libs # for qosify
make make
ncurses-devel ncurses-devel
patch patch
rsync perl
tar
unzip
wget
which
diffutils
python3
python3-devel
python3-setuptools
python3-pyelftools
perl-base
perl-Data-Dumper perl-Data-Dumper
perl-File-Compare perl-File-Compare
perl-File-Copy perl-File-Copy
perl-FindBin perl-FindBin
perl-IPC-Cmd perl-IPC-Cmd
perl-JSON-PP
perl-Thread-Queue perl-Thread-Queue
perl-Time-Piece perl-Time-Piece
perl-JSON-PP perl-base
python3
python3-devel
python3-pyelftools
python3-setuptools
rsync
swig swig
clang # for qosify tar
llvm15-libs unzip
patch) wget
;; which
) ;;
debian|ubuntu) debian|ubuntu)
pkg_list+=( pkg_list+=(
build-essential build-essential
clang clang
file
flex flex
g++ g++
gawk gawk
gcc-multilib gcc-multilib
gettext gettext
git git
liblzma-dev
libncurses5-dev libncurses5-dev
libssl-dev libssl-dev
python3-distutils python3-distutils
rsync rsync
patch
unzip unzip
zlib1g-dev
file
wget wget
patch) zlib1g-dev
;; ) ;;
arch) arch)
pkg_list+=( pkg_list+=(
base-devel
autoconf autoconf
automake automake
base-devel
bash bash
binutils binutils
bison bison
@@ -252,6 +254,7 @@ install_dependencies() {
m4 m4
make make
ncurses ncurses
net-snmp
openssl openssl
patch patch
pkgconf pkgconf
@@ -264,13 +267,10 @@ install_dependencies() {
util-linux util-linux
wget wget
which which
xz
zlib zlib
patch) ) ;;
;; *) debug "Unsupported OS, skipping dependencies"; return 1 ;;
*)
debug "Skipping dependency install, your OS is unsupported"
return 1
;;
esac esac
else else
# For Imagebuilder # For Imagebuilder
@@ -391,7 +391,7 @@ make_images() {
# fi # fi
# fi # fi
((VERBOSE)) && make_opts+=("V=s") ((DEBUG)) && make_opts+=("V=sc")
debug make "${make_opts[@]}" image BIN_DIR="$BIN_DIR" \ debug make "${make_opts[@]}" image BIN_DIR="$BIN_DIR" \
PROFILE="$DEVICE" PACKAGES="$PACKAGES" \ PROFILE="$DEVICE" PACKAGES="$PACKAGES" \
@@ -466,18 +466,37 @@ from_source() {
local seed_url="$1" local seed_url="$1"
local src_url="https://github.com/openwrt/openwrt.git" local src_url="https://github.com/openwrt/openwrt.git"
local seed_file="$WORKTREE_DIR/.config" local seed_file="$WORKTREE_DIR/.config"
local worktree_name; worktree_name="$(basename "$WORKTREE_DIR")"
local worktree_meta="$SRC_DIR/.git/worktrees/$worktree_name"
local pkg config commit seed_file wt_commit description local pkg config commit seed_file wt_commit description
local -a make_opts config_opts local -a make_opts config_opts
echo "Building from source is under development" echo "Building from source is under development"
if ((DEBUG)); then
echo "Profile settings:"
for x in "${!P_ARR[@]}"; do printf "%s=%s\n" "$x" "${P_ARR[$x]}"; done
echo "Environment variables:"
declare -p
fi
if ((RESET)); then
if [[ -d "$WORKTREE_DIR" || -d "$worktree_meta" ]]; then
execute git -C "$SRC_DIR" worktree remove --force --force "$WORKTREE_DIR"
[[ -d "$WORKTREE_DIR" ]] && execute rm -rf "$WORKTREE_DIR"
[[ -d "$worktree_meta" ]] && execute rm -rf "$worktree_meta"
fi
[[ -d "$BUILD_DIR" ]] && execute rm -rf "$BUILD_DIR"
fi
# Update source code # Update source code
if [[ ! -d "$SRC_DIR" ]]; then if [[ ! -d "$SRC_DIR" ]]; then
execute mkdir -p "$SRC_DIR" execute mkdir -p "$SRC_DIR"
execute git clone "$src_url" "$SRC_DIR" execute git clone "$src_url" "$SRC_DIR"
fi fi
git -C "$SRC_DIR" pull execute git -C "$SRC_DIR" worktree prune --verbose
execute git -C "$SRC_DIR" pull
# Generate commitish for git worktree # Generate commitish for git worktree
case "$RELEASE" in case "$RELEASE" in
@@ -497,18 +516,16 @@ from_source() {
;; ;;
esac esac
# TODO There's a bug in the make clean functions that seem to invoke a full make # Pull existing or add new git worktree
if [[ -d "$WORKTREE_DIR" ]]; then if [[ -d "$WORKTREE_DIR" && -d "$worktree_meta" ]]; then
execute git -C "$WORKTREE_DIR" checkout "$wt_commit" execute git -C "$WORKTREE_DIR" checkout "$wt_commit"
execute git -C "$WORKTREE_DIR" pull execute git -C "$WORKTREE_DIR" pull
else else
execute git -C "$SRC_DIR" worktree add --force --detach "$WORKTREE_DIR" "$wt_commit" [[ -d "$WORKTREE_DIR" ]] && execute rm -rf "$WORKTREE_DIR"
[[ -d "$worktree_meta" ]] && execute rm -rf "$worktree_meta"
execute git -C "$SRC_DIR" worktree add --force --force --detach "$WORKTREE_DIR" "$wt_commit"
fi fi
# To workaround bug, don't use make *clean, blow it away and start fresh
# [[ -d "$WORKTREE_DIR" ]] && execute rm -rf "$WORKTREE_DIR"
# execute git -C "$SRC_DIR" worktree add --force --detach "$WORKTREE_DIR" "$wt_commit"
# Print commit information # Print commit information
commit=$(git -C "$WORKTREE_DIR" rev-parse HEAD) commit=$(git -C "$WORKTREE_DIR" rev-parse HEAD)
description=$(git -C "$WORKTREE_DIR" describe) description=$(git -C "$WORKTREE_DIR" describe)
@@ -521,15 +538,17 @@ from_source() {
execute pushd "$WORKTREE_DIR" || return 1 execute pushd "$WORKTREE_DIR" || return 1
# Cleanup build environment # Cleanup build environment
((VERBOSE)) && make_opts+=("V=s") ((DEBUG)) && make_opts+=("V=sc")
execute make "${make_opts[@]}" "-j1" distclean execute make "${make_opts[@]}" "-j1" distclean
# make clean # compiled output # make clean # compiled output
# make targetclean # compiled output, toolchain # make targetclean # compiled output, toolchain
# make dirclean # compiled output, toolchain, build tools # make dirclean # compiled output, toolchain, build tools
# make distclean # compiled output, toolchain, build tools, .config, feeds, .ccache # make distclean # compiled output, toolchain, build tools, .config, feeds, .ccache
# Use a custom (faster) mirror
# execute sed -i -E 's;git.openwrt.org/(feed|project);github.com/openwrt;' feeds.conf.default
# Update package feed # Update package feed
./scripts/feeds update -i -f &&
./scripts/feeds update -a -f && ./scripts/feeds update -a -f &&
./scripts/feeds install -a -f ./scripts/feeds install -a -f
@@ -586,8 +605,7 @@ from_source() {
# Make prep # Make prep
execute make "${make_opts[@]}" "-j1" defconfig execute make "${make_opts[@]}" "-j1" defconfig
execute make "${make_opts[@]}" "-j1" download execute make "${make_opts[@]}" "-j1" download
# ((DEBUG)) && make_opts+=("-j1") || make_opts+=("-j$(($(nproc)+1))") ((DEBUG)) && make_opts+=("-j1") || make_opts+=("-j$(($(nproc)-1))")
make_opts+=("-j$(($(nproc)+1))")
# Make image # Make image
if ! execute ionice -c 3 chrt --idle 0 nice -n19 make "${make_opts[@]}" world; then if ! execute ionice -c 3 chrt --idle 0 nice -n19 make "${make_opts[@]}" world; then
@@ -765,23 +783,6 @@ main() {
backup "$SYSUPGRADEIMGGZ" "$BACKUP_DIR/$profile/$RELEASE" backup "$SYSUPGRADEIMGGZ" "$BACKUP_DIR/$profile/$RELEASE"
if ((RESET)); then
if ((FROM_SOURCE)); then
[[ -d $WORKTREE_DIR ]] && ask_ok "Remove $WORKTREE_DIR?"
execute git worktree remove --force "$WORKTREE_DIR"
execute rm -rf "$WORKTREE_DIR"
elif [[ -d $BUILD_DIR ]] && ask_ok "Remove $BUILD_DIR?"; then
execute rm -rf "$BUILD_DIR"
fi
fi
if ((DEBUG)); then
echo "Profile settings:"
for x in "${!P_ARR[@]}"; do printf "%s=%s\n" "$x" "${P_ARR[$x]}"; done
echo "Environment variables:"
declare -p
fi
if ((FROM_SOURCE)); then if ((FROM_SOURCE)); then
from_source "$seed_url" || return $? from_source "$seed_url" || return $?
else else

View File

@@ -16,7 +16,7 @@ declare -Ag r4s=(
[packages]="$default_packages luci-app-ddns luci-app-sqm irqbalance \ [packages]="$default_packages luci-app-ddns luci-app-sqm irqbalance \
collectd-mod-df usbutils kmod-usb-storage kmod-usb-storage-uas \ collectd-mod-df usbutils kmod-usb-storage kmod-usb-storage-uas \
kmod-fs-btrfs btrfs-progs block-mount smcroute avahi-daemon \ kmod-fs-btrfs btrfs-progs block-mount smcroute avahi-daemon \
curl ethtool ca-bundle" curl ethtool ca-bundle tailscale"
[config]="CONFIG_KERNEL_BTRFS_FS_POSIX_ACL=y CONFIG_BTRFS_PROGS_ZSTD=y \ [config]="CONFIG_KERNEL_BTRFS_FS_POSIX_ACL=y CONFIG_BTRFS_PROGS_ZSTD=y \
CONFIG_TARGET_ROOTFS_PARTSIZE=512 CONFIG_TARGET_KERNEL_PARTSIZE=32 \ CONFIG_TARGET_ROOTFS_PARTSIZE=512 CONFIG_TARGET_KERNEL_PARTSIZE=32 \
CONFIG_BUILDBOT=n" CONFIG_BUILDBOT=n"
@@ -28,7 +28,7 @@ declare -Ag ax6000=(
[target]="mediatek/filogic" [target]="mediatek/filogic"
[release]="snapshot" [release]="snapshot"
[filesystem]="squashfs" [filesystem]="squashfs"
[packages]="$default_packages -dnsmasq -odhcpd-ipv6only -nftables -firewall4" [packages]="$default_packages -dnsmasq -odhcpd-ipv6only -nftables -firewall4 tailscale"
) )
declare -Ag ax6000_uboot=( declare -Ag ax6000_uboot=(
@@ -50,7 +50,7 @@ declare -Ag n5100=(
lm-sensors samba4-server luci-app-samba4 tailscale shadow-useradd" lm-sensors samba4-server luci-app-samba4 tailscale shadow-useradd"
[config]="CONFIG_KERNEL_BTRFS_FS_POSIX_ACL=y CONFIG_BTRFS_PROGS_ZSTD=y \ [config]="CONFIG_KERNEL_BTRFS_FS_POSIX_ACL=y CONFIG_BTRFS_PROGS_ZSTD=y \
CONFIG_TARGET_ROOTFS_PARTSIZE=512 CONFIG_TARGET_KERNEL_PARTSIZE=32" CONFIG_TARGET_ROOTFS_PARTSIZE=512 CONFIG_TARGET_KERNEL_PARTSIZE=32"
[files]="/mnt/backup" # [files]="/mnt/backup"
) )
declare -Ag rpi4=( declare -Ag rpi4=(