More multi-profile work

This commit is contained in:
2023-01-12 16:17:14 -05:00
parent 0bd32d5d7c
commit 3ee6de5fb1

View File

@@ -13,7 +13,7 @@ printHelp() {
debug "${FUNCNAME[0]}" debug "${FUNCNAME[0]}"
cat <<-'EOF' cat <<-'EOF'
Run and deploy OpenWRT images using the Image Builder. Create and deploy OpenWRT images using the Image Builder.
USAGE: USAGE:
openwrtbuilder [OPTION [VALUE]] -p PROFILE [-p PROFILE2]... openwrtbuilder [OPTION [VALUE]] -p PROFILE [-p PROFILE2]...
@@ -23,7 +23,7 @@ OPTIONS
--info, -i (print profile info) --info, -i (print profile info)
--list-profiles, -l --list-profiles, -l
--release, -r, --version, -v RELEASE_VERSION ("snapshot", "22.03.3", etc.) --release, -r, --version, -v RELEASE_VERSION ("snapshot", "22.03.3", etc.)
--builddir, -b PATH --buildroot, -b PATH
--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
@@ -46,7 +46,7 @@ readInput() {
declare -ga PROFILES declare -ga PROFILES
declare -g PROFILE_INFO declare -g PROFILE_INFO
if _input=$(getopt -o +r:v:p:i:lb:sf:dh -l release:,version:,profile:,info:,list-profiles,builddir:,from-source,ssh-upgrade:,ssh-backup:,flash:,reset,debug,help -- "$@"); then if _input=$(getopt -o +r:v:p:i:lb:sf:dh -l release:,version:,profile:,info:,list-profiles,buildroot:,from-source,ssh-upgrade:,ssh-backup:,flash:,reset,debug,help -- "$@"); then
eval set -- "$_input" eval set -- "$_input"
while true; do while true; do
case "$1" in case "$1" in
@@ -62,8 +62,8 @@ readInput() {
--list-profiles|-l) --list-profiles|-l)
listProfiles && exit $? listProfiles && exit $?
;; ;;
--builddir|-b) --buildroot|-b)
shift && BUILDDIR="$1" shift && BUILDROOT="$1"
;; ;;
--from-source|-s) --from-source|-s)
FROM_SOURCE=1 FROM_SOURCE=1
@@ -252,7 +252,7 @@ installDependencies() {
getImageBuilder() { getImageBuilder() {
debug "${FUNCNAME[0]}" debug "${FUNCNAME[0]}"
declare dl_tool sha256sum declare dl_tool
if [[ -f "${P_ARR[source_archive]}" ]]; then if [[ -f "${P_ARR[source_archive]}" ]]; then
if askOk "Update ImageBuilder ?"; then if askOk "Update ImageBuilder ?"; then
@@ -493,12 +493,11 @@ askOk() {
resetAll() { resetAll() {
debug "${FUNCNAME[0]}" debug "${FUNCNAME[0]}"
# BUILDDIR may not be set, so fallback to SCRIPTDIR askOk "Remove ${BUILDROOT}/sources and ${BUILDROOT}/bin?" || exit $?
askOk "Remove ${BUILDDIR}/sources and ${BUILDDIR}/bin?" || exit $? debug "rm -rf ${BUILDROOT}/sources ${BUILDROOT}/bin"
debug "rm -rf ${BUILDDIR}/sources ${BUILDDIR}/bin" find "${BUILDROOT}/sources" "${BUILDROOT}/bin" \
find "${BUILDDIR}/sources" "${BUILDDIR}/bin" \
! -dir "$FILESDIR" -type f -delete + ! -dir "$FILESDIR" -type f -delete +
#rm -rf "${BUILDDIR}/sources" "${BUILDDIR}/bin" #rm -rf "${BUILDROOT}/sources" "${BUILDROOT}/bin"
} }
@@ -602,10 +601,6 @@ init() {
main() { main() {
debug "${FUNCNAME[0]}" debug "${FUNCNAME[0]}"
# Use openwrtbuilder directory as fallback if BUILDDIR cannot be determined
declare -g SCRIPTDIR
SCRIPTDIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit $? ; pwd -P )"
init init
loadProfiles loadProfiles
@@ -630,44 +625,42 @@ main() {
[[ ! ${!profile@a} = A ]] && echo "Profile does not exist" && return 1 [[ ! ${!profile@a} = A ]] && echo "Profile does not exist" && return 1
# Set profile vars in the P_ARR array
declare -gn P_ARR="$profile" declare -gn P_ARR="$profile"
# Fallback to SCRIPTDIR if BUILDDIR has not been set # Fallback to SCRIPTDIR if BUILDROOT has not been set
BUILDDIR="${BUILDDIR:=$SCRIPTDIR}" SCRIPTDIR="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit $? ; pwd -P)"
FILESDIR="${FILESDIR:=$BUILDDIR/files}" BUILDROOT="${BUILDROOT:=$SCRIPTDIR}"
FILESDIR="${FILESDIR:=$BUILDROOT/files}"
P_ARR[release]=${USER_RELEASE:=${P_ARR[release]}:=$RELEASE} # precedence: user input>profile>env>hardcode # precedence: user input>profile>env>hardcode
P_ARR[source_archive]=${P_ARR[build_dir]}/sources/${P_ARR[profile]}-${P_ARR[release]}.tar.xz P_ARR[release]="${USER_RELEASE:=${P_ARR[release]}:=$RELEASE}"
P_ARR[source_dir]=${P_ARR[source_archive]%.tar.xz} P_ARR[build_dir]="$BUILDROOT/$profile/${P_ARR[release]}"
P_ARR[bin_dir]=${P_ARR[build_dir]}/bin/${P_ARR[profile]}-${P_ARR[release]} P_ARR[source_dir]="${P_ARR[build_root]}/sources"
P_ARR[source_archive]="${P_ARR[source_dir]}/${P_ARR[profile]}-${P_ARR[release]}.tar.xz"
P_ARR[bin_dir]="${P_ARR[build_dir]}/bin"
if [[ "${P_ARR[release]}" == "snapshot" ]]; then if [[ "${P_ARR[release]}" == "snapshot" ]]; then
P_ARR[OUT_PREFIX]="${P_ARR[bin_dir]}/openwrt-${P_ARR[target]//\//-}-${P_ARR[profile]}" P_ARR[OUT_PREFIX]="${P_ARR[bin_dir]}/openwrt-${P_ARR[target]//\//-}-${P_ARR[profile]}"
else
P_ARR[OUT_PREFIX]="${P_ARR[bin_dir]}/openwrt-${P_ARR[release]}-${P_ARR[target]//\//-}-${P_ARR[profile]}"
fi
P_ARR[factory_img]=${P_ARR[OUT_PREFIX]}-${P_ARR[filesystem]}-factory.img
P_ARR[factory_img_gz]=${P_ARR[factory_img]}.gz
P_ARR[sysupgrade_img]=${P_ARR[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]##*/}
P_ARR[build_dir]="${BUILDDIR}"
if [[ "${P_ARR[release]}" == "snapshot" ]]; then
P_ARR[URL_PREFIX]="https://downloads.openwrt.org/snapshots/targets/${P_ARR[target]}" P_ARR[URL_PREFIX]="https://downloads.openwrt.org/snapshots/targets/${P_ARR[target]}"
P_ARR[FILENAME]="openwrt-imagebuilder-${P_ARR[target]//\//-}.Linux-x86_64.tar.xz" P_ARR[FILENAME]="openwrt-imagebuilder-${P_ARR[target]//\//-}.Linux-x86_64.tar.xz"
P_ARR[IB_URL]="${URL_PREFIX}/$FILENAME" P_ARR[IB_URL]="${P_ARR[URL_PREFIX]}/${P_ARR[FILENAME]}"
else else
P_ARR[OUT_PREFIX]="${P_ARR[bin_dir]}/openwrt-${P_ARR[release]}-${P_ARR[target]//\//-}-${P_ARR[profile]}"
P_ARR[URL_PREFIX]="https://downloads.openwrt.org/releases/${P_ARR[release]}/targets/${P_ARR[target]}" P_ARR[URL_PREFIX]="https://downloads.openwrt.org/releases/${P_ARR[release]}/targets/${P_ARR[target]}"
P_ARR[FILENAME]="openwrt-imagebuilder-${P_ARR[release]}-${P_ARR[target]//\//-}.Linux-x86_64.tar.xz" P_ARR[FILENAME]="openwrt-imagebuilder-${P_ARR[release]}-${P_ARR[target]//\//-}.Linux-x86_64.tar.xz"
P_ARR[IB_URL]="${URL_PREFIX}/$FILENAME" P_ARR[IB_URL]="${P_ARR[URL_PREFIX]}/${P_ARR[FILENAME]}"
fi fi
P_ARR[factory_img]="${P_ARR[OUT_PREFIX]}-${P_ARR[filesystem]}-factory.img"
P_ARR[factory_img_gz]="${P_ARR[factory_img]}.gz"
P_ARR[sysupgrade_img]="${P_ARR[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]##*/}"
P_ARR[SHA256_URL]="${P_ARR[URL_PREFIX]}/sha256sums" P_ARR[SHA256_URL]="${P_ARR[URL_PREFIX]}/sha256sums"
P_ARR[CONFIG_SEED]="${P_ARR[URL_PREFIX]}" P_ARR[CONFIG_SEED]="${P_ARR[URL_PREFIX]}"