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
|
# 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)
|
||||||
|
|||||||
428
openwrtbuilder
428
openwrtbuilder
@@ -16,24 +16,25 @@ 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
|
--buildroot,-b PATH
|
||||||
--release, --version, -r, -v RELEASE ("snapshot", "22.03.3")
|
Default: location of openwrtbuilder script
|
||||||
--buildroot, -b PATH
|
--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
|
||||||
(Enabled by default for --ssh-upgrade)
|
(Enabled by default for --ssh-upgrade)
|
||||||
--flash, -f DEVICE
|
--flash,-f DEVICE
|
||||||
Example: /dev/sdX
|
Example: /dev/sdX
|
||||||
--reset
|
--reset
|
||||||
Cleanup all source and output files
|
Cleanup all source and output files
|
||||||
--debug, -d
|
--debug,-d
|
||||||
--help, -h
|
--help,-h
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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"
|
}
|
||||||
else
|
|
||||||
echo "Downloading the Image Builder requires axel or curl!"
|
|
||||||
return 1
|
|
||||||
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
|
getImageBuilderChecksum() {
|
||||||
echo "Could not download Image Builder archive"
|
debug "${FUNCNAME[0]}"
|
||||||
return 1
|
|
||||||
|
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
|
fi
|
||||||
|
|
||||||
if [[ ! -f "$IB_ARCHIVE" ]]; then
|
"$DL_TOOL" -o "$IB_SHA256_FILE" "$IB_SHA256_URL"
|
||||||
echo "Archive missing"
|
}
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# 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"
|
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,14 +474,62 @@ flashImage() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# TODO Roughly choose the correct image
|
# TODO Roughly choose the correct image
|
||||||
if [[ -f "$FACTORYIMGGZ" ]]; then
|
|
||||||
img_gz="$FACTORYIMGGZ"
|
|
||||||
img="$FACTORYIMG"
|
if (( FROM_SOURCE )); then
|
||||||
elif [[ -f "$SYSUPGRADEIMGGZ" ]]; then
|
if [[ -f $SOURCEFACTORYIMGGZ &&
|
||||||
img_gz="$SYSUPGRADEIMGGZ"
|
-f $SOURCESYSUPGRADEIMGGZ ]]; then
|
||||||
img="$SYSUPGRADEIMG"
|
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
|
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
|
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]}"
|
||||||
|
|
||||||
echo "Copying '$SYSUPGRADEIMGGZ' to $SSH_UPGRADE_PATH/tmp/"
|
if (( FROM_SOURCE )); then
|
||||||
debug "scp \"$SYSUPGRADEIMGGZ\" \"$SSH_UPGRADE_PATH\":\"/tmp/$SYSUPGRADEIMGGZFNAME\""
|
if [[ -f $SOURCESYSUPGRADEIMGGZ ]]; then
|
||||||
|
echo "Copying '$SOURCESYSUPGRADEIMGGZ' to $SSH_UPGRADE_PATH/tmp/"
|
||||||
if ! scp "$SYSUPGRADEIMGGZ" "$SSH_UPGRADE_PATH":"/tmp/$SYSUPGRADEIMGGZFNAME"; then
|
debug "scp $SOURCESYSUPGRADEIMGGZ $SSH_UPGRADE_PATH:/tmp/$SYSUPGRADEIMGGZFNAME"
|
||||||
echo "Could not access the --ssh-upgrade PATH"
|
if ! scp "$SOURCESYSUPGRADEIMGGZ" "$SSH_UPGRADE_PATH":"/tmp/$SYSUPGRADEIMGGZFNAME"; then
|
||||||
exit 1
|
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
|
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
|
||||||
|
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
|
# TODO symlink clang for qosify
|
||||||
make download
|
[[ -d "$GITSRCDIR/staging_dir/host/llvm-bpf/bin" ]] || mkdir -p "$GITSRCDIR/staging_dir/host/llvm-bpf/bin"
|
||||||
make -j"$(nproc)" world
|
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
|
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"
|
||||||
@@ -639,7 +780,7 @@ main() {
|
|||||||
for profile in "${PROFILES[@]}"; do
|
for profile in "${PROFILES[@]}"; do
|
||||||
debug "Starting profile: $profile"
|
debug "Starting profile: $profile"
|
||||||
|
|
||||||
if [[ ! ${!profile@a} = A ]]; then
|
if [[ ! ${!profile@a} = A ]]; then
|
||||||
echo "Profile '$profile' does not exist"
|
echo "Profile '$profile' does not exist"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -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
|
||||||
9
profiles
9
profiles
@@ -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"
|
||||||
|
|||||||
Reference in New Issue
Block a user