Compare commits
56 Commits
0dfd58b9ef
...
bc20bf535b
| Author | SHA1 | Date | |
|---|---|---|---|
| bc20bf535b | |||
| fbd2a63839 | |||
| f028970924 | |||
| eb2d79ff7e | |||
| 215e0747b4 | |||
| 7d093de1f9 | |||
| 586e5d298e | |||
| dffa2128a8 | |||
| de38f78a55 | |||
| 4cb0cbc3e4 | |||
| a4a21d47ee | |||
| 159249667f | |||
| df7897c4a3 | |||
| a684747c94 | |||
| fd729d02eb | |||
| 98b49ca40b | |||
| b80f31b911 | |||
| bc37d9c0b9 | |||
| 9158b6a966 | |||
| 19e96f38f5 | |||
| 5a6c3de113 | |||
| d425cc9ed2 | |||
| 8a7481f64b | |||
| d1edbee394 | |||
| b040802d3f | |||
| 6d65d2c7a6 | |||
| 3143e5b452 | |||
| 423e910a04 | |||
| 7e8cbb01fd | |||
| d2eb875a97 | |||
| 2fe70355e6 | |||
| b1f664ca7c | |||
| cafdfb4978 | |||
| fb6d8c4e4a | |||
| 2947d088ff | |||
| 099ceadfe1 | |||
| dd2ae010ab | |||
| 4c130e347c | |||
| f504f3e89b | |||
| a9696ac713 | |||
| 8eb569ecdd | |||
| 2b97ab1533 | |||
| 3da0d408ff | |||
| 614082980d | |||
| c8c57db8d4 | |||
| e2ee50197c | |||
| b0dce34b83 | |||
| 44624918bf | |||
| 70e40077f6 | |||
| 25298352a6 | |||
| 86fc9f3170 | |||
| 37b1355d46 | |||
| b7ba3ba159 | |||
| 661de3fd19 | |||
| 31a4aac014 | |||
| 60bb05e19a |
32
README.md
32
README.md
@@ -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)
|
||||
|
||||
424
openwrtbuilder
424
openwrtbuilder
@@ -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
|
||||
echo "Downloading Image Builder archive using $DL_TOOL"
|
||||
debug "$DL_TOOL -o $IB_ARCHIVE $IB_URL"
|
||||
"$DL_TOOL" -o "$IB_ARCHIVE" "$IB_URL"
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
|
||||
echo "Downloading Image Builder archive using $dl_tool"
|
||||
|
||||
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
|
||||
"$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
|
||||
git -C "$GITSRCDIR" pull
|
||||
|
||||
pushd "$src_dir" || return 1
|
||||
|
||||
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"
|
||||
|
||||
make distclean
|
||||
make download
|
||||
make -j"$(nproc)" world
|
||||
# output to bindir instead of builddir
|
||||
# echo "CONFIG_BINARY_FOLDER=\"$THIS_BINDIR\"" >> "$SEED_FILE"
|
||||
|
||||
popd || return 1
|
||||
# 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
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
@@ -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
|
||||
9
profiles
9
profiles
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user