Compare commits

..

11 Commits

Author SHA1 Message Date
8dc558a6d5 Do distclean before editing .config 2024-12-05 22:10:30 -05:00
ff275aa0ad Retry dirclean 2024-12-05 22:00:08 -05:00
0ead0af0b5 Remove kernel config overridden by defconfig 2024-12-05 21:56:59 -05:00
21899bb072 Remove tabs from profiles 2024-12-05 21:39:32 -05:00
84dc370d32 Separate debug output from verbose make 2024-12-05 21:37:15 -05:00
ab1569fced Remove unecessary element quoting 2024-12-05 21:25:11 -05:00
be5dfb2832 Reformat and simplify device profiles 2024-12-05 21:21:02 -05:00
7dbc7fc3ef Multicore --debug make 2024-11-30 20:57:50 -05:00
9efb42f944 Refactor image backup 2024-11-30 19:41:38 -05:00
6ba2335f8a Standardize var naming 2024-11-30 19:03:17 -05:00
114c9dfc68 Don't install zero dependencies 2024-11-30 18:28:34 -05:00
2 changed files with 297 additions and 398 deletions

View File

@@ -33,6 +33,8 @@ print_help() {
Cleanup all source and output files Cleanup all source and output files
--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
@@ -46,13 +48,13 @@ print_help() {
init() { init() {
debug "${FUNCNAME[0]}" debug "${FUNCNAME[0]}"
declare -g ID RPM_MGR SCRIPTDIR DL_TOOL declare -g ID RPM_MGR SCRIPT_DIR DL_TOOL
((DEBUG)) || echo "To enable debugging output, use --debug or -d" ((DEBUG)) || echo "To enable debugging output, use --debug or -d"
# Save the script directory # Save the script directory
# https://stackoverflow.com/a/4774063 # https://stackoverflow.com/a/4774063
SCRIPTDIR="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit $? ; pwd -P)" SCRIPT_DIR="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit $? ; pwd -P)"
if [[ -e "/etc/os-release" ]]; then if [[ -e "/etc/os-release" ]]; then
source "/etc/os-release" source "/etc/os-release"
@@ -120,22 +122,25 @@ 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 -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,debug,help' long_opts+='ssh-upgrade:,ssh-backup:,flash:,reset,yes,verbose,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"
while true; do while true; do
case "$1" in case "$1" in
--release|-r|--version|-v) shift; declare -g USER_RELEASE="$1" ;; --release|-r|--version|-v) shift; USER_RELEASE="$1" ;;
--profile|-p) shift; PROFILES+=("$1") ;; --profile|-p) shift; PROFILES+=("$1") ;;
--buildroot|-b) shift; BUILDROOT="$1" ;; --buildroot|-b) shift; BUILD_ROOT="$1" ;;
--source|-s) FROM_SOURCE=1 ;; --source|-s) FROM_SOURCE=1 ;;
--ssh-upgrade) shift; SSH_UPGRADE_PATH="$1" ;; --ssh-upgrade) shift; SSH_UPGRADE_PATH="$1" ;;
--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 ;;
--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 ;;
--) --)
@@ -156,9 +161,9 @@ install_dependencies() {
local -a pkg_list local -a pkg_list
local lock_file local lock_file
if ((FROM_SOURCE)); then if ((FROM_SOURCE)); then
lock_file="$BUILDROOT/.dependencies_sc" lock_file="$BUILD_ROOT/.dependencies_source"
else else
lock_file="$BUILDROOT/.dependencies_ib" lock_file="$BUILD_ROOT/.dependencies_ib"
fi fi
if [[ ! -f $lock_file ]]; then if [[ ! -f $lock_file ]]; then
@@ -168,99 +173,99 @@ install_dependencies() {
case "$ID" in case "$ID" in
fedora|centos) fedora|centos)
pkg_list+=( pkg_list+=(
"bash-completion" bash-completion
"bzip2" bzip2
"gcc" gcc
"gcc-c++" gcc-c++
"git" git
"make" make
"ncurses-devel" ncurses-devel
"patch" patch
"rsync" rsync
"tar" tar
"unzip" unzip
"wget" wget
"which" which
"diffutils" diffutils
"python3" python3
"python3-devel" python3-devel
"python3-setuptools" python3-setuptools
"python3-pyelftools" python3-pyelftools
"perl-base" 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-Thread-Queue" perl-Thread-Queue
"perl-Time-Piece" perl-Time-Piece
"perl-JSON-PP" perl-JSON-PP
"swig" swig
"clang" # for qosify clang # for qosify
"llvm15-libs" llvm15-libs
"patch") patch)
;; ;;
debian|ubuntu) debian|ubuntu)
pkg_list+=( pkg_list+=(
"build-essential" build-essential
"clang" clang
"flex" flex
"g++" g++
"gawk" gawk
"gcc-multilib" gcc-multilib
"gettext" gettext
"git" git
"libncurses5-dev" libncurses5-dev
"libssl-dev" libssl-dev
"python3-distutils" python3-distutils
"rsync" rsync
"unzip" unzip
"zlib1g-dev" zlib1g-dev
"file" file
"wget" wget
"patch") patch)
;; ;;
arch) arch)
pkg_list+=( pkg_list+=(
"base-devel" base-devel
"autoconf" autoconf
"automake" automake
"bash" bash
"binutils" binutils
"bison" bison
"bzip2" bzip2
"clang" clang
"fakeroot" fakeroot
"file" file
"findutils" findutils
"flex" flex
"gawk" gawk
"gcc" gcc
"gettext" gettext
"git" git
"grep" grep
"groff" groff
"gzip" gzip
"libelf" libelf
"libtool" libtool
"libxslt" libxslt
"m4" m4
"make" make
"ncurses" ncurses
"openssl" openssl
"patch" patch
"pkgconf" pkgconf
"python" python
"rsync" rsync
"sed" sed
"texinfo" texinfo
"time" time
"unzip" unzip
"util-linux" util-linux
"wget" wget
"which" which
"zlib" zlib
"patch") patch)
;; ;;
*) *)
debug "Skipping dependency install, your OS is unsupported" debug "Skipping dependency install, your OS is unsupported"
@@ -272,36 +277,36 @@ install_dependencies() {
case "$ID" in case "$ID" in
fedora|centos) fedora|centos)
pkg_list+=( pkg_list+=(
"@c-development" @c-development
"@development-tools" @development-tools
"@development-libs" @development-libs
"perl-FindBin" perl-FindBin
"zlib-static" zlib-static
"elfutils-libelf-devel" elfutils-libelf-devel
"gawk" gawk
"unzip" unzip
"file" file
"wget" wget
"python3" python3
"python2" python2
"axel" axel
"perl-IPC-Cmd") perl-IPC-Cmd)
;; ;;
debian|ubuntu) debian|ubuntu)
pkg_list+=( pkg_list+=(
"build-essential" build-essential
"libncurses5-dev" libncurses5-dev
"libncursesw5-dev" libncursesw5-dev
"zlib1g-dev" zlib1g-dev
"gawk" gawk
"git" git
"gettext" gettext
"libssl-dev" libssl-dev
"xsltproc" xsltproc
"wget" wget
"unzip" unzip
"python" python
"axel") axel)
;; ;;
*) *)
debug "Skipping dependency install, your OS is unsupported" debug "Skipping dependency install, your OS is unsupported"
@@ -309,9 +314,9 @@ install_dependencies() {
;; ;;
esac esac
fi fi
fi
pkg_install "${pkg_list[@]}" && echo "${pkg_list[@]}" > "$lock_file" pkg_install "${pkg_list[@]}" && echo "${pkg_list[@]}" > "$lock_file"
fi
} }
get_imagebuilder() { get_imagebuilder() {
@@ -339,10 +344,10 @@ add_repos() {
debug "${FUNCNAME[0]}" debug "${FUNCNAME[0]}"
if [[ -v P_ARR[repo] ]]; then if [[ -v P_ARR[repo] ]]; then
if ! grep -q "${P_ARR[repo]}" "$BUILDDIR/repositories.conf"; then if ! grep -q "${P_ARR[repo]}" "$BUILD_DIR/repositories.conf"; then
echo "${P_ARR[repo]}" >> "$BUILDDIR/repositories.conf" echo "${P_ARR[repo]}" >> "$BUILD_DIR/repositories.conf"
fi fi
sed -i '/option check_signature/d' "$BUILDDIR/repositories.conf" sed -i '/option check_signature/d' "$BUILD_DIR/repositories.conf"
fi fi
} }
@@ -353,7 +358,7 @@ ssh_backup() {
hostname=$(ssh -qt "$SSH_BACKUP_PATH" echo -n \$HOSTNAME) hostname=$(ssh -qt "$SSH_BACKUP_PATH" echo -n \$HOSTNAME)
backup_fname="backup-$hostname-$date.tar.gz" backup_fname="backup-$hostname-$date.tar.gz"
[[ -d "$FILESDIR" ]] || execute mkdir -p "$FILESDIR" [[ -d "$FILES_DIR" ]] || execute mkdir -p "$FILES_DIR"
# Make backup archive on remote # Make backup archive on remote
if ! execute "ssh -t $SSH_BACKUP_PATH sysupgrade -b /tmp/$backup_fname"; then if ! execute "ssh -t $SSH_BACKUP_PATH sysupgrade -b /tmp/$backup_fname"; then
@@ -362,45 +367,48 @@ ssh_backup() {
fi fi
# Move backup archive locally # Move backup archive locally
if ! execute "rsync -avz --remove-source-files $SSH_BACKUP_PATH:/tmp/$backup_fname $BUILDDIR/"; then if ! execute "rsync -avz --remove-source-files $SSH_BACKUP_PATH:/tmp/$backup_fname $BUILD_DIR/"; then
echo "Could not copy SSH backup" echo "Could not copy SSH backup"
exit 1 exit 1
fi fi
# Extract backup archive # Extract backup archive
if ! execute "tar -C $FILESDIR -xzf $BUILDDIR/$backup_fname"; then if ! execute "tar -C $FILES_DIR -xzf $BUILD_DIR/$backup_fname"; then
echo "Could not extract SSH backup" echo "Could not extract SSH backup"
exit 1 exit 1
fi fi
execute "rm $BUILDDIR/$backup_fname" execute "rm $BUILD_DIR/$backup_fname"
} }
make_images() { make_images() {
debug "${FUNCNAME[0]}" debug "${FUNCNAME[0]}"
local -a make_opts
# Reuse the existing output # Reuse the existing output
# if [[ -d "$BINDIR" ]]; then # if [[ -d "$BIN_DIR" ]]; then
# if ask_ok "$BINDIR exists. Rebuild?"; then # if ask_ok "$BIN_DIR exists. Rebuild?"; then
# execute rm -rf "$BINDIR" # execute rm -rf "$BIN_DIR"
# else # else
# return 0 # return 0
# fi # fi
# fi # fi
debug make image BIN_DIR="$BINDIR" \ ((VERBOSE)) && make_opts+=("V=s")
debug make "${make_opts[@]}" image BIN_DIR="$BIN_DIR" \
PROFILE="$DEVICE" PACKAGES="$PACKAGES" \ PROFILE="$DEVICE" PACKAGES="$PACKAGES" \
FILES="$FILESDIR" --directory="$BUILDDIR" \ FILES="$FILES_DIR" --directory="$BUILD_DIR" \
--jobs="$(($(nproc) - 1))" --jobs="$(($(nproc) - 1))"
make image \ make "${make_opts[@]}" image \
BIN_DIR="$BINDIR" \ BIN_DIR="$BINDIR" \
PROFILE="$DEVICE" \ PROFILE="$DEVICE" \
PACKAGES="$PACKAGES" \ PACKAGES="$PACKAGES" \
FILES="$FILESDIR" \ FILES="$FILES_DIR" \
--directory="$BUILDDIR" \ --directory="$BUILD_DIR" \
--jobs="$(($(nproc) - 1))" \ --jobs="$(($(nproc) - 1))" \
> "$BUILDDIR/make.log" > "$BUILD_DIR/make.log"
} }
flash_images() { flash_images() {
@@ -457,19 +465,19 @@ from_source() {
debug "${FUNCNAME[0]}" "$*" debug "${FUNCNAME[0]}" "$*"
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="$GITWORKTREEDIR/.config" local seed_file="$WORKTREE_DIR/.config"
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"
# Update source code # Update source code
if [[ ! -d "$GITSRCDIR" ]]; then if [[ ! -d "$SRC_DIR" ]]; then
execute mkdir -p "$GITSRCDIR" execute mkdir -p "$SRC_DIR"
execute git clone "$src_url" "$GITSRCDIR" execute git clone "$src_url" "$SRC_DIR"
fi fi
git -C "$GITSRCDIR" pull git -C "$SRC_DIR" pull
# Generate commitish for git worktree # Generate commitish for git worktree
case "$RELEASE" in case "$RELEASE" in
@@ -490,33 +498,37 @@ from_source() {
esac esac
# TODO There's a bug in the make clean functions that seem to invoke a full make # TODO There's a bug in the make clean functions that seem to invoke a full make
if [[ -d "$GITWORKTREEDIR" ]]; then if [[ -d "$WORKTREE_DIR" ]]; then
execute git -C "$GITWORKTREEDIR" checkout "$wt_commit" execute git -C "$WORKTREE_DIR" checkout "$wt_commit"
execute git -C "$GITWORKTREEDIR" pull execute git -C "$WORKTREE_DIR" pull
else else
execute git -C "$GITSRCDIR" worktree add --force --detach "$GITWORKTREEDIR" "$wt_commit" execute git -C "$SRC_DIR" worktree add --force --detach "$WORKTREE_DIR" "$wt_commit"
fi fi
# To workaround bug, don't use make *clean, blow it away and start fresh # To workaround bug, don't use make *clean, blow it away and start fresh
# [[ -d "$GITWORKTREEDIR" ]] && execute rm -rf "$GITWORKTREEDIR" # [[ -d "$WORKTREE_DIR" ]] && execute rm -rf "$WORKTREE_DIR"
# execute git -C "$GITSRCDIR" worktree add --force --detach "$GITWORKTREEDIR" "$wt_commit" # execute git -C "$SRC_DIR" worktree add --force --detach "$WORKTREE_DIR" "$wt_commit"
# Print commit information # Print commit information
commit=$(git -C "$GITWORKTREEDIR" rev-parse HEAD) commit=$(git -C "$WORKTREE_DIR" rev-parse HEAD)
description=$(git -C "$GITWORKTREEDIR" describe) description=$(git -C "$WORKTREE_DIR" describe)
echo "Current commit hash: $commit" echo "Current commit hash: $commit"
echo "Git worktree description: $description" echo "Git worktree description: $description"
((DEBUG)) && git --no-pager -C "$GITWORKTREEDIR" log -1 ((DEBUG)) && git --no-pager -C "$WORKTREE_DIR" log -1
# Enter worktree # Enter worktree
execute pushd "$GITWORKTREEDIR" || return 1 execute pushd "$WORKTREE_DIR" || return 1
# Update package feed # Update package feed
./scripts/feeds update -i -f && ./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
# Cleanup build environment
((VERBOSE)) && make_opts+=("V=s")
execute make "${make_opts[@]}" "-j1" distclean # TODO 'dirclean' has a bug that triggers menuconfig
# Grab the release seed config # Grab the release seed config
if ! execute "$DL_TOOL" "-o" "$seed_file" "$seed_url"; then if ! execute "$DL_TOOL" "-o" "$seed_file" "$seed_url"; then
echo "Could not obtain $seed_file from $seed_url" echo "Could not obtain $seed_file from $seed_url"
@@ -524,7 +536,7 @@ from_source() {
fi fi
# Set compilation output dir # Set compilation output dir
config_opts+=("CONFIG_BINARY_FOLDER=\"$BINDIR\"") config_opts+=("CONFIG_BINARY_FOLDER=\"$BIN_DIR\"")
# Add custom packages # Add custom packages
for pkg in $PACKAGES; do for pkg in $PACKAGES; do
@@ -574,11 +586,10 @@ from_source() {
# make distclean # compiled output, toolchain, build tools, .config, feeds, .ccache # make distclean # compiled output, toolchain, build tools, .config, feeds, .ccache
# Make prep # Make prep
((DEBUG)) && make_opts+=("V=s")
execute make "${make_opts[@]}" "-j1" distclean # TODO 'dirclean' has a bug that triggers menuconfig
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
@@ -588,10 +599,10 @@ from_source() {
popd || return 1 popd || return 1
# Symlink output images to root of BINDIR (match Image Builder) # Symlink output images to root of BIN_DIR (match Image Builder)
shopt -s nullglob shopt -s nullglob
for image in "$BINDIR/targets/${TARGET}/"*.{img,img.gz,ubi}; do for image in "$BIN_DIR/targets/${TARGET}/"*.{img,img.gz,ubi}; do
execute ln -fs "$image" "$BINDIR/${image##*/}" execute ln -fs "$image" "$BIN_DIR/${image##*/}"
done done
shopt -u nullglob shopt -u nullglob
@@ -618,18 +629,15 @@ extract() {
} }
backup_image() { backup_image() {
debug "${FUNCNAME[0]} $*" debug "${FUNCNAME[0]} $*"
local file="$1" local file="$1" dir="$2" count=1
local dir="$2" [[ -f $file ]] || return 1
local count=1
[[ -f $file ]] || return
local creation_date local creation_date
creation_date=$(stat -c %w "$file" 2>/dev/null || stat -c %y "$file" | cut -d' ' -f1) creation_date=$(stat -c %w "$file" 2>/dev/null || stat -c %y "$file" | cut -d' ' -f1)
creation_date=${creation_date:-unknown} # Default to "unknown" if no creation date
[[ "$creation_date" == "-" ]] && creation_date="unknown"
local base_name; base_name=$(basename "$file")
execute mkdir -p "$dir" execute mkdir -p "$dir"
local base_name while [[ -e "$dir/$creation_date-$base_name.bk.$count" ]]; do ((count++)); done
base_name=$(basename "$file")
while [[ -e "$dir/$creation_date-$base_name.bk.$count" ]]; do
((count++))
done
execute mv "$file" "$dir/$creation_date-$base_name.bk.$count" execute mv "$file" "$dir/$creation_date-$base_name.bk.$count"
} }
verify() { verify() {
@@ -661,27 +669,27 @@ main() {
debug "${FUNCNAME[0]}" debug "${FUNCNAME[0]}"
init init
load "$SCRIPTDIR/profiles" load "$SCRIPT_DIR/profiles"
parse_input "$@" parse_input "$@"
# Fallback to SCRIPTDIR if BUILDROOT has not been set # Fallback to SCRIPT_DIR if BUILD_ROOT has not been set
declare -g BUILDROOT="${BUILDROOT:=$SCRIPTDIR}" declare -g BUILD_ROOT="${BUILD_ROOT:=$SCRIPT_DIR}"
declare -g FILESDIR="${FILESDIR:=$BUILDROOT/src/files}" declare -g FILES_DIR="${FILES_DIR:=$BUILD_ROOT/src/files}"
declare -g BACKUPDIR="$SCRIPTDIR/backups" declare -g BACKUP_DIR="$SCRIPT_DIR/backups"
# This could be dangerous # This could be dangerous
if [[ $BUILDROOT == "/" ]]; then if [[ $BUILD_ROOT == "/" ]]; then
echo "Invalid --buildroot" echo "Invalid --buildroot"
exit 1 exit 1
fi fi
for dir in "$BUILDROOT/src" "$BUILDROOT/bin"; do for dir in "$BUILD_ROOT/src" "$BUILD_ROOT/bin"; do
[[ -d "$dir" ]] || execute mkdir -p "$dir" [[ -d "$dir" ]] || execute mkdir -p "$dir"
done done
# Allow --reset without a profile # Allow --reset without a profile
if ((RESET)) && [[ ${#PROFILES} -lt 1 ]]; then if ((RESET)) && [[ ${#PROFILES} -lt 1 ]]; then
for d in "$BUILDROOT/src" "$BUILDROOT/bin"; do for d in "$BUILD_ROOT/src" "$BUILD_ROOT/bin"; do
ask_ok "Remove $d?" && execute rm -rf "$d" ask_ok "Remove $d?" && execute rm -rf "$d"
done done
exit $? exit $?
@@ -719,10 +727,10 @@ main() {
;; ;;
esac esac
declare -g GITSRCDIR="$BUILDROOT/src/openwrt" declare -g SRC_DIR="$BUILD_ROOT/src/openwrt"
declare -g GITWORKTREEDIR="$BUILDROOT/src/$profile/$RELEASE-src" declare -g WORKTREE_DIR="$BUILD_ROOT/src/$profile/$RELEASE-src"
declare -g BUILDDIR="$BUILDROOT/src/$profile/$RELEASE" declare -g BUILD_DIR="$BUILD_ROOT/src/$profile/$RELEASE"
declare -g BINDIR="$BUILDROOT/bin/$profile/$RELEASE" declare -g BIN_DIR="$BUILD_ROOT/bin/$profile/$RELEASE"
if [[ "$RELEASE" == "snapshot" ]]; then if [[ "$RELEASE" == "snapshot" ]]; then
local url_prefix="https://downloads.openwrt.org/snapshots/targets/$TARGET" local url_prefix="https://downloads.openwrt.org/snapshots/targets/$TARGET"
@@ -735,26 +743,26 @@ main() {
fi fi
local ib_url="$url_prefix/$url_filename" local ib_url="$url_prefix/$url_filename"
local ib_file="$BUILDDIR/$url_filename" local ib_file="$BUILD_DIR/$url_filename"
local ib_sha256_url="$url_prefix/sha256sums" local ib_sha256_url="$url_prefix/sha256sums"
local ib_sha256_file="$BUILDDIR/sha256sums" local ib_sha256_file="$BUILD_DIR/sha256sums"
local seed_url="$url_prefix/config.buildinfo" local seed_url="$url_prefix/config.buildinfo"
if ((FROM_SOURCE)); then if ((FROM_SOURCE)); then
declare -g SYSUPGRADEIMGGZ="$BINDIR/targets/$img_fname-sysupgrade.img.gz" declare -g SYSUPGRADEIMGGZ="$BIN_DIR/targets/$img_fname-sysupgrade.img.gz"
else else
declare -g SYSUPGRADEIMGGZ="$BUILDDIR/$img_fname-sysupgrade.img.gz" declare -g SYSUPGRADEIMGGZ="$BUILD_DIR/$img_fname-sysupgrade.img.gz"
fi fi
backup_image "$SYSUPGRADEIMGGZ" "$BACKUPDIR/$profile/$RELEASE" backup_image "$SYSUPGRADEIMGGZ" "$BACKUP_DIR/$profile/$RELEASE"
if ((RESET)); then if ((RESET)); then
if ((FROM_SOURCE)); then if ((FROM_SOURCE)); then
[[ -d $GITWORKTREEDIR ]] && ask_ok "Remove $GITWORKTREEDIR?" [[ -d $WORKTREE_DIR ]] && ask_ok "Remove $WORKTREE_DIR?"
execute git worktree remove --force "$GITWORKTREEDIR" execute git worktree remove --force "$WORKTREE_DIR"
execute rm -rf "$GITWORKTREEDIR" execute rm -rf "$WORKTREE_DIR"
elif [[ -d $BUILDDIR ]] && ask_ok "Remove $BUILDDIR?"; then elif [[ -d $BUILD_DIR ]] && ask_ok "Remove $BUILD_DIR?"; then
execute rm -rf "$BUILDDIR" execute rm -rf "$BUILD_DIR"
fi fi
fi fi
@@ -768,16 +776,16 @@ main() {
if ((FROM_SOURCE)); then if ((FROM_SOURCE)); then
from_source "$seed_url" || return $? from_source "$seed_url" || return $?
else else
[[ -d $BUILDDIR ]] || mkdir -p "$BUILDDIR" [[ -d $BUILD_DIR ]] || mkdir -p "$BUILD_DIR"
get_imagebuilder "$ib_url" "$ib_file" "$ib_sha256_url" "$ib_sha256_file" && get_imagebuilder "$ib_url" "$ib_file" "$ib_sha256_url" "$ib_sha256_file" &&
verify "$ib_file" "$ib_sha256_file" && verify "$ib_file" "$ib_sha256_file" &&
extract "$ib_file" "$BUILDDIR" || return $? extract "$ib_file" "$BUILD_DIR" || return $?
add_repos add_repos
make_images make_images
# Verify output image for stock builds (in testing) # Verify output image for stock builds (in testing)
if [[ ! -v P_ARR[packages] || -z ${P_ARR[packages]} ]]; then if [[ ! -v P_ARR[packages] || -z ${P_ARR[packages]} ]]; then
shopt -s nullglob shopt -s nullglob
local -a outfiles=("$BINDIR"/*.img.gz "$BINDIR"/*.img) local -a outfiles=("$BIN_DIR"/*.img.gz "$BIN_DIR"/*.img)
shopt -u nullglob shopt -u nullglob
for outfile in "${outfiles[@]}"; do for outfile in "${outfiles[@]}"; do
verify "$outfile" "$ib_sha256_file" || return 1 verify "$outfile" "$ib_sha256_file" || return 1

297
profiles
View File

@@ -1,218 +1,109 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2034 # shellcheck disable=SC2034
# This file contains a set of device profiles for openwrtbuilder # Device profiles for openwrtbuilder
# bash doesn't like nested arrays so we use strings instead
# Packages to install for all profiles # Default packages
default_packages="\ default_packages="luci luci-ssl luci-proto-wireguard luci-app-statistics \
luci \ collectd-mod-sensors collectd-mod-thermal collectd-mod-conntrack \
luci-ssl \ collectd-mod-cpu nano htop diffutils tar iperf3 zsh rsync \
luci-proto-wireguard \ openssh-sftp-server"
luci-app-statistics \
collectd-mod-sensors \
collectd-mod-thermal \
collectd-mod-conntrack \
collectd-mod-cpu \
nano \
htop \
diffutils \
tar \
iperf3 \
zsh \
rsync \
openssh-sftp-server \
"
# Current devices # Current devices
# Main router declare -Ag r4s=(
declare -Ag r4s [device]="friendlyarm_nanopi-r4s"
r4s['device']="friendlyarm_nanopi-r4s" [target]="rockchip/armv8"
r4s['target']="rockchip/armv8" [filesystem]="ext4"
r4s['filesystem']="ext4" [packages]="$default_packages luci-app-ddns luci-app-sqm irqbalance \
r4s['packages']="\ collectd-mod-df usbutils kmod-usb-storage kmod-usb-storage-uas \
$default_packages \ kmod-fs-btrfs btrfs-progs block-mount smcroute avahi-daemon \
luci-app-ddns \ curl ethtool ca-bundle"
luci-app-sqm \ [config]="CONFIG_KERNEL_BTRFS_FS_POSIX_ACL=y CONFIG_BTRFS_PROGS_ZSTD=y \
irqbalance \ CONFIG_BUILDBOT=n"
collectd-mod-df \ [files]="/mnt/backup"
usbutils \ )
kmod-usb-storage \
kmod-usb-storage-uas \
kmod-fs-btrfs \
btrfs-progs \
block-mount \
smcroute \
avahi-daemon \
curl \
ethtool \
ca-bundle"
# The following only work in --source mode
r4s['config']="\
CONFIG_KERNEL_BTRFS_FS_POSIX_ACL=y \
CONFIG_BTRFS_PROGS_ZSTD=y \
CONFIG_TARGET_ROOTFS_PARTSIZE=512 \
CONFIG_TARGET_KERNEL_PARTSIZE=32 \
CONFIG_BUILDBOT=n"
r4s['files']="\
/mnt/backup"
# Access point declare -Ag ax6000=(
declare -Ag ax6000 [device]="xiaomi_redmi-router-ax6000-stock"
ax6000['device']="xiaomi_redmi-router-ax6000-stock" [target]="mediatek/filogic"
ax6000['target']="mediatek/filogic" [release]="snapshot"
ax6000['release']="snapshot" [filesystem]="squashfs"
ax6000['filesystem']="squashfs" [packages]="$default_packages -dnsmasq -odhcpd-ipv6only -nftables -firewall4"
ax6000['packages']="\ )
$default_packages \
-dnsmasq \
-odhcpd-ipv6only \
-nftables \
-firewall4"
# For uboot'd access points declare -Ag ax6000_uboot=(
declare -Ag ax6000_uboot [device]="xiaomi_redmi-router-ax6000-ubootmod"
ax6000_uboot['device']="xiaomi_redmi-router-ax6000-ubootmod" [target]="mediatek/filogic"
ax6000_uboot['target']="mediatek/filogic" [release]="snapshot"
ax6000_uboot['release']="snapshot" [filesystem]="squashfs"
ax6000_uboot['filesystem']="squashfs" [packages]="$default_packages -dnsmasq -odhcpd-ipv6only -nftables -firewall4"
ax6000_uboot['packages']="\ )
$default_packages \
-dnsmasq \
-odhcpd-ipv6only \
-nftables \
-firewall4"
# Remote NAS declare -Ag n5100=(
declare -Ag n5100 [device]="generic"
n5100['device']="generic" [target]="x86/64"
n5100['target']="x86/64" [filesystem]="squashfs"
n5100['filesystem']="squashfs" [packages]="$default_packages luci-app-ddns irqbalance collectd-mod-df \
n5100['packages']="\ usbutils kmod-usb-storage kmod-usb-storage-uas kmod-fs-btrfs \
$default_packages \ btrfs-progs block-mount cryptsetup kmod-crypto-xts smcroute \
luci-app-ddns \ avahi-daemon curl ethtool ca-bundle smartmontools intel-microcode \
irqbalance \ lm-sensors samba4-server luci-app-samba4 tailscale shadow-useradd"
collectd-mod-df \ [config]="CONFIG_KERNEL_BTRFS_FS_POSIX_ACL=y CONFIG_BTRFS_PROGS_ZSTD=y \
usbutils \ CONFIG_TARGET_ROOTFS_PARTSIZE=512 CONFIG_TARGET_KERNEL_PARTSIZE=32"
kmod-usb-storage \ [files]="/mnt/backup"
kmod-usb-storage-uas \ )
kmod-fs-btrfs \
btrfs-progs \
block-mount \
cryptsetup \
kmod-crypto-xts \
smcroute \
avahi-daemon \
curl \
ethtool \
ca-bundle \
smartmontools \
intel-microcode \
lm-sensors \
samba4-server \
luci-app-samba4 \
tailscale \
shadow-useradd"
# The following are source mode only
n5100['config']="\
CONFIG_KERNEL_BTRFS_FS_POSIX_ACL=y \
CONFIG_BTRFS_PROGS_ZSTD=y \
CONFIG_TARGET_ROOTFS_PARTSIZE=512 \
CONFIG_TARGET_KERNEL_PARTSIZE=32"
n5100['files']="\
/mnt/backup"
# Dusty drawer declare -Ag rpi4=(
declare -Ag rpi4 [device]="rpi-4"
rpi4['device']="rpi-4" [target]="bcm27xx/bcm2711"
rpi4['target']="bcm27xx/bcm2711" [filesystem]="ext4"
rpi4['filesystem']="ext4" [packages]="$default_packages kmod-usb-net-asix-ax88179 kmod-usb-net-rtl8152 \
rpi4['packages']="\ luci-app-upnp luci-app-pbr -dnsmasq dnsmasq-full luci-app-ddns luci-app-sqm"
$default_packages \ )
kmod-usb-net-asix-ax88179 \
kmod-usb-net-rtl8152 \
luci-app-upnp \
luci-app-pbr \
-dnsmasq \
dnsmasq-full \
luci-app-ddns \
luci-app-sqm"
# Stock builds declare -Ag r4s_stock=(
declare -Ag r4s_stock [device]="friendlyarm_nanopi-r4s"
r4s_stock['device']="friendlyarm_nanopi-r4s" [target]="rockchip/armv8"
r4s_stock['target']="rockchip/armv8" [filesystem]="ext4"
r4s_stock['filesystem']="ext4" [release]="snapshot"
r4s_stock['release']="snapshot" )
# Old devices declare -Ag totolink=(
declare -Ag totolink [device]="totolink_x5000r"
totolink['device']="totolink_x5000r" [target]="ramips/mt7621"
totolink['target']="ramips/mt7621" [filesystem]="squashfs"
totolink['filesystem']="squashfs" [packages]="$default_packages -dnsmasq -odhcpd-ipv6only -nftables -firewall4 \
totolink['packages']="\ -kmod-nft-offload collectd-mod-iwinfo"
$default_packages \ )
-dnsmasq \
-odhcpd-ipv6only \
-nftables \
-firewall4 \
-kmod-nft-offload \
collectd-mod-iwinfo"
declare -Ag archer declare -Ag archer=(
archer['device']="tplink_archer-c7-v2" [device]="tplink_archer-c7-v2"
archer['target']="ath79/generic" [target]="ath79/generic"
archer['filesystem']="squashfs" [filesystem]="squashfs"
archer['packages']="\ [packages]="$default_packages -dnsmasq -odhcpd -iptables \
$default_packages \ -ath10k-firmware-qca988x-ct ath10k-firmware-qca988x-ct-full-htt"
-dnsmasq \ )
-odhcpd \
-iptables \
-ath10k-firmware-qca988x-ct \
ath10k-firmware-qca988x-ct-full-htt"
declare -Ag linksys declare -Ag linksys=(
linksys['device']="linksys_ea8300" [device]="linksys_ea8300"
linksys['target']="ipq40xx/generic" [target]="ipq40xx/generic"
linksys['filesystem']="squashfs" [filesystem]="squashfs"
linksys['packages']="\ [packages]="$default_packages -dnsmasq -odhcpd -iptables"
$default_packages \ )
-dnsmasq \
-odhcpd \
-iptables"
declare -Ag r2s declare -Ag r2s=(
r2s['device']="friendlyarm_nanopi-r2s" [device]="friendlyarm_nanopi-r2s"
r2s['target']="rockchip/armv8" [target]="rockchip/armv8"
r2s['filesystem']="ext4" [filesystem]="ext4"
r2s['packages']="\ [packages]="$default_packages luci-app-upnp luci-app-pbr -dnsmasq dnsmasq-full \
$default_packages \ luci-app-ddns luci-app-sqm luci-app-statistics collectd-mod-sensors \
luci-app-upnp \ collectd-mod-thermal collectd-mod-conntrack smcroute curl ethtool"
luci-app-pbr \ )
-dnsmasq \
dnsmasq-full \
luci-app-ddns \
luci-app-sqm \
luci-app-statistics \
collectd-mod-sensors \
collectd-mod-thermal \
collectd-mod-conntrack \
smcroute \
curl \
ethtool"
declare -Ag r2s_tr declare -Ag r2s_tr=(
r2s_tr['device']="friendlyarm_nanopi-r2s" [device]="friendlyarm_nanopi-r2s"
r2s_tr['target']="rockchip/armv8" [target]="rockchip/armv8"
r2s_tr['filesystem']="ext4" [filesystem]="ext4"
r2s_tr['packages']="\ [packages]="$default_packages luci-app-upnp luci-app-pbr luci-app-ddns \
$default_packages \ luci-app-statistics collectd-mod-sensors collectd-mod-thermal \
luci-app-upnp \ collectd-mod-conntrack curl ethtool travelmate"
luci-app-pbr \ )
luci-app-ddns \
luci-app-statistics \
collectd-mod-sensors \
collectd-mod-thermal \
collectd-mod-conntrack \
curl \
ethtool \
travelmate"