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
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,24 +16,25 @@ printHelp() {
Build and deploy OpenWRT images
USAGE:
openwrtbuilder [OPTION [VALUE]] -p PROFILE [-p PROFILE2]...
openwrtbuilder [OPTION [VALUE]]... -p PROFILE [-p PROFILE]...
OPTIONS
--profile, -p PROFILE
--info, -i (print profile info)
--list-profiles, -l
--release, --version, -r, -v RELEASE ("snapshot", "22.03.3")
--buildroot, -b PATH
--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
--flash,-f DEVICE
Example: /dev/sdX
--reset
Cleanup all source and output files
--debug, -d
--help, -h
--debug,-d
--help,-h
EOF
}
@@ -41,11 +42,12 @@ printHelp() {
init() {
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"
# Save the script directory
# https://stackoverflow.com/a/4774063
SCRIPTDIR="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit $? ; pwd -P)"
if [[ -e "/etc/os-release" ]]; then
@@ -117,6 +119,15 @@ init() {
pkg_install(){ sudo pacman -S --noconfirm --needed "$@"; }
;;
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
declare -ga PROFILES
declare -g PROFILE_INFO
declare long_opts
long_opts='release:,version:,profile:,info:,list-profiles,buildroot:,'
long_opts+='source,ssh-upgrade:,ssh-backup:,flash:,reset,debug,help'
declare long_opts='release:,version:,profile:,buildroot:,source,'
long_opts+='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"
while true; do
case "$1" in
@@ -141,12 +150,6 @@ readInput() {
--profile|-p)
shift && PROFILES+=("$1")
;;
--info|-i)
PROFILE_INFO=1
;;
--list-profiles|-l)
listProfiles && exit $?
;;
--buildroot|-b)
shift && BUILDROOT="$1"
;;
@@ -186,12 +189,6 @@ readInput() {
}
listProfiles() {
debug "${FUNCNAME[0]}"
grep "declare -Ag" "$PFILE" | cut -d" " -f3
}
installDependencies() {
debug "${FUNCNAME[0]}"
@@ -226,6 +223,7 @@ installDependencies() {
"perl-File-Copy"
"perl-FindBin"
"perl-Thread-Queue"
"clang" # for qosify
)
;;
debian|ubuntu)
@@ -257,6 +255,7 @@ installDependencies() {
"binutils"
"bison"
"bzip2"
"clang"
"fakeroot"
"file"
"findutils"
@@ -337,48 +336,37 @@ installDependencies() {
getImageBuilder() {
debug "${FUNCNAME[0]}"
declare dl_tool
if [[ -f "$IB_ARCHIVE" ]]; then
echo "Image Builder $IB_ARCHIVE exists"
if askOk "Redownload Image Builder archive?"; then
if askOK "$IB_ARCHIVE exists. Re-download?"; then
rm -f "$IB_ARCHIVE"
else
return 0
fi
fi
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
echo "Downloading Image Builder archive using $dl_tool"
echo "Downloading Image Builder archive using $DL_TOOL"
debug "$DL_TOOL -o $IB_ARCHIVE $IB_URL"
"$DL_TOOL" -o "$IB_ARCHIVE" "$IB_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
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
return 0
fi
fi
if [[ ! -f "$IB_ARCHIVE" ]]; then
echo "Archive missing"
return 1
fi
"$DL_TOOL" -o "$IB_SHA256_FILE" "$IB_SHA256_URL"
}
# if hash sha256sum &>/dev/null; then
# echo "Verifying checksums"
# 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
extractImageBuilder() {
debug "${FUNCNAME[0]}"
echo "Extracting Image Builder archive"
[[ ! -d "$BUILDDIR" ]] && mkdir -p "$BUILDDIR"
@@ -439,7 +427,7 @@ sshBackup() {
}
makeImage() {
makeImages() {
debug "${FUNCNAME[0]}"
# Reuse the existing output
@@ -453,17 +441,25 @@ makeImage() {
[[ -d "$BUILDDIR" ]] || mkdir -p "$BUILDDIR"
if ! make image \
make image \
BIN_DIR="$THIS_BINDIR" \
PROFILE="${P_ARR[profile]}" \
PACKAGES="${P_ARR[packages]}" \
PACKAGES="${P_ARR[packages]:+"${P_ARR[packages]}"}" \
FILES="${FILESDIR}" \
--directory="$BUILDDIR" \
--jobs="$(nproc)" \
> "$BUILDDIR/make.log"; then
echo "Make image failed!"
exit 1
fi
> "$BUILDDIR/make.log"
}
verifyImages() {
debug "${FUNCNAME[0]}"
declare outfile
for outfile in "$THIS_BINDIR"/*.img.gz; do
verify "$outfile" "$IB_OUT_SHA256_FILE" || return 1
done
}
@@ -478,14 +474,62 @@ flashImage() {
fi
# TODO Roughly choose the correct image
if [[ -f "$FACTORYIMGGZ" ]]; then
img_gz="$FACTORYIMGGZ"
img="$FACTORYIMG"
elif [[ -f "$SYSUPGRADEIMGGZ" ]]; then
img_gz="$SYSUPGRADEIMGGZ"
img="$SYSUPGRADEIMG"
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
return 1
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="$FACTORYIMG"
elif [[ "$_response" =~ ^(s|sysupgrade)$ ]]; then
img_gz="$SYSUPGRADEIMGGZ"
img="$SYSUPGRADEIMG"
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
fi
fi
debug "$img_gz $img"
@@ -498,7 +542,7 @@ flashImage() {
debug "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
sync
echo "Image flashed sucessfully!"
@@ -512,16 +556,28 @@ flashImage() {
sshUpgrade() {
debug "${FUNCNAME[0]}"
echo "Copying '$SYSUPGRADEIMGGZ' to $SSH_UPGRADE_PATH/tmp/"
debug "scp \"$SYSUPGRADEIMGGZ\" \"$SSH_UPGRADE_PATH\":\"/tmp/$SYSUPGRADEIMGGZFNAME\""
if ! scp "$SYSUPGRADEIMGGZ" "$SSH_UPGRADE_PATH":"/tmp/$SYSUPGRADEIMGGZFNAME"; then
echo "Could not access the --ssh-upgrade PATH"
exit 1
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/"
debug "scp $SYSUPGRADEIMGGZ $SSH_UPGRADE_PATH:/tmp/$SYSUPGRADEIMGGZFNAME"
if ! scp "$SYSUPGRADEIMGGZ" "$SSH_UPGRADE_PATH":"/tmp/$SYSUPGRADEIMGGZFNAME"; then
echo "Could not access the --ssh-upgrade PATH"
return 1
fi
fi
fi
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
ssh "$SSH_UPGRADE_PATH" "sysupgrade -F /tmp/$SYSUPGRADEIMGGZFNAME"
}
@@ -531,38 +587,110 @@ fromSource() {
debug "${FUNCNAME[0]}"
declare src_url="https://github.com/openwrt/openwrt.git"
declare src_dir="$SRCDIR/openwrt"
declare -a pkg_list
declare pkg kopt
declare -a make_opts
echo "Building from source is under development"
if [[ ! -d "$src_dir" ]]; then
mkdir -p "$src_dir"
git clone "$src_url" "$src_dir"
# Update source code
if [[ ! -d "$GITSRCDIR" ]]; then
mkdir -p "$GITSRCDIR"
git clone "$src_url" "$GITSRCDIR"
fi
pushd "$src_dir" || return 1
git -C "$GITSRCDIR" pull
if [[ ${P_ARR[release]} == "snapshot" ]]; then
git checkout master
git -C "$GITSRCDIR" worktree add -d "$GITWORKTREEDIR" master
else
git checkout "v$RELEASE"
git -C "$GITSRCDIR" worktree add -d "$GITWORKTREEDIR" "v$RELEASE"
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
# Grab the release config.seed
k_options=$(curl -s "$SEED_URL")
debug "$k_options"
# Grab the release seed config
if [[ -f "$SEED_FILE" ]]; then
if askOk "$SEED_FILE exists. Recreate?"; then
make distclean
fi
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
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"
make distclean
make download
make -j"$(nproc)" world
# 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"
popd || return 1
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
}
@@ -597,13 +725,25 @@ resetProfile() {
loadProfiles() {
debug "${FUNCNAME[0]}"
declare -g PFILE
# https://stackoverflow.com/a/4774063
PFILE="$SCRIPTDIR/profiles"
# shellcheck source=./profiles
! 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() {
debug "${FUNCNAME[0]}"
@@ -619,6 +759,7 @@ main() {
declare -g FILESDIR="${FILESDIR:=$BUILDROOT/src/files}"
declare -g SRCDIR="$BUILDROOT/src" # input/build
declare -g BINDIR="$BUILDROOT/bin" # output
declare -g GITSRCDIR="$SRCDIR/openwrt"
for dir in "$SRCDIR" "$BINDIR"; do
[[ -d "$dir" ]] || mkdir -p "$dir"
@@ -639,7 +780,7 @@ main() {
for profile in "${PROFILES[@]}"; do
debug "Starting profile: $profile"
if [[ ! ${!profile@a} = A ]]; then
if [[ ! ${!profile@a} = A ]]; then
echo "Profile '$profile' does not exist"
return 1
fi
@@ -649,48 +790,68 @@ main() {
# release precedence: user input>profile>env>hardcode
declare -g RELEASE="${USER_RELEASE:=${P_ARR[release]:=$RELEASE}}"
declare -g BUILDDIR="$SRCDIR/${P_ARR[profile]}-$RELEASE"
declare -g IB_ARCHIVE="$SRCDIR/${P_ARR[profile]}-$RELEASE.tar.xz"
declare -g BUILDDIR="$SRCDIR/$profile/${P_ARR[profile]}-$RELEASE"
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
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 img_prefix="$BUILDDIR/openwrt-${P_ARR[target]//\//-}-${P_ARR[profile]}-$FILESYSTEM"
declare img_fname="openwrt-${P_ARR[target]//\//-}-${P_ARR[profile]}-$FILESYSTEM"
else
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 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
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_FILE="$GITSRCDIR/.config"
declare -g FACTORYIMG="$img_prefix-factory.img"
declare -g FACTORYIMGGZ="$img_prefix-factory.img.gz"
declare -g SYSUPGRADEIMG="$img_prefix-sysupgrade.img"
declare -g SYSUPGRADEIMGGZ="$img_prefix-sysupgrade.img.gz"
declare -g FACTORYIMG="$BUILDDIR/$img_fname-factory.img"
declare -g FACTORYIMGGZ="$BUILDDIR/$img_fname-factory.img.gz"
declare -g FACTORYIMGGZFNAME="${FACTORYIMGGZ##*/}"
declare -g SYSUPGRADEIMG="$BUILDDIR/$img_fname-sysupgrade.img"
declare -g SYSUPGRADEIMGGZ="$BUILDDIR/$img_fname-sysupgrade.img.gz"
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:"
for x in "${!P_ARR[@]}"; do printf "%s=%s\n" "$x" "${P_ARR[$x]}"; done
echo "Build settings:"
cat <<- EOF
ALIAS: $profile
BUILDROOT: $BUILDROOT
BUILDDIR: $BUILDDIR
SRCDIR: $SRCDIR
BINDIR: $BINDIR
THIS_BINDIR: $THIS_BINDIR
TARGET: ${P_ARR[target]}
PROFILE: ${P_ARR[profile]}
RELEASE: $RELEASE
FILESYSTEM: $FILESYSTEM
IB_URL: $IB_URL
IB_ARCHIVE: $IB_ARCHIVE
ALIAS=$profile
BUILDROOT=$BUILDROOT
BUILDDIR=$BUILDDIR
SRCDIR=$SRCDIR
BINDIR=$BINDIR
GITSRCDIR=$GITSRCDIR
THIS_BINDIR=$THIS_BINDIR
TARGET=${P_ARR[target]}
PROFILE=${P_ARR[profile]}
RELEASE=$RELEASE
FILESYSTEM=$FILESYSTEM
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
fi
@@ -698,11 +859,21 @@ main() {
(( FROM_SOURCE )) && fromSource
getImageBuilder || return $?
# Acquire and verify Image Builder
getImageBuilder &&
getImageBuilderChecksum &&
verify "$IB_ARCHIVE" "$IB_SHA256_FILE" ||
return $?
extractImageBuilder || return $?
addRepos
#copyFiles
[[ -v SSH_BACKUP_PATH ]] && sshBackup
if makeImage; then
if makeImages && verifyImages; then
[[ -v SSH_UPGRADE_PATH ]] && sshUpgrade
[[ -v FLASH_DEV ]] && flashImage
fi
@@ -711,3 +882,12 @@ main() {
main "$@"
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 \
nano \
htop \
tcpdump \
diffutils \
tar \
iperf \
@@ -90,6 +89,7 @@ r4s['packages']="\
$default_packages \
luci-app-upnp \
luci-app-wireguard \
luci-proto-wireguard \
luci-app-ddns \
luci-app-sqm \
irqbalance \
@@ -106,7 +106,12 @@ r4s['packages']="\
smcroute \
curl \
ethtool \
ca-bundle"
ca-bundle \
tailscale"
r4s['kopts']="\
CONFIG_KERNEL_BTRFS_FS_POSIX_ACL=y \
"
declare -Ag ax6000_stock
ax6000_stock['profile']="xiaomi_redmi-router-ax6000-stock"