Compare commits

..

56 Commits

Author SHA1 Message Date
bc20bf535b Cleanup help 2023-01-26 21:37:16 -05:00
fbd2a63839 Update README 2023-01-26 21:36:28 -05:00
f028970924 Enable --source and ssh-upgrade, --flash to work 2023-01-26 21:31:21 -05:00
eb2d79ff7e Include wireguard dependency 2023-01-26 20:24:04 -05:00
215e0747b4 Add tailscale 2023-01-26 17:57:00 -05:00
7d093de1f9 Fix worktree option 2023-01-24 10:23:09 -05:00
586e5d298e First stab at git worktrees 2023-01-24 10:15:45 -05:00
dffa2128a8 Prune compilation items 2023-01-23 09:53:17 -05:00
de38f78a55 Allow empty options 2023-01-21 13:39:52 -05:00
4cb0cbc3e4 Add back curl 2023-01-21 12:51:35 -05:00
a4a21d47ee Remove broken curl 2023-01-21 12:37:28 -05:00
159249667f Temp disable targetclean 2023-01-21 12:24:15 -05:00
df7897c4a3 More debug output 2023-01-21 12:23:46 -05:00
a684747c94 Workaround tcpdump build fail 2023-01-20 19:34:18 -05:00
fd729d02eb defconfig after seed 2023-01-20 18:29:36 -05:00
98b49ca40b Add device profile to opts 2023-01-20 18:24:34 -05:00
b80f31b911 Use make envs 2023-01-20 17:57:52 -05:00
bc37d9c0b9 Update profiles 2023-01-20 17:57:21 -05:00
9158b6a966 Cleanup help 2023-01-14 14:49:53 -05:00
19e96f38f5 Simplify options 2023-01-14 14:46:26 -05:00
5a6c3de113 Symlink clang for qosify 2023-01-14 14:24:42 -05:00
d425cc9ed2 Symlink clang for qosify 2023-01-14 14:04:32 -05:00
8a7481f64b Install clang for qosify 2023-01-14 13:59:58 -05:00
d1edbee394 Tidy output 2023-01-14 13:56:41 -05:00
b040802d3f Remove dupe curl 2023-01-14 13:24:21 -05:00
6d65d2c7a6 Fix seedfile dl 2023-01-14 13:18:36 -05:00
3143e5b452 Support kopts 2023-01-14 12:43:25 -05:00
423e910a04 Cleanup checksum path 2023-01-14 12:23:43 -05:00
7e8cbb01fd Cleanup checksum path 2023-01-14 11:21:11 -05:00
d2eb875a97 Cleanup checksum path 2023-01-14 11:12:26 -05:00
2fe70355e6 Use default IB filename 2023-01-14 10:50:27 -05:00
b1f664ca7c More work on sha256sum 2023-01-14 10:45:27 -05:00
cafdfb4978 More work on sha256sum 2023-01-14 10:42:42 -05:00
fb6d8c4e4a More work on sha256sum 2023-01-14 10:41:52 -05:00
2947d088ff More work on sha256sum 2023-01-14 10:36:18 -05:00
099ceadfe1 More work on sha256sum 2023-01-14 10:34:56 -05:00
dd2ae010ab More work on sha256sum 2023-01-14 10:33:52 -05:00
4c130e347c More work on sha256sum 2023-01-14 10:32:29 -05:00
f504f3e89b More work on sha256sum 2023-01-14 10:12:25 -05:00
a9696ac713 Refactor verifyImage 2023-01-13 21:55:45 -05:00
8eb569ecdd Allow cp from debug 2023-01-13 21:34:13 -05:00
2b97ab1533 Refactor 2023-01-13 21:31:35 -05:00
3da0d408ff Use curl for hash 2023-01-13 21:26:28 -05:00
614082980d Add debug 2023-01-13 21:22:15 -05:00
c8c57db8d4 Add debug 2023-01-13 18:32:59 -05:00
e2ee50197c Fix for axel 2023-01-13 18:31:40 -05:00
b0dce34b83 Use checksums 2023-01-13 18:15:56 -05:00
44624918bf Fix derp 2023-01-13 17:29:43 -05:00
70e40077f6 Fix derp 2023-01-13 17:14:54 -05:00
25298352a6 Add more debug 2023-01-13 17:13:36 -05:00
86fc9f3170 Put .config in var 2023-01-13 16:49:13 -05:00
37b1355d46 Change make output to bindir 2023-01-13 16:12:16 -05:00
b7ba3ba159 Prevent make defconfig from overwriting devices 2023-01-13 15:56:27 -05:00
661de3fd19 Fix derp 2023-01-13 15:49:55 -05:00
31a4aac014 Only compile our target 2023-01-13 15:30:36 -05:00
60bb05e19a Support user packages in --source 2023-01-13 15:13:06 -05:00
3 changed files with 342 additions and 127 deletions

