Compare commits
39 Commits
847fd59e7c
...
5c6d589e0b
| Author | SHA1 | Date | |
|---|---|---|---|
| 5c6d589e0b | |||
| 80779c9f2d | |||
| ad76c9cc6b | |||
| 5867c8111e | |||
| 128c141843 | |||
| 25c317c4d0 | |||
| 42cbbd43c3 | |||
| 81cd5c0880 | |||
| 6953cdfc5e | |||
| f1f7fca41e | |||
| 1d5b8c522a | |||
| a9dd252ad6 | |||
| bf737644fb | |||
| 1f484d8bfc | |||
| f3aa4a0558 | |||
| 1ac5a8efaa | |||
| bff5d058b0 | |||
| 498b491dc6 | |||
| 16e677ed94 | |||
| 5d5f74850f | |||
| 346094def6 | |||
| 6995284786 | |||
| 462593f523 | |||
| 335dd8e56f | |||
| 941b51da0f | |||
| 97f6e0a927 | |||
| 03db94e20d | |||
| 07fc9e7953 | |||
| cc42ef328c | |||
| e06155527b | |||
| 0243236b16 | |||
| ebacce2f68 | |||
| 824c23901d | |||
| e61493239e | |||
| 7bea684ecf | |||
| d47f635133 | |||
| 16e57cf094 | |||
| faccb7c619 | |||
| a7935e6888 |
7
.gitignore
vendored
7
.gitignore
vendored
@@ -1,6 +1,3 @@
|
||||
sources/
|
||||
src/
|
||||
bin/
|
||||
files/
|
||||
patches/
|
||||
.lock
|
||||
make.log
|
||||
.dependencies
|
||||
@@ -1,6 +1,6 @@
|
||||
# openwrtbuilder
|
||||
|
||||
Sanely build and deploy OpenWRT images using the Image Builder (or git source)
|
||||
Sanely build and deploy OpenWRT images using the Image Builder or from source code
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -36,10 +36,10 @@ See `./profiles` for example device profile definitions.
|
||||
## Examples
|
||||
|
||||
* `./openwrtbuilder -p r4s -r snapshot --debug`
|
||||
* `./openwrtbuilder -p ax6000_stock -r 23.03.3 --source --debug`
|
||||
* `./openwrtbuilder -p rpi4 -r 23.03.3 --flash /dev/sdX`
|
||||
* `./openwrtbuilder -p ax6000_stock -r 22.03.3 --source --debug`
|
||||
* `./openwrtbuilder -p rpi4 -r 22.03.3 --flash /dev/sdX`
|
||||
* `./openwrtbuilder -p linksys -r snapshot --ssh-upgrade root@192.168.1.1`
|
||||
|
||||
## Additional Info
|
||||
|
||||
Did you find `openwrtbuilder` useful? [Buy me a coffee!](https://paypal.me/bryanroessler?locale.x=en_US)
|
||||
Did you find `openwrtbuilder` useful? [Buy me a coffee!](https://paypal.me/bryanroessler)
|
||||
|
||||
499
openwrtbuilder
499
openwrtbuilder
@@ -8,6 +8,9 @@
|
||||
#
|
||||
# See README.md and ./profiles
|
||||
#
|
||||
# Some PROFILE options are incompatible with Image Builder mode (kopts) and
|
||||
# will be ignored
|
||||
#
|
||||
|
||||
# Set default release
|
||||
: "${RELEASE:="22.03.3"}"
|
||||
@@ -29,7 +32,7 @@ printHelp() {
|
||||
--source
|
||||
Build image from source, not from Image Builder
|
||||
--ssh-upgrade HOST
|
||||
Example: root@192.168.1.1
|
||||
Examples: root@192.168.1.1, root@router.lan
|
||||
--ssh-backup SSH_PATH
|
||||
Enabled by default for --ssh-upgrade
|
||||
--flash,-f DEVICE
|
||||
@@ -40,9 +43,9 @@ printHelp() {
|
||||
--help,-h
|
||||
|
||||
EXAMPLES
|
||||
./openwrtbuilder -p r4s -r snapshot --debug
|
||||
./openwrtbuilder -p ax6000_stock -r 23.03.3 --source --debug
|
||||
./openwrtbuilder -p rpi4 -r 23.03.3 --flash /dev/sdX
|
||||
./openwrtbuilder -p r4s -r snapshot
|
||||
./openwrtbuilder -p ax6000_stock -r 22.03.3 --source --debug
|
||||
./openwrtbuilder -p rpi4 -r 22.03.3 --flash /dev/sdX
|
||||
./openwrtbuilder -p linksys -r snapshot --ssh-upgrade root@192.168.1.1
|
||||
EOF
|
||||
}
|
||||
@@ -53,7 +56,7 @@ init() {
|
||||
|
||||
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
|
||||
# https://stackoverflow.com/a/4774063
|
||||
@@ -134,7 +137,7 @@ init() {
|
||||
elif hash curl &>/dev/null; then
|
||||
DL_TOOL="curl"
|
||||
else
|
||||
echo "Downloading the Image Builder requires axel or curl!"
|
||||
echo "Downloading the Image Builder requires axel or curl"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
@@ -202,6 +205,7 @@ installDependencies() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
|
||||
declare -a pkg_list
|
||||
declare lock_file="$BUILDROOT/.dependencies"
|
||||
|
||||
# TODO please contribute your platform here
|
||||
if (( FROM_SOURCE )); then
|
||||
@@ -297,6 +301,10 @@ installDependencies() {
|
||||
"zlib"
|
||||
)
|
||||
;;
|
||||
*)
|
||||
debug "Skipping dependency install, your OS is unsupported"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
else
|
||||
# For Imagebuilder
|
||||
@@ -335,16 +343,26 @@ installDependencies() {
|
||||
"axel"
|
||||
)
|
||||
;;
|
||||
*)
|
||||
debug "Skipping dependency install, your OS is unsupported"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
pkg_install "${pkg_list[@]}"
|
||||
# Skip dependency installation if lock file is present
|
||||
[[ -f $lock_file ]] && return
|
||||
|
||||
pkg_install "${pkg_list[@]}" && echo "${pkg_list[@]}" > "$lock_file"
|
||||
|
||||
}
|
||||
|
||||
|
||||
getImageBuilder() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
|
||||
declare url="$1"
|
||||
|
||||
if [[ -f "$IB_ARCHIVE" ]]; then
|
||||
if askOK "$IB_ARCHIVE exists. Re-download?"; then
|
||||
rm -f "$IB_ARCHIVE"
|
||||
@@ -354,8 +372,8 @@ getImageBuilder() {
|
||||
fi
|
||||
|
||||
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 $url"
|
||||
execute "$DL_TOOL" "-o" "$IB_ARCHIVE" "$url"
|
||||
}
|
||||
|
||||
|
||||
@@ -370,20 +388,7 @@ getImageBuilderChecksum() {
|
||||
fi
|
||||
fi
|
||||
|
||||
debug "$DL_TOOL -o $IB_SHA256_FILE $IB_SHA256_URL"
|
||||
"$DL_TOOL" -o "$IB_SHA256_FILE" "$IB_SHA256_URL"
|
||||
}
|
||||
|
||||
|
||||
extractImageBuilder() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
|
||||
echo "Extracting Image Builder archive"
|
||||
debug "tar -xf $IB_ARCHIVE -C $BUILDDIR --strip-components 1"
|
||||
if ! tar -xf "$IB_ARCHIVE" -C "$BUILDDIR" --strip-components 1; then
|
||||
echo "Extraction failed"
|
||||
return 1
|
||||
fi
|
||||
execute "$DL_TOOL -o $IB_SHA256_FILE $IB_SHA256_URL"
|
||||
}
|
||||
|
||||
|
||||
@@ -402,37 +407,33 @@ addRepos() {
|
||||
sshBackup() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
|
||||
local _date _hostname _backup_fname
|
||||
declare date hostname backup_fname
|
||||
|
||||
[[ -d "$FILESDIR" ]] || mkdir -p "$FILESDIR"
|
||||
|
||||
printf -v _date '%(%Y-%m-%d-%H-%M-%S)T'
|
||||
_hostname=$(ssh -qt "$SSH_BACKUP_PATH" echo -n \$HOSTNAME)
|
||||
_backup_fname="backup-$_hostname-$_date.tar.gz"
|
||||
printf -v date '%(%Y-%m-%d-%H-%M-%S)T'
|
||||
hostname=$(ssh -qt "$SSH_BACKUP_PATH" echo -n \$HOSTNAME)
|
||||
backup_fname="backup-$hostname-$date.tar.gz"
|
||||
|
||||
# Make backup archive on remote
|
||||
debug "ssh -t $SSH_BACKUP_PATH sysupgrade -b /tmp/$_backup_fname"
|
||||
if ! ssh -t "$SSH_BACKUP_PATH" "sysupgrade -b /tmp/$_backup_fname"; then
|
||||
if ! execute "ssh -t $SSH_BACKUP_PATH sysupgrade -b /tmp/$backup_fname"; then
|
||||
echo "SSH backup failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Move backup archive locally
|
||||
debug "rsync -avz --remove-source-files $SSH_BACKUP_PATH:/tmp/$_backup_fname $BUILDDIR/"
|
||||
if ! rsync -avz --remove-source-files \
|
||||
"$SSH_BACKUP_PATH":"/tmp/$_backup_fname" "$BUILDDIR/"; then
|
||||
if ! execute "rsync -avz --remove-source-files $SSH_BACKUP_PATH:/tmp/$backup_fname $BUILDDIR/"; then
|
||||
echo "Could not copy SSH backup"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract backup archive
|
||||
debug "tar -C $FILESDIR -xzf $BUILDDIR/$_backup_fname"
|
||||
if ! tar -C "$FILESDIR" -xzf "$BUILDDIR/$_backup_fname"; then
|
||||
if ! execute "tar -C $FILESDIR -xzf $BUILDDIR/$backup_fname"; then
|
||||
echo "Could not extract SSH backup"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm "$BUILDDIR/$_backup_fname"
|
||||
execute "rm $BUILDDIR/$backup_fname"
|
||||
}
|
||||
|
||||
|
||||
@@ -440,18 +441,18 @@ makeImages() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
|
||||
# Reuse the existing output
|
||||
if [[ -d "$THIS_BINDIR" ]]; then
|
||||
if askOk "$THIS_BINDIR exists. Rebuild?"; then
|
||||
rm -rf "$THIS_BINDIR"
|
||||
if [[ -d "$BINDIR" ]]; then
|
||||
if askOk "$BINDIR exists. Rebuild?"; then
|
||||
execute rm -rf "$BINDIR"
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
make image \
|
||||
BIN_DIR="$THIS_BINDIR" \
|
||||
PROFILE="${P_ARR[profile]}" \
|
||||
PACKAGES="${P_ARR[packages]:+"${P_ARR[packages]}"}" \
|
||||
BIN_DIR="$BINDIR" \
|
||||
PROFILE="$PROFILE" \
|
||||
PACKAGES="$PACKAGES" \
|
||||
FILES="${FILESDIR}" \
|
||||
--directory="$BUILDDIR" \
|
||||
--jobs="$(nproc)" \
|
||||
@@ -464,7 +465,7 @@ verifyImages() {
|
||||
|
||||
declare outfile
|
||||
|
||||
for outfile in "$THIS_BINDIR"/*.img.gz; do
|
||||
for outfile in "$BINDIR"/*.img.gz; do
|
||||
verify "$outfile" "$IB_OUT_SHA256_FILE" || return 1
|
||||
done
|
||||
}
|
||||
@@ -473,84 +474,33 @@ verifyImages() {
|
||||
flashImage() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
|
||||
declare img img_gz partitions
|
||||
declare img_gz="$1"
|
||||
declare dev="$2"
|
||||
|
||||
declare img="${img_gz%.gz}"
|
||||
declare partitions
|
||||
|
||||
if [[ ! -e "$FLASH_DEV" ]]; then
|
||||
if [[ ! -e "$dev" ]]; then
|
||||
echo "The device specified by --flash could not be found"
|
||||
exit 1
|
||||
return 1
|
||||
fi
|
||||
|
||||
# TODO Roughly choose the correct image
|
||||
|
||||
|
||||
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="$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
|
||||
if [[ ! -f $img_gz ]]; then
|
||||
echo "$img_gz does not exist"
|
||||
echo "Check your build output"
|
||||
return 1
|
||||
fi
|
||||
|
||||
debug "$img_gz $img"
|
||||
|
||||
debug "gunzip -qfk $img_gz"
|
||||
gunzip -qfk "$img_gz"
|
||||
|
||||
echo "Unmounting target device $FLASH_DEV partitions"
|
||||
partitions=( "$FLASH_DEV"?* )
|
||||
echo "Unmounting target device $dev partitions"
|
||||
partitions=( "$dev"?* )
|
||||
debug "umount ${partitions[*]}"
|
||||
sudo umount "${partitions[@]}"
|
||||
|
||||
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
|
||||
debug "sudo dd if=$img of=$dev bs=2M conv=fsync"
|
||||
if sudo dd if="$img" of="$dev" bs=2M conv=fsync; then
|
||||
sync
|
||||
echo "Image flashed sucessfully!"
|
||||
else
|
||||
@@ -563,36 +513,29 @@ flashImage() {
|
||||
sshUpgrade() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
|
||||
declare img_gz img_fname
|
||||
declare img_gz="$1"
|
||||
declare ssh_path="$2"
|
||||
|
||||
if (( FROM_SOURCE )); then
|
||||
if [[ -f $SOURCESYSUPGRADEIMGGZ ]]; then
|
||||
img_gz="$SOURCESYSUPGRADEIMGGZ"
|
||||
img_fname="$SOURCESYSUPGRADEIMGGZFNAME"
|
||||
fi
|
||||
elif [[ -f $SYSUPGRADEIMGGZ ]]; then
|
||||
img_gz="$SYSUPGRADEIMGGZ"
|
||||
img_fname="$SYSUPGRADEIMGGZFNAME"
|
||||
fi
|
||||
declare img_fname="${img_gz##*/}"
|
||||
|
||||
if [[ ! -f $img_gz ]]; then
|
||||
if ! [[ -f $img_gz ]]; then
|
||||
echo "$img_gz is missing, check build output"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "Copying '$img_gz' to $SSH_UPGRADE_PATH/tmp/$img_fname"
|
||||
debug "scp $img_gz $SSH_UPGRADE_PATH:/tmp/$img_fname"
|
||||
if ! scp "$img_gz" "$SSH_UPGRADE_PATH":"/tmp/$img_fname"; then
|
||||
echo "Could not copy $img_gz to $SSH_UPGRADE_PATH:/tmp/$img_fname"
|
||||
echo "Copying '$img_gz' to $ssh_path/tmp/$img_fname"
|
||||
debug "scp $img_gz $ssh_path:/tmp/$img_fname"
|
||||
if ! scp "$img_gz" "$ssh_path:/tmp/$img_fname"; then
|
||||
echo "Could not copy $img_gz to $ssh_path:/tmp/$img_fname"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "Executing remote sysupgrade"
|
||||
debug "ssh $SSH_UPGRADE_PATH sysupgrade -F /tmp/$img_fname"
|
||||
debug "ssh $ssh_path sysupgrade -F /tmp/$img_fname"
|
||||
# shellcheck disable=SC2029
|
||||
# execute remotely
|
||||
# this will probably be a weird exit code from closed connection
|
||||
ssh "$SSH_UPGRADE_PATH" "sysupgrade -F /tmp/$img_fname"
|
||||
ssh "$ssh_path" "sysupgrade -F /tmp/$img_fname"
|
||||
}
|
||||
|
||||
|
||||
@@ -600,39 +543,56 @@ fromSource() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
|
||||
declare src_url="https://github.com/openwrt/openwrt.git"
|
||||
declare pkg kopt opt
|
||||
declare seed_file="$SOURCEDIR/.config"
|
||||
declare pkg kopt opt commit seed_file wt_cmd
|
||||
declare -a make_opts config_opts
|
||||
declare -g SEED_FILE="$GITWORKTREEDIR/.config"
|
||||
|
||||
echo "Building from source is under development"
|
||||
|
||||
# Update source code
|
||||
if [[ ! -d "$GITSRCDIR" ]]; then
|
||||
mkdir -p "$GITSRCDIR"
|
||||
git clone "$src_url" "$GITSRCDIR"
|
||||
if [[ ! -d "$GITDIR" ]]; then
|
||||
mkdir -p "$GITDIR"
|
||||
git clone "$src_url" "$GITDIR"
|
||||
fi
|
||||
|
||||
git -C "$GITSRCDIR" pull
|
||||
git -C "$GITDIR" pull
|
||||
|
||||
wt_cmd=(git -C "$GITDIR"
|
||||
worktree add
|
||||
--force
|
||||
--detach
|
||||
"$SOURCEDIR")
|
||||
|
||||
if [[ $RELEASE == "snapshot" ]]; then
|
||||
git -C "$GITSRCDIR" worktree add -d "$GITWORKTREEDIR" master
|
||||
execute "${wt_cmd[@]}" master
|
||||
else
|
||||
git -C "$GITSRCDIR" worktree add -d "$GITWORKTREEDIR" "v$RELEASE"
|
||||
execute "${wt_cmd[@]}" "origin/openwrt-${RELEASE%.*}"
|
||||
fi
|
||||
|
||||
pushd "$GITWORKTREEDIR" &>/dev/null || return 1
|
||||
# Print commit information
|
||||
commit=$(git -C "$SOURCEDIR" rev-parse HEAD)
|
||||
echo "Current commit hash: $commit"
|
||||
(( DEBUG )) && git -C "$SOURCEDIR" log -1
|
||||
(( DEBUG )) && git -C "$SOURCEDIR" describe
|
||||
|
||||
# Enter worktree
|
||||
pushd "$SOURCEDIR" || return 1
|
||||
|
||||
# Update package feed
|
||||
./scripts/feeds update -a &&
|
||||
./scripts/feeds install -a
|
||||
|
||||
# Grab the release seed config
|
||||
if ! curl -so "$SEED_FILE" "$SEED_URL"; then
|
||||
echo "Could not obtain $SEED_FILE from $SEED_URL"
|
||||
if ! curl -so "$seed_file" "$SEED_URL"; then
|
||||
echo "Could not obtain $seed_file from $SEED_URL"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Set compilation output dir
|
||||
config_opts+=("CONFIG_BINARY_FOLDER=\"$THIS_BINDIR\"")
|
||||
config_opts+=("CONFIG_BINARY_FOLDER=\"$BINDIR\"")
|
||||
|
||||
# Add custom packages
|
||||
for pkg in ${P_ARR[packages]}; do
|
||||
for pkg in $PACKAGES; do
|
||||
if [[ $pkg == -* ]]; then
|
||||
config_opts+=("CONFIG_PACKAGE_${pkg#-}=n") # remove package
|
||||
else
|
||||
@@ -646,7 +606,7 @@ fromSource() {
|
||||
done
|
||||
|
||||
# Only compile selected fs
|
||||
sed -i '/CONFIG_TARGET_ROOTFS_/d' "$SEED_FILE"
|
||||
sed -i '/CONFIG_TARGET_ROOTFS_/d' "$seed_file"
|
||||
config_opts+=("CONFIG_TARGET_PER_DEVICE_ROOTFS=n")
|
||||
if [[ $FILESYSTEM == "squashfs" ]]; then
|
||||
config_opts+=("CONFIG_TARGET_ROOTFS_EXT4FS=n")
|
||||
@@ -656,11 +616,11 @@ fromSource() {
|
||||
config_opts+=("CONFIG_TARGET_ROOTFS_EXT4FS=y")
|
||||
fi
|
||||
|
||||
# Only compile selected target
|
||||
sed -i '/CONFIG_TARGET_DEVICE_/d' "$SEED_FILE"
|
||||
# Only compile selected target image
|
||||
sed -i '/CONFIG_TARGET_DEVICE_/d' "$seed_file"
|
||||
config_opts+=("CONFIG_TARGET_MULTI_PROFILE=n")
|
||||
config_opts+=("CONFIG_TARGET_PROFILE=DEVICE_${P_ARR[profile]}")
|
||||
config_opts+=("CONFIG_TARGET_${P_ARR[target]//\//_}_DEVICE_${P_ARR[profile]}=y")
|
||||
config_opts+=("CONFIG_TARGET_PROFILE=DEVICE_$PROFILE")
|
||||
config_opts+=("CONFIG_TARGET_${TARGET//\//_}_DEVICE_$PROFILE=y")
|
||||
config_opts+=("CONFIG_SDK=n")
|
||||
config_opts+=("CONFIG_SDK_LLVM_BPF=n")
|
||||
config_opts+=("CONFIG_IB=n")
|
||||
@@ -668,23 +628,12 @@ fromSource() {
|
||||
|
||||
# Write options to config seed file
|
||||
for opt in "${config_opts[@]}"; do
|
||||
debug "Writing $opt to $SEED_FILE"
|
||||
echo "$opt" >> "$SEED_FILE"
|
||||
debug "Writing $opt to $seed_file"
|
||||
echo "$opt" >> "$seed_file"
|
||||
done
|
||||
|
||||
# Update package feed
|
||||
# ./scripts/feeds install will run make defconfig for us
|
||||
# to normalize and expand .config
|
||||
./scripts/feeds update -a &&
|
||||
./scripts/feeds install -a
|
||||
|
||||
# TODO for now symlink clang for qosify
|
||||
declare llvm_dir="$GITSRCDIR/staging_dir/host/llvm-bpf/bin"
|
||||
[[ -d "$llvm_dir" ]] || mkdir -p "$llvm_dir"
|
||||
ln -fs "$(which clang)" "$llvm_dir/clang"
|
||||
|
||||
# Make image
|
||||
(( DEBUG )) && make_opts+=("V=s")
|
||||
# [[ -v P_ARR[nested_kopts] ]] &&
|
||||
# echo "${P_ARR[nested_kopts]}" >> "$seed_file"
|
||||
|
||||
# Cleaning modes
|
||||
# make clean # compiled output
|
||||
@@ -692,54 +641,47 @@ fromSource() {
|
||||
# make dirclean # compiled output, toolchain, build tools
|
||||
# make distclean # compiled output, toolchain, build tools, .config, feeds, .ccache
|
||||
|
||||
debug "make ${make_opts[*]} dirclean"
|
||||
make "${make_opts[@]}" dirclean
|
||||
# Make image
|
||||
(( DEBUG )) && make_opts+=("V=s")
|
||||
debug "make ${make_opts[*]} defconfig"
|
||||
make "${make_opts[@]}" defconfig
|
||||
debug "make ${make_opts[*]} targetclean"
|
||||
make "${make_opts[@]}" targetclean
|
||||
debug "make ${make_opts[*]} download"
|
||||
make "${make_opts[@]}" download
|
||||
debug "make ${make_opts[*]} -j$(nproc) world"
|
||||
make "${make_opts[@]}" -j"$(nproc)" world
|
||||
|
||||
popd &>/dev/null || return 1
|
||||
exit
|
||||
popd || return 1
|
||||
|
||||
# Provide symlinks to images in root of BINDIR (to match Image Builder)
|
||||
shopt -s nullglob
|
||||
for image in "$BINDIR/targets/${TARGET}/"*.{img,img.gz,ubi}; do
|
||||
ln -fs "$image" "$BINDIR/${image##*/}"
|
||||
done
|
||||
shopt -u nullglob
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
# Generic helpers
|
||||
debug() { (( DEBUG )) && echo "Debug: $*"; }
|
||||
|
||||
|
||||
askOk() {
|
||||
local _response
|
||||
read -r -p "$* [y/N]" _response
|
||||
_response=${_response,,}
|
||||
[[ "$_response" =~ ^(yes|y)$ ]]
|
||||
local r
|
||||
read -r -p "$* [y/N]" r
|
||||
r=${r,,}
|
||||
[[ "$r" =~ ^(yes|y)$ ]]
|
||||
}
|
||||
|
||||
|
||||
resetAll() {
|
||||
extract() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
askOk "Remove $SRCDIR and $BINDIR?" || exit $?
|
||||
debug "rm -rf $SRCDIR $BINDIR"
|
||||
rm -rf "$SRCDIR" "$BINDIR"
|
||||
declare archive="$1"
|
||||
declare out_dir="$2"
|
||||
debug "tar -xf $archive -C $out_dir --strip-components 1"
|
||||
if ! tar -xf "$archive" -C "$out_dir" --strip-components 1; then
|
||||
echo "Extraction failed"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
resetProfile() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
askOk "Remove $BUILDDIR and $THIS_BINDIR?" || exit $?
|
||||
debug "rm -rf $BUILDDIR $THIS_BINDIR"
|
||||
rm -rf "$BUILDDIR" "$THIS_BINDIR"
|
||||
}
|
||||
|
||||
|
||||
loadProfiles() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
declare -g PFILE
|
||||
PFILE="$SCRIPTDIR/profiles"
|
||||
# shellcheck source=./profiles
|
||||
! source "$PFILE" && echo "profiles file missing!" && return 1
|
||||
}
|
||||
|
||||
|
||||
verify() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
declare file_to_check="$1"
|
||||
@@ -751,6 +693,17 @@ verify() {
|
||||
checksum=$(grep "${file_to_check##*/}" "$sumfile" | cut -f1 -d' ')
|
||||
echo -n "$checksum $file_to_check" | sha256sum --check --status
|
||||
}
|
||||
load() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
declare source_file="$1"
|
||||
# shellcheck disable=SC1090
|
||||
[[ -f $source_file ]] && source "$source_file"
|
||||
}
|
||||
execute() {
|
||||
declare cmd="$*"
|
||||
debug "$cmd" || cmd+=" &>/dev/null"
|
||||
eval "${cmd[*]}"
|
||||
}
|
||||
|
||||
|
||||
main() {
|
||||
@@ -758,30 +711,30 @@ main() {
|
||||
|
||||
init
|
||||
|
||||
loadProfiles
|
||||
load "$SCRIPTDIR/profiles"
|
||||
|
||||
readInput "$@"
|
||||
|
||||
# Fallback to SCRIPTDIR if BUILDROOT has not been set
|
||||
declare -g BUILDROOT="${BUILDROOT:=$SCRIPTDIR}"
|
||||
[[ $BUILDROOT == "/" ]] && echo "Invalid --buildroot" && exit 1
|
||||
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
|
||||
# This could be dangerous
|
||||
if [[ $BUILDROOT == "/" ]]; then
|
||||
echo "Invalid --buildroot"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for dir in "$BUILDROOT/src" "$BUILDROOT/bin"; do
|
||||
[[ -d "$dir" ]] || mkdir -p "$dir"
|
||||
done
|
||||
|
||||
# Allow --reset without a profile
|
||||
if [[ ${#PROFILES} -lt 1 ]]; then
|
||||
if (( RESET )); then
|
||||
resetAll
|
||||
exit
|
||||
else
|
||||
echo "No profile supplied" && return 1
|
||||
fi
|
||||
if (( RESET )) && [[ ${#PROFILES} -lt 1 ]]; then
|
||||
for d in "$BUILDROOT/src" "$BUILDROOT/bin"; do
|
||||
askOk "Remove $d?" && execute rm -rf "$d"
|
||||
done
|
||||
exit $?
|
||||
fi
|
||||
|
||||
installDependencies
|
||||
@@ -799,94 +752,88 @@ main() {
|
||||
|
||||
# release precedence: user input>profile>env>hardcode
|
||||
declare -g RELEASE="${USER_RELEASE:=${P_ARR[release]:=$RELEASE}}"
|
||||
declare -g BUILDDIR="$SRCDIR/$profile/$RELEASE"
|
||||
declare -g BUILDDIR="$BUILDROOT/src/$profile/$RELEASE"
|
||||
declare -g BINDIR="$BUILDROOT/bin/$profile/$RELEASE"
|
||||
declare -g FILESYSTEM="${P_ARR[filesystem]:="squashfs"}"
|
||||
declare -g THIS_BINDIR="$BINDIR/$profile/$RELEASE"
|
||||
declare -g TARGET="${P_ARR[target]}"
|
||||
declare -g PROFILE="${P_ARR[profile]}"
|
||||
declare -g PACKAGES="${P_ARR[packages]:-}"
|
||||
declare -g SOURCEDIR="$BUILDROOT/src/$profile/$RELEASE-src"
|
||||
declare -g GITDIR="$BUILDROOT/src/openwrt"
|
||||
|
||||
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_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_fname="openwrt-$RELEASE-${P_ARR[target]//\//-}-${P_ARR[profile]}-$FILESYSTEM"
|
||||
if (( RESET )); then
|
||||
if (( FROM_SOURCE )); then
|
||||
[[ -d $SOURCEDIR ]] && askOk "Remove $SOURCEDIR?"
|
||||
execute git worktree remove --force "$SOURCEDIR"
|
||||
execute rm -rf "$SOURCEDIR"
|
||||
elif [[ -d $BUILDDIR ]] && askOk "Remove $BUILDDIR?"; then
|
||||
execute rm -rf "$BUILDDIR"
|
||||
fi
|
||||
fi
|
||||
|
||||
declare -g IB_URL="$url_prefix/$url_filename"
|
||||
declare -g IB_ARCHIVE="$BUILDDIR/$url_filename"
|
||||
declare -g IB_SHA256_URL="$url_prefix/sha256sums"
|
||||
declare -g IB_SHA256_FILE="$IB_ARCHIVE.sha256sums"
|
||||
declare -g IB_OUT_SHA256_FILE="$THIS_BINDIR/sha256sums"
|
||||
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"
|
||||
declare -g SOURCESYSUPGRADEIMGGZFNAME="${SOURCESYSUPGRADEIMGGZ##*/}"
|
||||
declare -g GITWORKTREEDIR="$SRCDIR/$profile/$RELEASE"
|
||||
declare -g SEED_URL="$url_prefix/config.buildinfo"
|
||||
declare -g SEED_FILE="$GITWORKTREEDIR/.config"
|
||||
if [[ "$RELEASE" == "snapshot" ]]; then
|
||||
declare url_prefix="https://downloads.openwrt.org/snapshots/targets/$TARGET"
|
||||
declare url_filename="openwrt-imagebuilder-${TARGET//\//-}.Linux-x86_64.tar.xz"
|
||||
declare img_fname="openwrt-${TARGET//\//-}-$PROFILE-$FILESYSTEM"
|
||||
else
|
||||
declare url_prefix="https://downloads.openwrt.org/releases/$RELEASE/targets/$TARGET"
|
||||
declare url_filename="openwrt-imagebuilder-$RELEASE-${TARGET//\//-}.Linux-x86_64.tar.xz"
|
||||
declare img_fname="openwrt-$RELEASE-${TARGET//\//-}-$PROFILE-$FILESYSTEM"
|
||||
fi
|
||||
|
||||
declare ib_url="$url_prefix/$url_filename"
|
||||
|
||||
if (( FROM_SOURCE )); then
|
||||
declare -g SYSUPGRADEIMGGZ="$BINDIR/targets/$img_fname-sysupgrade.img.gz"
|
||||
declare -g SEED_URL="$url_prefix/config.buildinfo"
|
||||
else
|
||||
declare -g SYSUPGRADEIMGGZ="$BUILDDIR/$img_fname-sysupgrade.img.gz"
|
||||
declare -g IB_ARCHIVE="$BUILDDIR/$url_filename"
|
||||
declare -g IB_SHA256_URL="$url_prefix/sha256sums"
|
||||
declare -g IB_SHA256_FILE="$IB_ARCHIVE.sha256sums"
|
||||
declare -g IB_OUT_SHA256_FILE="$BINDIR/sha256sums"
|
||||
fi
|
||||
|
||||
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
|
||||
ALIAS (\$profile, \$P_ARR -- should match)=$profile, ${!P_ARR}
|
||||
BUILDROOT=$BUILDROOT
|
||||
BUILDDIR=$BUILDDIR
|
||||
SRCDIR=$SRCDIR
|
||||
GITDIR=$GITDIR
|
||||
SOURCEDIR=$SOURCEDIR
|
||||
BINDIR=$BINDIR
|
||||
GITSRCDIR=$GITSRCDIR
|
||||
THIS_BINDIR=$THIS_BINDIR
|
||||
TARGET=${P_ARR[target]}
|
||||
PROFILE=${P_ARR[profile]}
|
||||
TARGET=$TARGET
|
||||
PROFILE=$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
|
||||
SYSUPGRADEIMGGZ=$SYSUPGRADEIMGGZ
|
||||
ib_url=$ib_url
|
||||
EOF
|
||||
fi
|
||||
|
||||
(( RESET )) && resetProfile
|
||||
|
||||
[[ -d $BUILDDIR ]] || mkdir -p "$BUILDDIR"
|
||||
|
||||
(( FROM_SOURCE )) && fromSource
|
||||
|
||||
# Acquire and verify Image Builder
|
||||
getImageBuilder &&
|
||||
getImageBuilderChecksum &&
|
||||
verify "$IB_ARCHIVE" "$IB_SHA256_FILE" ||
|
||||
return $?
|
||||
|
||||
extractImageBuilder || return $?
|
||||
|
||||
addRepos
|
||||
|
||||
#copyFiles
|
||||
|
||||
[[ -v SSH_BACKUP_PATH ]] && sshBackup
|
||||
|
||||
if makeImages && verifyImages; then
|
||||
[[ -v SSH_UPGRADE_PATH ]] && sshUpgrade
|
||||
[[ -v FLASH_DEV ]] && flashImage
|
||||
if (( FROM_SOURCE )); then
|
||||
fromSource || return $?
|
||||
else
|
||||
[[ -d $BUILDDIR ]] || mkdir -p "$BUILDDIR"
|
||||
getImageBuilder "$ib_url" &&
|
||||
getImageBuilderChecksum &&
|
||||
verify "$IB_ARCHIVE" "$IB_SHA256_FILE" &&
|
||||
extract "$IB_ARCHIVE" "$BUILDDIR" || return $?
|
||||
addRepos
|
||||
makeImages &&
|
||||
verifyImages
|
||||
#copyFiles
|
||||
fi
|
||||
|
||||
[[ -v SSH_BACKUP_PATH ]] &&
|
||||
sshBackup
|
||||
[[ -v SSH_UPGRADE_PATH ]] &&
|
||||
sshUpgrade "$SYSUPGRADEIMGGZ" "$SSH_UPGRADE_PATH"
|
||||
[[ -v FLASH_DEV ]] &&
|
||||
flashImage "$SYSUPGRADEIMGGZ" "$FLASH_DEV"
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
74
profiles
74
profiles
@@ -11,18 +11,17 @@ default_packages="\
|
||||
htop \
|
||||
diffutils \
|
||||
tar \
|
||||
iperf \
|
||||
iperf3 \
|
||||
bash \
|
||||
rsync \
|
||||
openssh-sftp-server \
|
||||
luci-app-wireguard \
|
||||
luci-proto-wireguard \
|
||||
luci-app-statistics \
|
||||
luci-app-attendedsysupgrade \
|
||||
collectd-mod-sensors \
|
||||
collectd-mod-thermal \
|
||||
collectd-mod-conntrack \
|
||||
collectd-mod-cpu " # Leave trailing whitespace
|
||||
|
||||
collectd-mod-cpu"
|
||||
|
||||
declare -Ag archer
|
||||
archer['profile']="tplink_archer-c7-v2"
|
||||
@@ -56,7 +55,7 @@ rpi4['packages']="\
|
||||
kmod-usb-net-rtl8152 \
|
||||
luci-app-upnp \
|
||||
luci-app-wireguard \
|
||||
luci-app-vpn-policy-routing \
|
||||
luci-app-pbr \
|
||||
-dnsmasq \
|
||||
dnsmasq-full \
|
||||
luci-app-ddns \
|
||||
@@ -70,7 +69,7 @@ r2s['packages']="\
|
||||
$default_packages \
|
||||
luci-app-upnp \
|
||||
luci-app-wireguard \
|
||||
luci-app-vpn-policy-routing \
|
||||
luci-app-pbr \
|
||||
-dnsmasq \
|
||||
dnsmasq-full \
|
||||
luci-app-ddns \
|
||||
@@ -83,22 +82,33 @@ r2s['packages']="\
|
||||
curl \
|
||||
ethtool"
|
||||
|
||||
declare -Ag r2s_tr
|
||||
r2s_tr['profile']="friendlyarm_nanopi-r2s"
|
||||
r2s_tr['target']="rockchip/armv8"
|
||||
r2s_tr['filesystem']="ext4"
|
||||
r2s_tr['packages']="\
|
||||
$default_packages \
|
||||
luci-app-upnp \
|
||||
luci-app-wireguard \
|
||||
luci-app-pbr \
|
||||
luci-app-ddns \
|
||||
luci-app-statistics \
|
||||
collectd-mod-sensors \
|
||||
collectd-mod-thermal \
|
||||
collectd-mod-conntrack \
|
||||
curl \
|
||||
ethtool \
|
||||
travelmate"
|
||||
|
||||
declare -Ag r4s
|
||||
r4s['profile']="friendlyarm_nanopi-r4s"
|
||||
r4s['target']="rockchip/armv8"
|
||||
r4s['filesystem']="ext4"
|
||||
r4s['packages']="\
|
||||
$default_packages \
|
||||
luci-app-upnp \
|
||||
luci-app-wireguard \
|
||||
luci-proto-wireguard \
|
||||
luci-app-ddns \
|
||||
luci-app-sqm \
|
||||
irqbalance \
|
||||
collectd-mod-sqm \
|
||||
collectd-mod-df \
|
||||
pbr \
|
||||
luci-app-pbr \
|
||||
usbutils \
|
||||
kmod-usb-storage \
|
||||
kmod-usb-storage-uas \
|
||||
@@ -109,14 +119,42 @@ r4s['packages']="\
|
||||
curl \
|
||||
ethtool \
|
||||
ca-bundle \
|
||||
tailscale"
|
||||
-libustream-wolfssl"
|
||||
r4s['kopts']="\
|
||||
CONFIG_KERNEL_BTRFS_FS_POSIX_ACL=y \
|
||||
CONFIG_BTRFS_PROGS_ZSTD=y
|
||||
"
|
||||
CONFIG_BTRFS_PROGS_ZSTD=y \
|
||||
CONFIG_TARGET_ROOTFS_PARTSIZE=1024"
|
||||
r4s['nested_kopts']="CONFIG_TARGET_OPTIMIZATION=\"-O3 -pipe -mcpu=cortex-a72.cortex-a53+crypto+crc\""
|
||||
r4s['files']="\
|
||||
/mnt/backup \
|
||||
"
|
||||
/mnt/backup"
|
||||
|
||||
declare -Ag r4s_stock
|
||||
r4s_stock['profile']="friendlyarm_nanopi-r4s"
|
||||
r4s_stock['target']="rockchip/armv8"
|
||||
r4s_stock['filesystem']="ext4"
|
||||
r4s_stock['release']="snapshot"
|
||||
# r4s_stock['packages']="\
|
||||
# $default_packages \
|
||||
# luci-app-ddns \
|
||||
# irqbalance \
|
||||
# collectd-mod-df \
|
||||
# usbutils \
|
||||
# kmod-usb-storage \
|
||||
# kmod-usb-storage-uas \
|
||||
# kmod-fs-btrfs \
|
||||
# btrfs-progs \
|
||||
# block-mount \
|
||||
# smcroute \
|
||||
# curl \
|
||||
# ethtool \
|
||||
# ca-bundle"
|
||||
# r4s_stock['kopts']="\
|
||||
# CONFIG_KERNEL_BTRFS_FS_POSIX_ACL=y \
|
||||
# CONFIG_BTRFS_PROGS_ZSTD=y \
|
||||
# CONFIG_TARGET_ROOTFS_PARTSIZE=1024"
|
||||
# r4s_stock['nested_kopts']="CONFIG_TARGET_OPTIMIZATION=\"-O3 -pipe -mcpu=cortex-a72.cortex-a53+crypto+crc\""
|
||||
# r4s_stock['files']="\
|
||||
# /mnt/backup"
|
||||
|
||||
declare -Ag ax6000_stock
|
||||
ax6000_stock['profile']="xiaomi_redmi-router-ax6000-stock"
|
||||
|
||||
Reference in New Issue
Block a user