Compare commits
45 Commits
fd5e127ea3
...
0dfd58b9ef
| Author | SHA1 | Date | |
|---|---|---|---|
| 0dfd58b9ef | |||
| 36d392c2f2 | |||
| 4fd858d635 | |||
| d342206f0a | |||
| 00b82452f4 | |||
| 97d7c84b58 | |||
| 29ea95db65 | |||
| 41900c4e02 | |||
| ed331cc581 | |||
| cf7b9e45c0 | |||
| 0c1f60971e | |||
| 00c70b9da0 | |||
| d14d8f9eb8 | |||
| f3579cb9a7 | |||
| 94e6545fcc | |||
| a4efc9e7d1 | |||
| 860631cf7d | |||
| 3683296110 | |||
| 3ee6de5fb1 | |||
| 0bd32d5d7c | |||
| 64081a1dda | |||
| 08601a3284 | |||
| 4cb4e85e4e | |||
| 2009725f33 | |||
| 93eb9afad1 | |||
| 14e8fcb814 | |||
| dde5d6260a | |||
| 3ee0afda05 | |||
| 3f4b9042c9 | |||
| c6158f241e | |||
| 22dd0f25f9 | |||
| 4447ccdd56 | |||
| 8ce8ea92fe | |||
| 2b1e94da87 | |||
| 295855e0ae | |||
| e876247ccd | |||
| b381222022 | |||
| de5f6f02f3 | |||
| b00195dbeb | |||
| ac878b82ee | |||
| 242cdb02b8 | |||
| b9848a177a | |||
| 724755d762 | |||
| 6856791364 | |||
| 3ab01b9d3d |
583
openwrtbuilder
583
openwrtbuilder
@@ -1,29 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Copyright 2022 Bryan C. Roessler
|
||||
# Copyright 2022-23 Bryan C. Roessler
|
||||
#
|
||||
# Build and flash/upgrade OpenWRT devices
|
||||
# Build and deploy OpenWRT images
|
||||
#
|
||||
# Apache 2.0 License
|
||||
|
||||
# Set default release
|
||||
: "${RELEASE:="22.03.2"}"
|
||||
: "${RELEASE:="22.03.3"}"
|
||||
|
||||
printHelp() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
|
||||
cat <<-'EOF'
|
||||
Run and deploy OpenWRT images using the Image Builder.
|
||||
Build and deploy OpenWRT images
|
||||
|
||||
USAGE:
|
||||
openwrtbuilder [OPTION [VALUE]]...
|
||||
openwrtbuilder [OPTION [VALUE]] -p PROFILE [-p PROFILE2]...
|
||||
|
||||
OPTIONS
|
||||
--profile, -p PROFILE
|
||||
--info, -i PROFILE
|
||||
--info, -i (print profile info)
|
||||
--list-profiles, -l
|
||||
--release, -r, --version, -v RELEASE_VERSION ("snapshot", "22.03.3", etc.)
|
||||
--builddir, -b PATH
|
||||
--release, --version, -r, -v RELEASE ("snapshot", "22.03.3")
|
||||
--buildroot, -b PATH
|
||||
--ssh-upgrade HOST
|
||||
Example: root@192.168.1.1
|
||||
--ssh-backup SSH_PATH
|
||||
@@ -38,29 +38,120 @@ EOF
|
||||
}
|
||||
|
||||
|
||||
init() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
|
||||
declare -g ID RPM_MGR SCRIPTDIR
|
||||
|
||||
debug || echo "To enable debugging output, use --debug or -d"
|
||||
|
||||
# Save the script directory
|
||||
SCRIPTDIR="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit $? ; pwd -P)"
|
||||
|
||||
if [[ -e "/etc/os-release" ]]; then
|
||||
source "/etc/os-release"
|
||||
else
|
||||
err "/etc/os-release not found"
|
||||
err "Your OS is unsupported"
|
||||
printHelp
|
||||
exit 1
|
||||
fi
|
||||
|
||||
debug "Detected host platform: $ID"
|
||||
|
||||
# normalize distro ID
|
||||
case "$ID" in
|
||||
debian|arch)
|
||||
;;
|
||||
centos|fedora)
|
||||
if hash dnf &>/dev/null; then
|
||||
RPM_MGR="dnf"
|
||||
elif hash yum &>/dev/null; then
|
||||
RPM_MGR="yum"
|
||||
fi
|
||||
;;
|
||||
rhel)
|
||||
ID="centos"
|
||||
;;
|
||||
linuxmint|neon|*ubuntu*)
|
||||
ID="ubuntu"
|
||||
;;
|
||||
*suse*)
|
||||
ID="suse"
|
||||
;;
|
||||
raspbian)
|
||||
ID="debian"
|
||||
;;
|
||||
*)
|
||||
echo "Autodetecting distro, this may be unreliable"
|
||||
if hash dnf &>/dev/null; then
|
||||
ID="fedora"
|
||||
RPM_MGR="dnf"
|
||||
elif hash yum &>/dev/null; then
|
||||
ID="centos"
|
||||
RPM_MGR="yum"
|
||||
elif hash apt &>/dev/null; then
|
||||
ID="ubuntu"
|
||||
elif hash pacman &>/dev/null; then
|
||||
ID="arch"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
debug "Using host platform: $ID"
|
||||
|
||||
# Set distro-specific functions
|
||||
case "$ID" in
|
||||
fedora|centos)
|
||||
pkg_install(){ sudo "$RPM_MGR" install -y "$@"; }
|
||||
;;
|
||||
debian|ubuntu)
|
||||
pkg_install(){ sudo apt-get install -y -q0 "$@"; }
|
||||
;;
|
||||
suse)
|
||||
pkg_install(){ sudo zypper --non-interactive -q install --force --no-confirm "$@"; }
|
||||
;;
|
||||
arch)
|
||||
pkg_install(){ sudo pacman -S --noconfirm --needed "$@"; }
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
readInput() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
|
||||
unset RESET
|
||||
|
||||
if _input=$(getopt -o +r:v:p:i:lb:f:dh -l release:,version:,profile:,info:,list-profiles,builddir:,ssh-upgrade:,ssh-backup:,flash:,reset,debug,help -- "$@"); then
|
||||
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'
|
||||
|
||||
if _input=$(getopt -o +r:v:p:i:lb:sf:dh -l $long_opts -- "$@"); then
|
||||
eval set -- "$_input"
|
||||
while true; do
|
||||
case "$1" in
|
||||
--release|-r|--version|-v)
|
||||
shift && RELEASE="$1"
|
||||
shift && declare -g USER_RELEASE="$1"
|
||||
;;
|
||||
--profile|-p)
|
||||
shift && PROFILE="$1"
|
||||
shift && PROFILES+=("$1")
|
||||
;;
|
||||
--info|-i)
|
||||
shift && PROFILE="$1" && PROFILE_INFO=1 && exit $?
|
||||
PROFILE_INFO=1
|
||||
;;
|
||||
--list-profiles|-l)
|
||||
listProfiles && exit $?
|
||||
;;
|
||||
--builddir|-b)
|
||||
shift && BUILDDIR="$1"
|
||||
--buildroot|-b)
|
||||
shift && BUILDROOT="$1"
|
||||
;;
|
||||
--source|-s)
|
||||
FROM_SOURCE=1
|
||||
;;
|
||||
--ssh-upgrade)
|
||||
shift && SSH_UPGRADE_PATH="$1"
|
||||
@@ -101,113 +192,200 @@ listProfiles() {
|
||||
}
|
||||
|
||||
|
||||
installHostDependencies() {
|
||||
installDependencies() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
|
||||
local -a _pkg_list
|
||||
local _pkg_cmd
|
||||
declare -a pkg_list
|
||||
|
||||
source /etc/os-release
|
||||
|
||||
if [[ "$ID" =~ ^(fedora)$ ]]; then
|
||||
_pkg_list=(\
|
||||
"@c-development" \
|
||||
"@development-tools" \
|
||||
"@development-libs" \
|
||||
"perl-FindBin" \
|
||||
"zlib-static" \
|
||||
"elfutils-libelf-devel" \
|
||||
"gawk" \
|
||||
"unzip" \
|
||||
"file" \
|
||||
"wget" \
|
||||
"python3" \
|
||||
"python2" \
|
||||
"axel" \
|
||||
# TODO please contribute your platform here
|
||||
if (( FROM_SOURCE )); then
|
||||
# For building from source with make
|
||||
# https://openwrt.org/docs/guide-developer/toolchain/install-buildsystem
|
||||
case "$ID" in
|
||||
fedora|centos)
|
||||
pkg_list+=(
|
||||
"bash-completion"
|
||||
"bzip2"
|
||||
"gcc"
|
||||
"gcc-c++"
|
||||
"git"
|
||||
"make"
|
||||
"ncurses-devel"
|
||||
"patch"
|
||||
"rsync"
|
||||
"tar"
|
||||
"unzip"
|
||||
"wget"
|
||||
"which"
|
||||
"diffutils"
|
||||
"python2"
|
||||
"python3"
|
||||
"perl-base"
|
||||
"perl-Data-Dumper"
|
||||
"perl-File-Compare"
|
||||
"perl-File-Copy"
|
||||
"perl-FindBin"
|
||||
"perl-Thread-Queue"
|
||||
)
|
||||
_pkg_cmd="dnf"
|
||||
elif [[ "$ID" =~ ^(debian|ubuntu)$ ]]; then
|
||||
_pkg_list=(\
|
||||
"build-essential" \
|
||||
"libncurses5-dev" \
|
||||
"libncursesw5-dev" \
|
||||
"zlib1g-dev" \
|
||||
"gawk" \
|
||||
"git" \
|
||||
"gettext" \
|
||||
"libssl-dev" \
|
||||
"xsltproc" \
|
||||
"wget" \
|
||||
"unzip" \
|
||||
"python" \
|
||||
"axel" \
|
||||
;;
|
||||
debian|ubuntu)
|
||||
pkg_list+=(
|
||||
"build-essential"
|
||||
"clang"
|
||||
"flex"
|
||||
"g++"
|
||||
"gawk"
|
||||
"gcc-multilib"
|
||||
"gettext"
|
||||
"git"
|
||||
"libncurses5-dev"
|
||||
"libssl-dev"
|
||||
"python3-distutils"
|
||||
"rsync"
|
||||
"unzip"
|
||||
"zlib1g-dev"
|
||||
"file"
|
||||
"wget"
|
||||
)
|
||||
_pkg_cmd="apt-get"
|
||||
;;
|
||||
arch)
|
||||
pkg_list+=(
|
||||
"base-devel"
|
||||
"autoconf"
|
||||
"automake"
|
||||
"bash"
|
||||
"binutils"
|
||||
"bison"
|
||||
"bzip2"
|
||||
"fakeroot"
|
||||
"file"
|
||||
"findutils"
|
||||
"flex"
|
||||
"gawk"
|
||||
"gcc"
|
||||
"gettext"
|
||||
"git"
|
||||
"grep"
|
||||
"groff"
|
||||
"gzip"
|
||||
"libelf"
|
||||
"libtool"
|
||||
"libxslt"
|
||||
"m4"
|
||||
"make"
|
||||
"ncurses"
|
||||
"openssl"
|
||||
"patch"
|
||||
"pkgconf"
|
||||
"python"
|
||||
"rsync"
|
||||
"sed"
|
||||
"texinfo"
|
||||
"time"
|
||||
"unzip"
|
||||
"util-linux"
|
||||
"wget"
|
||||
"which"
|
||||
"zlib"
|
||||
)
|
||||
;;
|
||||
esac
|
||||
else
|
||||
# For Imagebuilder
|
||||
case "$ID" in
|
||||
fedora|centos)
|
||||
pkg_list+=(
|
||||
"@c-development"
|
||||
"@development-tools"
|
||||
"@development-libs"
|
||||
"perl-FindBin"
|
||||
"zlib-static"
|
||||
"elfutils-libelf-devel"
|
||||
"gawk"
|
||||
"unzip"
|
||||
"file"
|
||||
"wget"
|
||||
"python3"
|
||||
"python2"
|
||||
"axel"
|
||||
)
|
||||
;;
|
||||
debian|ubuntu)
|
||||
pkg_list+=(
|
||||
"build-essential"
|
||||
"libncurses5-dev"
|
||||
"libncursesw5-dev"
|
||||
"zlib1g-dev"
|
||||
"gawk"
|
||||
"git"
|
||||
"gettext"
|
||||
"libssl-dev"
|
||||
"xsltproc"
|
||||
"wget"
|
||||
"unzip"
|
||||
"python"
|
||||
"axel"
|
||||
)
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
debug "Installing dependencies"
|
||||
debug "sudo $_pkg_cmd -y install ${_pkg_list[*]}"
|
||||
if ! sudo "$_pkg_cmd" -y install "${_pkg_list[@]}" > /dev/null 2>&1; then
|
||||
echo "Warning: Problem installing dependencies"
|
||||
return 1
|
||||
fi
|
||||
pkg_install "${pkg_list[@]}"
|
||||
}
|
||||
|
||||
|
||||
getImageBuilder() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
|
||||
local _url _filename _dl_tool
|
||||
declare dl_tool
|
||||
|
||||
if [[ "${P_ARR[release]}" == "snapshot" ]]; then
|
||||
_filename="openwrt-imagebuilder-${P_ARR[target]//\//-}.Linux-x86_64.tar.xz"
|
||||
_url="https://downloads.openwrt.org/snapshots/targets/${P_ARR[target]}/$_filename"
|
||||
if [[ -f "${P_ARR[source_archive]}" ]]; then
|
||||
if askOk "Update ImageBuilder snapshot?"; then
|
||||
rm -f "${P_ARR[source_archive]}"
|
||||
if [[ -f "$IB_ARCHIVE" ]]; then
|
||||
echo "Image Builder $IB_ARCHIVE exists"
|
||||
if askOk "Redownload Image Builder archive?"; then
|
||||
rm -f "$IB_ARCHIVE"
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
else
|
||||
_filename="openwrt-imagebuilder-${P_ARR[release]}-${P_ARR[target]//\//-}.Linux-x86_64.tar.xz"
|
||||
_url="https://downloads.openwrt.org/releases/${P_ARR[release]}/targets/${P_ARR[target]}/$_filename"
|
||||
[[ -f "${P_ARR[source_archive]}" ]] && return 0 # Reuse existing ImageBuilders
|
||||
fi
|
||||
|
||||
# Make sources directory if it does not exist
|
||||
[[ ! -d "$BUILDDIR/sources" ]] && mkdir -p "$BUILDDIR/sources"
|
||||
|
||||
if hash axel &>/dev/null; then
|
||||
_dl_tool="axel"
|
||||
dl_tool="axel"
|
||||
elif hash curl &>/dev/null; then
|
||||
_dl_tool="curl"
|
||||
dl_tool="curl"
|
||||
else
|
||||
echo "Downloading the Image Builder requires axel or curl!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
#_dl_tool="curl" # TODO remove
|
||||
echo "Downloading Image Builder archive using $dl_tool"
|
||||
|
||||
echo "Downloading imagebuilder archive using $_dl_tool"
|
||||
|
||||
debug "$_dl_tool -o ${P_ARR[source_archive]} $_url"
|
||||
if ! "$_dl_tool" -o "${P_ARR[source_archive]}" "$_url"; then
|
||||
echo "Could not download imagebuilder archive"
|
||||
exit 1
|
||||
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 "${P_ARR[source_archive]}" ]]; then
|
||||
if [[ ! -f "$IB_ARCHIVE" ]]; then
|
||||
echo "Archive missing"
|
||||
exit 1
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "Extracting image archive"
|
||||
[[ ! -d "${P_ARR[source_dir]}" ]] && mkdir -p "${P_ARR[source_dir]}"
|
||||
debug "tar -xf ${P_ARR[source_archive]} -C ${P_ARR[source_dir]} --strip-components 1"
|
||||
if ! tar -xf "${P_ARR[source_archive]}" -C "${P_ARR[source_dir]}" --strip-components 1; then
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
echo "Extracting Image Builder archive"
|
||||
[[ ! -d "$BUILDDIR" ]] && mkdir -p "$BUILDDIR"
|
||||
debug "tar -xf $IB_ARCHIVE -C $BUILDDIR --strip-components 1"
|
||||
if ! tar -xf "$IB_ARCHIVE" -C "$BUILDDIR" --strip-components 1; then
|
||||
echo "Extraction failed"
|
||||
exit 1
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -216,10 +394,10 @@ addRepos() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
|
||||
if [[ -v P_ARR[repo] ]]; then
|
||||
if ! grep -q "${P_ARR[repo]}" "${P_ARR[source_dir]}/repositories.conf"; then
|
||||
echo "${P_ARR[repo]}" >> "${P_ARR[source_dir]}/repositories.conf"
|
||||
if ! grep -q "${P_ARR[repo]}" "$BUILDDIR/repositories.conf"; then
|
||||
echo "${P_ARR[repo]}" >> "$BUILDDIR/repositories.conf"
|
||||
fi
|
||||
sed -i '/option check_signature/d' "${P_ARR[source_dir]}/repositories.conf"
|
||||
sed -i '/option check_signature/d' "$BUILDDIR/repositories.conf"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -244,7 +422,8 @@ sshBackup() {
|
||||
|
||||
# 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 ! rsync -avz --remove-source-files \
|
||||
"$SSH_BACKUP_PATH":"/tmp/$_backup_fname" "$BUILDDIR/"; then
|
||||
echo "Could not copy SSH backup"
|
||||
exit 1
|
||||
fi
|
||||
@@ -264,24 +443,24 @@ makeImage() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
|
||||
# Reuse the existing output
|
||||
if [[ -d "${P_ARR[out_bin_dir]}" ]]; then
|
||||
if askOk "${P_ARR[out_bin_dir]} exists. Rebuild?"; then
|
||||
rm -rf "${P_ARR[out_bin_dir]}"
|
||||
if [[ -d "$THIS_BINDIR" ]]; then
|
||||
if askOk "$THIS_BINDIR exists. Rebuild?"; then
|
||||
rm -rf "$THIS_BINDIR"
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
[[ ! -d "${P_ARR[out_bin_dir]}" ]] && mkdir -p "${P_ARR[out_bin_dir]}"
|
||||
[[ -d "$BUILDDIR" ]] || mkdir -p "$BUILDDIR"
|
||||
|
||||
if ! make image \
|
||||
BIN_DIR="${P_ARR[out_bin_dir]}" \
|
||||
BIN_DIR="$THIS_BINDIR" \
|
||||
PROFILE="${P_ARR[profile]}" \
|
||||
PACKAGES="${P_ARR[packages]}" \
|
||||
FILES="$FILESDIR" \
|
||||
--directory="${P_ARR[source_dir]}" \
|
||||
--jobs=$(( $(nproc) - 1 )) \
|
||||
> make.log; then
|
||||
FILES="${FILESDIR}" \
|
||||
--directory="$BUILDDIR" \
|
||||
--jobs="$(nproc)" \
|
||||
> "$BUILDDIR/make.log"; then
|
||||
echo "Make image failed!"
|
||||
exit 1
|
||||
fi
|
||||
@@ -291,20 +470,20 @@ makeImage() {
|
||||
flashImage() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
|
||||
local _umount
|
||||
declare img img_gz partitions
|
||||
|
||||
if [[ ! -e "$FLASH_DEV" ]]; then
|
||||
echo "The device specified by --flash could not be found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# TODO Roughly chooses the correct image
|
||||
if [[ -f "${P_ARR[factory_img_gz]}" ]]; then
|
||||
img_gz="${P_ARR[factory_img_gz]}"
|
||||
img="${P_ARR[factory_img]}"
|
||||
elif [[ -f "${P_ARR[sysupgrade_img_gz]}" ]]; then
|
||||
img_gz="${P_ARR[sysupgrade_img_gz]}"
|
||||
img="${P_ARR[sysupgrade_img]}"
|
||||
# TODO Roughly choose the correct image
|
||||
if [[ -f "$FACTORYIMGGZ" ]]; then
|
||||
img_gz="$FACTORYIMGGZ"
|
||||
img="$FACTORYIMG"
|
||||
elif [[ -f "$SYSUPGRADEIMGGZ" ]]; then
|
||||
img_gz="$SYSUPGRADEIMGGZ"
|
||||
img="$SYSUPGRADEIMG"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
@@ -315,9 +494,9 @@ flashImage() {
|
||||
gunzip -qfk "$img_gz"
|
||||
|
||||
echo "Unmounting target device $FLASH_DEV partitions"
|
||||
_umount=( "$FLASH_DEV"?* )
|
||||
debug "umount ${_umount[*]}"
|
||||
sudo umount "${_umount[@]}"
|
||||
partitions=( "$FLASH_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
|
||||
@@ -333,46 +512,92 @@ flashImage() {
|
||||
sshUpgrade() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
|
||||
echo "Copying \"${P_ARR[sysupgrade_bin_gz]}\" to $SSH_UPGRADE_PATH/tmp/"
|
||||
debug "scp \"${P_ARR[sysupgrade_bin_gz]}\" \"$SSH_UPGRADE_PATH\":\"/tmp/${P_ARR[sysupgrade_bin_gz_fname]}\""
|
||||
# shellcheck disable=SC2140
|
||||
if ! scp "${P_ARR[sysupgrade_bin_gz]}" "$SSH_UPGRADE_PATH":"/tmp/${P_ARR[sysupgrade_bin_gz_fname]}"; 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"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Executing remote sysupgrade"
|
||||
debug "ssh \"$SSH_UPGRADE_PATH\" \"sysupgrade -F /tmp/${P_ARR[sysupgrade_bin_gz_fname]}\""
|
||||
debug "ssh \"$SSH_UPGRADE_PATH\" \"sysupgrade -F /tmp/$SYSUPGRADEIMGGZFNAME\""
|
||||
# shellcheck disable=SC2029
|
||||
ssh "$SSH_UPGRADE_PATH" "sysupgrade -F /tmp/${P_ARR[sysupgrade_bin_gz_fname]}"
|
||||
ssh "$SSH_UPGRADE_PATH" "sysupgrade -F /tmp/$SYSUPGRADEIMGGZFNAME"
|
||||
}
|
||||
|
||||
|
||||
debug() { (( DEBUG )) && echo "Running: $*"; }
|
||||
fromSource() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
|
||||
declare src_url="https://github.com/openwrt/openwrt.git"
|
||||
declare src_dir="$SRCDIR/openwrt"
|
||||
declare -a pkg_list
|
||||
|
||||
echo "Building from source is under development"
|
||||
|
||||
if [[ ! -d "$src_dir" ]]; then
|
||||
mkdir -p "$src_dir"
|
||||
git clone "$src_url" "$src_dir"
|
||||
fi
|
||||
|
||||
pushd "$src_dir" || return 1
|
||||
|
||||
if [[ ${P_ARR[release]} == "snapshot" ]]; then
|
||||
git checkout master
|
||||
else
|
||||
git checkout "v$RELEASE"
|
||||
fi
|
||||
|
||||
./scripts/feeds update -a
|
||||
./scripts/feeds install -a
|
||||
|
||||
# Grab the release config.seed
|
||||
k_options=$(curl -s "$SEED_URL")
|
||||
debug "$k_options"
|
||||
|
||||
|
||||
|
||||
make distclean
|
||||
make download
|
||||
make -j"$(nproc)" world
|
||||
|
||||
popd || return 1
|
||||
exit # TODO exit here for fromSource() testing
|
||||
}
|
||||
|
||||
|
||||
debug() { (( DEBUG )) && echo "Debug: $*"; }
|
||||
|
||||
|
||||
askOk() {
|
||||
local _response
|
||||
read -r -p "$* [y/N]" _response
|
||||
_response=${_response,,}
|
||||
[[ ! "$_response" =~ ^(yes|y)$ ]] && return 1
|
||||
return 0
|
||||
[[ "$_response" =~ ^(yes|y)$ ]]
|
||||
}
|
||||
|
||||
|
||||
reset() {
|
||||
resetAll() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
askOk "Remove $FILESDIR $BUILDDIR/sources $BUILDDIR/bin?" || exit $?
|
||||
debug "rm -rf $FILESDIR $BUILDDIR/sources $BUILDDIR/bin"
|
||||
rm -rf "$FILESDIR" "${BUILDDIR:?}/sources" "${BUILDDIR:?}/bin"
|
||||
askOk "Remove $SRCDIR and $BINDIR?" || exit $?
|
||||
debug "rm -rf $SRCDIR $BINDIR"
|
||||
rm -rf "$SRCDIR" "$BINDIR"
|
||||
}
|
||||
|
||||
|
||||
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 SCRIPTDIR PFILE
|
||||
declare -g PFILE
|
||||
# https://stackoverflow.com/a/4774063
|
||||
SCRIPTDIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit $? ; pwd -P )"
|
||||
PFILE="$SCRIPTDIR/profiles"
|
||||
# shellcheck source=./profiles
|
||||
! source "$PFILE" && echo "profiles file missing!" && return 1
|
||||
@@ -382,56 +607,106 @@ loadProfiles() {
|
||||
main() {
|
||||
debug "${FUNCNAME[0]}"
|
||||
|
||||
init
|
||||
|
||||
loadProfiles
|
||||
|
||||
readInput "$@"
|
||||
|
||||
[[ ! ${!PROFILE@a} = A ]] && echo "Profile does not exist" && return 1
|
||||
declare -gn P_ARR="$PROFILE"
|
||||
declare _out_prefix
|
||||
# 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
|
||||
|
||||
: "${BUILDDIR:=$SCRIPTDIR}"
|
||||
: "${FILESDIR:=$BUILDDIR/files}"
|
||||
for dir in "$SRCDIR" "$BINDIR"; do
|
||||
[[ -d "$dir" ]] || mkdir -p "$dir"
|
||||
done
|
||||
|
||||
: "${P_ARR[release]:=$RELEASE}"
|
||||
: "${P_ARR[source_archive]:=$BUILDDIR/sources/${P_ARR[profile]}-${P_ARR[release]}.tar.xz}"
|
||||
: "${P_ARR[source_dir]:=${P_ARR[source_archive]%.tar.xz}}"
|
||||
: "${P_ARR[out_bin_dir]:=$BUILDDIR/bin/${P_ARR[profile]}-${P_ARR[release]}}"
|
||||
|
||||
if [[ "${P_ARR[release]}" == "snapshot" ]]; then
|
||||
_out_prefix="${P_ARR[out_bin_dir]}/openwrt-${P_ARR[target]//\//-}-${P_ARR[profile]}"
|
||||
# Allow --reset without a profile
|
||||
if [[ ${#PROFILES} -lt 1 ]]; then
|
||||
if (( RESET )); then
|
||||
resetAll
|
||||
exit
|
||||
else
|
||||
_out_prefix="${P_ARR[out_bin_dir]}/openwrt-${P_ARR[release]}-${P_ARR[target]//\//-}-${P_ARR[profile]}"
|
||||
echo "No profile supplied" && return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
: "${P_ARR[factory_img]:=$_out_prefix-${P_ARR[filesystem]}-factory.img}"
|
||||
: "${P_ARR[factory_img_gz]:=${P_ARR[factory_img]}.gz}"
|
||||
: "${P_ARR[sysupgrade_img]:=$_out_prefix-${P_ARR[filesystem]}-sysupgrade.img}"
|
||||
: "${P_ARR[sysupgrade_img_gz]:=${P_ARR[sysupgrade_img]}.gz}"
|
||||
: "${P_ARR[sysupgrade_bin]:=$_out_prefix-${P_ARR[filesystem]}-sysupgrade.img}"
|
||||
: "${P_ARR[sysupgrade_bin_fname]:=${P_ARR[sysupgrade_bin]##*/}}"
|
||||
: "${P_ARR[sysupgrade_bin_gz]:=${P_ARR[sysupgrade_bin]}.gz}"
|
||||
: "${P_ARR[sysupgrade_bin_gz_fname]:=${P_ARR[sysupgrade_bin_gz]##*/}}"
|
||||
installDependencies
|
||||
|
||||
(( RESET )) && reset
|
||||
for profile in "${PROFILES[@]}"; do
|
||||
debug "Starting profile: $profile"
|
||||
|
||||
if [[ ! ${!profile@a} = A ]]; then
|
||||
echo "Profile '$profile' does not exist"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Store profile settings in P_ARR
|
||||
declare -gn P_ARR="$profile"
|
||||
|
||||
# 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 FILESYSTEM="${P_ARR[filesystem]:="squashfs"}"
|
||||
declare -g THIS_BINDIR="$BINDIR/${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"
|
||||
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"
|
||||
fi
|
||||
|
||||
declare -g IB_URL="$url_prefix/$url_filename"
|
||||
declare -g SHA256_URL="$url_prefix/sha256sums"
|
||||
declare -g SEED_URL="$url_prefix/config.buildinfo"
|
||||
|
||||
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 SYSUPGRADEIMGGZFNAME="${SYSUPGRADEIMGGZ##*/}"
|
||||
|
||||
if (( DEBUG )) || (( PROFILE_INFO )); then
|
||||
for x in "${!P_ARR[@]}"; do printf "[%s]=%s\n" "$x" "${P_ARR[$x]}"; done
|
||||
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
|
||||
EOF
|
||||
fi
|
||||
|
||||
installHostDependencies
|
||||
(( RESET )) && resetProfile
|
||||
|
||||
getImageBuilder
|
||||
(( FROM_SOURCE )) && fromSource
|
||||
|
||||
getImageBuilder || return $?
|
||||
addRepos
|
||||
|
||||
#copyFiles
|
||||
|
||||
[[ -v SSH_BACKUP_PATH ]] && sshBackup
|
||||
if makeImage; then
|
||||
[[ -v SSH_UPGRADE_PATH ]] && sshUpgrade
|
||||
[[ -v FLASH_DEV ]] && flashImage
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
3
profiles
3
profiles
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC2034
|
||||
# This file contains a set of device profiles for openwrtbuilder
|
||||
# bash doesn't like nested arrays so we use strings instead
|
||||
|
||||
# Packages to install for all profiles
|
||||
default_packages="\
|
||||
@@ -99,12 +100,12 @@ r4s['packages']="\
|
||||
usbutils \
|
||||
kmod-usb-storage \
|
||||
kmod-usb-storage-uas \
|
||||
kmod-fs-btrfs \
|
||||
btrfs-progs \
|
||||
block-mount \
|
||||
smcroute \
|
||||
curl \
|
||||
ethtool \
|
||||
kmod-tun \
|
||||
ca-bundle"
|
||||
|
||||
declare -Ag ax6000_stock
|
||||
|
||||
Reference in New Issue
Block a user