View File

@@ -1,3 +1,33 @@
# openwrtbuilder # openwrtbuilder
See `openwrtbuilder --help` for usage. Sanely build and deploy OpenWRT images using the Image Builder (or git source)
## Usage
`openwrtbuilder [--option [VALUE]]... -p PROFILE [-p PROFILE]...`
## Options
```(text)
--profile,-p PROFILE
--release,-r,--version,-v RELEASE ("snapshot", "22.03.3")
--buildroot,-b PATH
Default: location of openwrtbuilder script
--source
Build image from source, not from Image Builder
--ssh-upgrade HOST
Example: root@192.168.1.1
--ssh-backup SSH_PATH
(Enabled by default for --ssh-upgrade)
--flash,-f DEVICE
Example: /dev/sdX
--reset
Cleanup all source and output files
Can be combined with -p to reset a specific profile
--debug,-d
--help,-h
```
## Additional Info
Did you find `openwrtbuilder` useful? [Buy me a coffee!](https://paypal.me/bryanroessler?locale.x=en_US)

View File

@@ -16,14 +16,15 @@ printHelp() {
Build and deploy OpenWRT images Build and deploy OpenWRT images
USAGE: USAGE:
openwrtbuilder [OPTION [VALUE]] -p PROFILE [-p PROFILE2]... openwrtbuilder [OPTION [VALUE]]... -p PROFILE [-p PROFILE]...
OPTIONS OPTIONS
--profile,-p PROFILE --profile,-p PROFILE
--info, -i (print profile info) --release,-r,--version,-v RELEASE ("snapshot", "22.03.3")
--list-profiles, -l
--release, --version, -r, -v RELEASE ("snapshot", "22.03.3")
--buildroot,-b PATH --buildroot,-b PATH
Default: location of openwrtbuilder script
--source
Build image from source, not from Image Builder
--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
@@ -41,11 +42,12 @@ printHelp() {
init() { init() {
debug "${FUNCNAME[0]}" debug "${FUNCNAME[0]}"
declare -g ID RPM_MGR SCRIPTDIR declare -g ID RPM_MGR SCRIPTDIR 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
SCRIPTDIR="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit $? ; pwd -P)" SCRIPTDIR="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit $? ; pwd -P)"
if [[ -e "/etc/os-release" ]]; then if [[ -e "/etc/os-release" ]]; then
@@ -117,6 +119,15 @@ init() {
pkg_install(){ sudo pacman -S --noconfirm --needed "$@"; } pkg_install(){ sudo pacman -S --noconfirm --needed "$@"; }
;; ;;
esac esac
if hash axel &>/dev/null; then
DL_TOOL="axel"
elif hash curl &>/dev/null; then
DL_TOOL="curl"
else
echo "Downloading the Image Builder requires axel or curl!"
return 1
fi
} }
@@ -126,12 +137,10 @@ readInput() {
unset RESET unset RESET
declare -ga PROFILES declare -ga PROFILES
declare -g PROFILE_INFO declare long_opts='release:,version:,profile:,buildroot:,source,'
declare long_opts long_opts+='ssh-upgrade:,ssh-backup:,flash:,reset,debug,help'
long_opts='release:,version:,profile:,info:,list-profiles,buildroot:,'
long_opts+='source,ssh-upgrade:,ssh-backup:,flash:,reset,debug,help'
if _input=$(getopt -o +r:v:p:i:lb:sf:dh -l $long_opts -- "$@"); then if _input=$(getopt -o +r:v:p:b:sf:dh -l $long_opts -- "$@"); then
eval set -- "$_input" eval set -- "$_input"
while true; do while true; do
case "$1" in case "$1" in
@@ -141,12 +150,6 @@ readInput() {
--profile|-p) --profile|-p)
shift && PROFILES+=("$1") shift && PROFILES+=("$1")
;; ;;
--info|-i)
PROFILE_INFO=1
;;
--list-profiles|-l)
listProfiles && exit $?
;;
--buildroot|-b) --buildroot|-b)
shift && BUILDROOT="$1" shift && BUILDROOT="$1"
;; ;;
@@ -186,12 +189,6 @@ readInput() {
} }
listProfiles() {
debug "${FUNCNAME[0]}"
grep "declare -Ag" "$PFILE" | cut -d" " -f3
}
installDependencies() { installDependencies() {
debug "${FUNCNAME[0]}" debug "${FUNCNAME[0]}"
@@ -226,6 +223,7 @@ installDependencies() {
"perl-File-Copy" "perl-File-Copy"
"perl-FindBin" "perl-FindBin"
"perl-Thread-Queue" "perl-Thread-Queue"
"clang" # for qosify
) )
;; ;;
debian|ubuntu) debian|ubuntu)
@@ -257,6 +255,7 @@ installDependencies() {
"binutils" "binutils"
"bison" "bison"
"bzip2" "bzip2"
"clang"
"fakeroot" "fakeroot"
"file" "file"
"findutils" "findutils"
@@ -337,48 +336,37 @@ installDependencies() {
getImageBuilder() { getImageBuilder() {
debug "${FUNCNAME[0]}" debug "${FUNCNAME[0]}"
declare dl_tool
if [[ -f "$IB_ARCHIVE" ]]; then if [[ -f "$IB_ARCHIVE" ]]; then
echo "Image Builder $IB_ARCHIVE exists" if askOK "$IB_ARCHIVE exists. Re-download?"; then
if askOk "Redownload Image Builder archive?"; then
rm -f "$IB_ARCHIVE" rm -f "$IB_ARCHIVE"
else else
return 0 return 0
fi fi
fi fi
if hash axel &>/dev/null; then echo "Downloading Image Builder archive using $DL_TOOL"
dl_tool="axel" debug "$DL_TOOL -o $IB_ARCHIVE $IB_URL"
elif hash curl &>/dev/null; then "$DL_TOOL" -o "$IB_ARCHIVE" "$IB_URL"
dl_tool="curl" }
getImageBuilderChecksum() {
debug "${FUNCNAME[0]}"
if [[ -f $IB_SHA256_FILE ]]; then
if askOk "$IB_SHA256_FILE exists. Re-download?"; then
rm -f "$IB_SHA256_FILE"
else else
echo "Downloading the Image Builder requires axel or curl!" return 0
return 1 fi
fi fi
echo "Downloading Image Builder archive using $dl_tool" "$DL_TOOL" -o "$IB_SHA256_FILE" "$IB_SHA256_URL"
}
debug "$dl_tool -o $IB_ARCHIVE $IB_URL"
if ! "$dl_tool" -o "$IB_ARCHIVE" "$IB_URL"; then
echo "Could not download Image Builder archive"
return 1
fi
if [[ ! -f "$IB_ARCHIVE" ]]; then
echo "Archive missing"
return 1
fi
# if hash sha256sum &>/dev/null; then extractImageBuilder() {
# echo "Verifying checksums" debug "${FUNCNAME[0]}"
# debug "$dl_tool -s "${P_ARR[sha256_url]}" | grep $filename | cut -f1 -d' '"
# sha256sum=$($dl_tool -s "${P_ARR[sha256_url]}" |grep "$filename" |cut -f1 -d' ')
# debug "Downloaded sha256sum: $sha256sum"
# fi
echo "Extracting Image Builder archive" echo "Extracting Image Builder archive"
[[ ! -d "$BUILDDIR" ]] && mkdir -p "$BUILDDIR" [[ ! -d "$BUILDDIR" ]] && mkdir -p "$BUILDDIR"
@@ -439,7 +427,7 @@ sshBackup() {
} }
makeImage() { makeImages() {
debug "${FUNCNAME[0]}" debug "${FUNCNAME[0]}"
# Reuse the existing output # Reuse the existing output
@@ -453,17 +441,25 @@ makeImage() {
[[ -d "$BUILDDIR" ]] || mkdir -p "$BUILDDIR" [[ -d "$BUILDDIR" ]] || mkdir -p "$BUILDDIR"
if ! make image \ make image \
BIN_DIR="$THIS_BINDIR" \ BIN_DIR="$THIS_BINDIR" \
PROFILE="${P_ARR[profile]}" \ PROFILE="${P_ARR[profile]}" \
PACKAGES="${P_ARR[packages]}" \ PACKAGES="${P_ARR[packages]:+"${P_ARR[packages]}"}" \
FILES="${FILESDIR}" \ FILES="${FILESDIR}" \
--directory="$BUILDDIR" \ --directory="$BUILDDIR" \
--jobs="$(nproc)" \ --jobs="$(nproc)" \
> "$BUILDDIR/make.log"; then > "$BUILDDIR/make.log"
echo "Make image failed!" }
exit 1
fi
verifyImages() {
debug "${FUNCNAME[0]}"
declare outfile
for outfile in "$THIS_BINDIR"/*.img.gz; do
verify "$outfile" "$IB_OUT_SHA256_FILE" || return 1
done
} }
@@ -478,15 +474,63 @@ flashImage() {
fi fi
# TODO Roughly choose the correct image # TODO Roughly choose the correct image
if [[ -f "$FACTORYIMGGZ" ]]; then
if (( FROM_SOURCE )); then
if [[ -f $SOURCEFACTORYIMGGZ &&
-f $SOURCESYSUPGRADEIMGGZ ]]; then
local _response
echo "$SOURCEFACTORYIMGGZ and $SOURCESYSUPGRADEIMGGZ both exist"
read -r -p "Flash factory or sysupgrade image? [(f)actory/(s)ysupgrade]" _response
_response=${_response,,}
if [[ "$_response" =~ ^(f|factory)$ ]]; then
img_gz="$SOURCEFACTORYIMGGZ"
img="$SOURCEFACTORYIMG"
elif [[ "$_response" =~ ^(s|sysupgrade)$ ]]; then
img_gz="$SOURCESYSUPGRADEIMGGZ"
img="$SOURCESYSUPGRADEIMG"
else
echo "Invalid input, you must enter f or s"
fi
elif [[ -f $SOURCEFACTORYIMGGZ ]]; then
img_gz="$SOURCEFACTORYIMGGZ"
img="$SOURCEFACTORYIMG"
elif [[ -f $SOURCESYSUPGRADEIMGGZ ]]; then
img_gz="$SOURCESYSUPGRADEIMGGZ"
img="$SOURCESYSUPGRADEIMG"
else
echo "No files found at $SOURCEFACTORYIMGGZ or $SOURCESYSUPGRADEIMGGZ"
echo "Check your build output"
return 1
fi
else
if [[ -f $FACTORYIMGGZ &&
-f $SYSUPGRADEIMGGZ ]]; then
local _response
echo "$FACTORYIMGGZ and $SYSUPGRADEIMGGZ both exist"
read -r -p "Flash factory or sysupgrade image? [(f)actory/(s)ysupgrade]" _response
_response=${_response,,}
if [[ "$_response" =~ ^(f|factory)$ ]]; then
img_gz="$FACTORYIMGGZ" img_gz="$FACTORYIMGGZ"
img="$FACTORYIMG" img="$FACTORYIMG"
elif [[ -f "$SYSUPGRADEIMGGZ" ]]; then elif [[ "$_response" =~ ^(s|sysupgrade)$ ]]; then
img_gz="$SYSUPGRADEIMGGZ" img_gz="$SYSUPGRADEIMGGZ"
img="$SYSUPGRADEIMG" img="$SYSUPGRADEIMG"
else else
echo "Invalid input, you must enter f or s"
fi
elif [[ -f $FACTORYIMGGZ ]]; then
img_gz="$FACTORYIMGGZ"
img="$FACTORYIMG"
elif [[ -f $SYSUPGRADEIMGGZ ]]; then
img_gz="$SYSUPGRADEIMGGZ"
img="$SYSUPGRADEIMG"
else
echo "No files found at $FACTORYIMGGZ or $SYSUPGRADEIMGGZ"
echo "Check your build output"
return 1 return 1
fi fi
fi
debug "$img_gz $img" debug "$img_gz $img"
@@ -498,7 +542,7 @@ flashImage() {
debug "umount ${partitions[*]}" debug "umount ${partitions[*]}"
sudo umount "${partitions[@]}" sudo umount "${partitions[@]}"
debug "sudo dd if=\"$img\" of=\"$FLASH_DEV\" bs=2M conv=fsync" debug "sudo dd if=$img of=$FLASH_DEV bs=2M conv=fsync"
if sudo dd if="$img" of="$FLASH_DEV" bs=2M conv=fsync; then if sudo dd if="$img" of="$FLASH_DEV" bs=2M conv=fsync; then
sync sync
echo "Image flashed sucessfully!" echo "Image flashed sucessfully!"
@@ -512,16 +556,28 @@ flashImage() {
sshUpgrade() { sshUpgrade() {
debug "${FUNCNAME[0]}" debug "${FUNCNAME[0]}"
if (( FROM_SOURCE )); then
if [[ -f $SOURCESYSUPGRADEIMGGZ ]]; then
echo "Copying '$SOURCESYSUPGRADEIMGGZ' to $SSH_UPGRADE_PATH/tmp/"
debug "scp $SOURCESYSUPGRADEIMGGZ $SSH_UPGRADE_PATH:/tmp/$SYSUPGRADEIMGGZFNAME"
if ! scp "$SOURCESYSUPGRADEIMGGZ" "$SSH_UPGRADE_PATH":"/tmp/$SYSUPGRADEIMGGZFNAME"; then
echo "Could not access the --ssh-upgrade PATH"
return 1
fi
fi
else
if [[ -f $SYSUPGRADEIMGGZ ]]; then
echo "Copying '$SYSUPGRADEIMGGZ' to $SSH_UPGRADE_PATH/tmp/" echo "Copying '$SYSUPGRADEIMGGZ' to $SSH_UPGRADE_PATH/tmp/"
debug "scp \"$SYSUPGRADEIMGGZ\" \"$SSH_UPGRADE_PATH\":\"/tmp/$SYSUPGRADEIMGGZFNAME\"" debug "scp $SYSUPGRADEIMGGZ $SSH_UPGRADE_PATH:/tmp/$SYSUPGRADEIMGGZFNAME"
if ! scp "$SYSUPGRADEIMGGZ" "$SSH_UPGRADE_PATH":"/tmp/$SYSUPGRADEIMGGZFNAME"; then if ! scp "$SYSUPGRADEIMGGZ" "$SSH_UPGRADE_PATH":"/tmp/$SYSUPGRADEIMGGZFNAME"; then
echo "Could not access the --ssh-upgrade PATH" echo "Could not access the --ssh-upgrade PATH"
exit 1 return 1
fi
fi
fi fi
echo "Executing remote sysupgrade" echo "Executing remote sysupgrade"
debug "ssh \"$SSH_UPGRADE_PATH\" \"sysupgrade -F /tmp/$SYSUPGRADEIMGGZFNAME\"" debug "ssh $SSH_UPGRADE_PATH sysupgrade -F /tmp/$SYSUPGRADEIMGGZFNAME"
# shellcheck disable=SC2029 # shellcheck disable=SC2029
ssh "$SSH_UPGRADE_PATH" "sysupgrade -F /tmp/$SYSUPGRADEIMGGZFNAME" ssh "$SSH_UPGRADE_PATH" "sysupgrade -F /tmp/$SYSUPGRADEIMGGZFNAME"
} }
@@ -531,38 +587,110 @@ fromSource() {
debug "${FUNCNAME[0]}" debug "${FUNCNAME[0]}"
declare src_url="https://github.com/openwrt/openwrt.git" declare src_url="https://github.com/openwrt/openwrt.git"
declare src_dir="$SRCDIR/openwrt" declare pkg kopt
declare -a pkg_list declare -a make_opts
echo "Building from source is under development" echo "Building from source is under development"
if [[ ! -d "$src_dir" ]]; then # Update source code
mkdir -p "$src_dir" if [[ ! -d "$GITSRCDIR" ]]; then
git clone "$src_url" "$src_dir" mkdir -p "$GITSRCDIR"
git clone "$src_url" "$GITSRCDIR"
fi fi
git -C "$GITSRCDIR" pull
pushd "$src_dir" || return 1
if [[ ${P_ARR[release]} == "snapshot" ]]; then if [[ ${P_ARR[release]} == "snapshot" ]]; then
git checkout master git -C "$GITSRCDIR" worktree add -d "$GITWORKTREEDIR" master
else else
git checkout "v$RELEASE" git -C "$GITSRCDIR" worktree add -d "$GITWORKTREEDIR" "v$RELEASE"
fi fi
./scripts/feeds update -a pushd "$GITWORKTREEDIR" &>/dev/null || return 1
SEED_FILE="$GITWORKTREEDIR/.config"
# if [[ ${P_ARR[release]} == "snapshot" ]]; then
# git checkout master
# else
# git checkout "v$RELEASE"
# fi
# git pull
# Update package feed
./scripts/feeds update -a &&
./scripts/feeds install -a ./scripts/feeds install -a
# Grab the release config.seed # Grab the release seed config
k_options=$(curl -s "$SEED_URL") if [[ -f "$SEED_FILE" ]]; then
debug "$k_options" if askOk "$SEED_FILE exists. Recreate?"; then
make distclean make distclean
make download fi
make -j"$(nproc)" world fi
if [[ -f "$SEED_FILE" ]]; then
echo "Reusing existing $SEED_FILE seed config"
else
if ! curl -so "$SEED_FILE" "$SEED_URL"; then
echo "Could not obtain seed config"
fi
fi
popd || return 1 make defconfig # normalize .config and remove dupes
for pkg in ${P_ARR[packages]:+}; do
if [[ $pkg == -* ]]; then
make_opts+=("CONFIG_PACKAGE_${pkg#-}=n") # remove package
else
make_opts+=("CONFIG_PACKAGE_$pkg=y") # add package
fi
done
for kopt in ${P_ARR[kopts]:+}; do
make_opts+=("$kopt")
done
make_opts+=("CONFIG_TARGET_MULTI_PROFILE=n")
make_opts+=("CONFIG_TARGET_ALL_PROFILES=n")
make_opts+=("CONFIG_SDK=n")
make_opts+=("CONFIG_SDK_LLVM_BPF=n")
make_opts+=("CONFIG_TARGET_PROFILE=DEVICE_${P_ARR[profile]}")
make_opts+=("CONFIG_TARGET_DEVICE_${P_ARR[target]//\//_}_DEVICE_${P_ARR[profile]}=y")
make_opts+=("CONFIG_BINARY_FOLDER=\"$THIS_BINDIR\"")
(( DEBUG )) && make_opts+=("V=s")
# Override default .config seed with profile packages
# for pkg in ${P_ARR[packages]:+${P_ARR[packages]}}; do
# if [[ $pkg == -* ]]; then
# echo "CONFIG_PACKAGE_${pkg#-}=n" >> "$SEED_FILE" # remove package
# else
# echo "CONFIG_PACKAGE_$pkg=y" >> "$SEED_FILE" # add package
# fi
# done
# Add custom kernel config options
# for kopt in ${P_ARR[kopts]:+${P_ARR[kopts]}}; do
# echo "$kopt" >> "$SEED_FILE"
# done
# Only compile our target
# TODO causes a "configuration is out of sync" error w/o defconfig
# sed -i '/CONFIG_TARGET_DEVICE_/d' "$SEED_FILE"
# echo "CONFIG_TARGET_DEVICE_${P_ARR[target]//\//_}_DEVICE_${P_ARR[profile]}=y" >> "$SEED_FILE"
# output to bindir instead of builddir
# echo "CONFIG_BINARY_FOLDER=\"$THIS_BINDIR\"" >> "$SEED_FILE"
# TODO symlink clang for qosify
[[ -d "$GITSRCDIR/staging_dir/host/llvm-bpf/bin" ]] || mkdir -p "$GITSRCDIR/staging_dir/host/llvm-bpf/bin"
ln -fs "$(which clang)" "$GITSRCDIR/staging_dir/host/llvm-bpf/bin/clang"
make "${make_opts[@]}" download &&
debug "${make_opts[*]} -j$(nproc) world" &&
make "${make_opts[@]}" -j"$(nproc)" world
popd &>/dev/null || return 1
exit # TODO exit here for fromSource() testing exit # TODO exit here for fromSource() testing
} }
@@ -597,13 +725,25 @@ resetProfile() {
loadProfiles() { loadProfiles() {
debug "${FUNCNAME[0]}" debug "${FUNCNAME[0]}"
declare -g PFILE declare -g PFILE
# https://stackoverflow.com/a/4774063
PFILE="$SCRIPTDIR/profiles" PFILE="$SCRIPTDIR/profiles"
# shellcheck source=./profiles # shellcheck source=./profiles
! source "$PFILE" && echo "profiles file missing!" && return 1 ! source "$PFILE" && echo "profiles file missing!" && return 1
} }
verify() {
debug "${FUNCNAME[0]}"
declare file_to_check="$1"
declare sumfile="$2"
declare checksum
hash sha256sum &>/dev/null || return 1
[[ -f $sumfile && -f $file_to_check ]] || return 1
checksum=$(grep "${file_to_check##*/}" "$sumfile" | cut -f1 -d' ')
echo -n "$checksum $file_to_check" | sha256sum --check --status
}
main() { main() {
debug "${FUNCNAME[0]}" debug "${FUNCNAME[0]}"
@@ -619,6 +759,7 @@ main() {
declare -g FILESDIR="${FILESDIR:=$BUILDROOT/src/files}" declare -g FILESDIR="${FILESDIR:=$BUILDROOT/src/files}"
declare -g SRCDIR="$BUILDROOT/src" # input/build declare -g SRCDIR="$BUILDROOT/src" # input/build
declare -g BINDIR="$BUILDROOT/bin" # output declare -g BINDIR="$BUILDROOT/bin" # output
declare -g GITSRCDIR="$SRCDIR/openwrt"
for dir in "$SRCDIR" "$BINDIR"; do for dir in "$SRCDIR" "$BINDIR"; do
[[ -d "$dir" ]] || mkdir -p "$dir" [[ -d "$dir" ]] || mkdir -p "$dir"
@@ -649,48 +790,68 @@ main() {
# release precedence: user input>profile>env>hardcode # release precedence: user input>profile>env>hardcode
declare -g RELEASE="${USER_RELEASE:=${P_ARR[release]:=$RELEASE}}" declare -g RELEASE="${USER_RELEASE:=${P_ARR[release]:=$RELEASE}}"
declare -g BUILDDIR="$SRCDIR/${P_ARR[profile]}-$RELEASE" declare -g BUILDDIR="$SRCDIR/$profile/${P_ARR[profile]}-$RELEASE"
declare -g IB_ARCHIVE="$SRCDIR/${P_ARR[profile]}-$RELEASE.tar.xz"
declare -g FILESYSTEM="${P_ARR[filesystem]:="squashfs"}" declare -g FILESYSTEM="${P_ARR[filesystem]:="squashfs"}"
declare -g THIS_BINDIR="$BINDIR/${P_ARR[profile]}-$RELEASE" declare -g THIS_BINDIR="$BINDIR/$profile/${P_ARR[profile]}-$RELEASE"
if [[ "$RELEASE" == "snapshot" ]]; then if [[ "$RELEASE" == "snapshot" ]]; then
declare url_prefix="https://downloads.openwrt.org/snapshots/targets/${P_ARR[target]}" declare url_prefix="https://downloads.openwrt.org/snapshots/targets/${P_ARR[target]}"
declare url_filename="openwrt-imagebuilder-${P_ARR[target]//\//-}.Linux-x86_64.tar.xz" declare url_filename="openwrt-imagebuilder-${P_ARR[target]//\//-}.Linux-x86_64.tar.xz"
declare img_prefix="$BUILDDIR/openwrt-${P_ARR[target]//\//-}-${P_ARR[profile]}-$FILESYSTEM" declare img_fname="openwrt-${P_ARR[target]//\//-}-${P_ARR[profile]}-$FILESYSTEM"
else else
declare url_prefix="https://downloads.openwrt.org/releases/$RELEASE/targets/${P_ARR[target]}" declare url_prefix="https://downloads.openwrt.org/releases/$RELEASE/targets/${P_ARR[target]}"
declare url_filename="openwrt-imagebuilder-$RELEASE-${P_ARR[target]//\//-}.Linux-x86_64.tar.xz" declare url_filename="openwrt-imagebuilder-$RELEASE-${P_ARR[target]//\//-}.Linux-x86_64.tar.xz"
declare img_prefix="$BUILDDIR/openwrt-$RELEASE-${P_ARR[target]//\//-}-${P_ARR[profile]}-$FILESYSTEM" declare img_fname="openwrt-$RELEASE-${P_ARR[target]//\//-}-${P_ARR[profile]}-$FILESYSTEM"
fi fi
declare -g IB_URL="$url_prefix/$url_filename" declare -g IB_URL="$url_prefix/$url_filename"
declare -g SHA256_URL="$url_prefix/sha256sums" declare -g IB_ARCHIVE="$SRCDIR/$url_filename"
declare -g IB_SHA256_URL="$url_prefix/sha256sums"
declare -g IB_SHA256_FILE="$BUILDDIR/sha256sums"
declare -g IB_OUT_SHA256_FILE="$THIS_BINDIR/sha256sums"
declare -g SEED_URL="$url_prefix/config.buildinfo" declare -g SEED_URL="$url_prefix/config.buildinfo"
declare -g SEED_FILE="$GITSRCDIR/.config"
declare -g FACTORYIMG="$img_prefix-factory.img" declare -g FACTORYIMG="$BUILDDIR/$img_fname-factory.img"
declare -g FACTORYIMGGZ="$img_prefix-factory.img.gz" declare -g FACTORYIMGGZ="$BUILDDIR/$img_fname-factory.img.gz"
declare -g SYSUPGRADEIMG="$img_prefix-sysupgrade.img" declare -g FACTORYIMGGZFNAME="${FACTORYIMGGZ##*/}"
declare -g SYSUPGRADEIMGGZ="$img_prefix-sysupgrade.img.gz" declare -g SYSUPGRADEIMG="$BUILDDIR/$img_fname-sysupgrade.img"
declare -g SYSUPGRADEIMGGZ="$BUILDDIR/$img_fname-sysupgrade.img.gz"
declare -g SYSUPGRADEIMGGZFNAME="${SYSUPGRADEIMGGZ##*/}" declare -g SYSUPGRADEIMGGZFNAME="${SYSUPGRADEIMGGZ##*/}"
declare -g SOURCEFACTORYIMG="$THIS_BINDIR/$img_fname-factory.img"
declare -g SOURCEFACTORYIMGGZ="$THIS_BINDIR/$img_fname-factory.img.gz"
declare -g SOURCESYSUPGRADEIMG="$THIS_BINDIR/targets/$img_fname-sysupgrade.img"
declare -g SOURCESYSUPGRADEIMGGZ="$THIS_BINDIR/targets/$img_fname-sysupgrade.img.gz"
if (( DEBUG )) || (( PROFILE_INFO )); then declare -g GITWORKTREEDIR="$GITSRCDIR/$profile/$RELEASE"
if (( DEBUG )); then
echo "Profile settings:" echo "Profile settings:"
for x in "${!P_ARR[@]}"; do printf "%s=%s\n" "$x" "${P_ARR[$x]}"; done for x in "${!P_ARR[@]}"; do printf "%s=%s\n" "$x" "${P_ARR[$x]}"; done
echo "Build settings:" echo "Build settings:"
cat <<- EOF cat <<- EOF
ALIAS: $profile ALIAS=$profile
BUILDROOT: $BUILDROOT BUILDROOT=$BUILDROOT
BUILDDIR: $BUILDDIR BUILDDIR=$BUILDDIR
SRCDIR: $SRCDIR SRCDIR=$SRCDIR
BINDIR: $BINDIR BINDIR=$BINDIR
THIS_BINDIR: $THIS_BINDIR GITSRCDIR=$GITSRCDIR
TARGET: ${P_ARR[target]} THIS_BINDIR=$THIS_BINDIR
PROFILE: ${P_ARR[profile]} TARGET=${P_ARR[target]}
RELEASE: $RELEASE PROFILE=${P_ARR[profile]}
FILESYSTEM: $FILESYSTEM RELEASE=$RELEASE
IB_URL: $IB_URL FILESYSTEM=$FILESYSTEM
IB_ARCHIVE: $IB_ARCHIVE IB_URL=$IB_URL
IB_ARCHIVE=$IB_ARCHIVE
SEED_URL=$SEED_URL
SEED_FILE=$SEED_FILE
IB_SHA256_URL=$IB_SHA256_URL
IB_SHA256_FILE=$IB_SHA256_FILE
IB_OUT_SHA256_FILE=$IB_OUT_SHA256_FILE
FACTORYIMGGZ: $FACTORYIMGGZ
FACTORYIMGGZFNAME: $FACTORYIMGGZFNAME
SYSUPGRADEIMGGZ: $SYSUPGRADEIMGGZ
SYSUPGRADEIMGGZFNAME: $SYSUPGRADEIMGGZFNAME
EOF EOF
fi fi
@@ -698,11 +859,21 @@ main() {
(( FROM_SOURCE )) && fromSource (( FROM_SOURCE )) && fromSource
getImageBuilder || return $? # Acquire and verify Image Builder
getImageBuilder &&
getImageBuilderChecksum &&
verify "$IB_ARCHIVE" "$IB_SHA256_FILE" ||
return $?
extractImageBuilder || return $?
addRepos addRepos
#copyFiles #copyFiles
[[ -v SSH_BACKUP_PATH ]] && sshBackup [[ -v SSH_BACKUP_PATH ]] && sshBackup
if makeImage; then
if makeImages && verifyImages; then
[[ -v SSH_UPGRADE_PATH ]] && sshUpgrade [[ -v SSH_UPGRADE_PATH ]] && sshUpgrade
[[ -v FLASH_DEV ]] && flashImage [[ -v FLASH_DEV ]] && flashImage
fi fi
@@ -711,3 +882,12 @@ main() {
main "$@" main "$@"
exit exit
# VM setup (for testing)
# sudo sgdisk -N 0 /dev/vda &&
# sudo mkfs.ext4 /dev/vda1
# mkdir ~/mnt
# sudo mount /dev/vda1 ~/mnt
# sudo chown liveuser:liveuser -R ~/mnt

View File

@@ -9,7 +9,6 @@ default_packages="\
luci-ssl \ luci-ssl \
nano \ nano \
htop \ htop \
tcpdump \
diffutils \ diffutils \
tar \ tar \
iperf \ iperf \
@@ -90,6 +89,7 @@ r4s['packages']="\
$default_packages \ $default_packages \
luci-app-upnp \ luci-app-upnp \
luci-app-wireguard \ luci-app-wireguard \
luci-proto-wireguard \
luci-app-ddns \ luci-app-ddns \
luci-app-sqm \ luci-app-sqm \
irqbalance \ irqbalance \
@@ -106,7 +106,12 @@ r4s['packages']="\
smcroute \ smcroute \
curl \ curl \
ethtool \ ethtool \
ca-bundle" ca-bundle \
tailscale"
r4s['kopts']="\
CONFIG_KERNEL_BTRFS_FS_POSIX_ACL=y \
"
declare -Ag ax6000_stock declare -Ag ax6000_stock
ax6000_stock['profile']="xiaomi_redmi-router-ax6000-stock" ax6000_stock['profile']="xiaomi_redmi-router-ax6000-stock"