First stab at multi-profile support

This commit is contained in:
2023-01-11 14:25:52 -05:00
parent 724755d762
commit b9848a177a

View File

@@ -16,11 +16,11 @@ printHelp() {
Run and deploy OpenWRT images using the Image Builder. Run and deploy OpenWRT images using the Image Builder.
USAGE: USAGE:
openwrtbuilder [OPTION [VALUE]]... openwrtbuilder [OPTION [VALUE]] -p PROFILE [-p PROFILE2]...
OPTIONS OPTIONS
--profile, -p PROFILE --profile, -p PROFILE
--info, -i PROFILE --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 --builddir, -b PATH
@@ -43,6 +43,9 @@ readInput() {
unset RESET unset RESET
declare -ga PROFILES
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,builddir:,from-source,ssh-upgrade:,ssh-backup:,flash:,reset,debug,help -- "$@"); then
eval set -- "$_input" eval set -- "$_input"
while true; do while true; do
@@ -51,10 +54,10 @@ readInput() {
shift && RELEASE="$1" shift && RELEASE="$1"
;; ;;
--profile|-p) --profile|-p)
shift && PROFILE="$1" shift && PROFILES+=("$1")
;; ;;
--info|-i) --info|-i)
shift && PROFILE="$1" && PROFILE_INFO=1 && exit $? PROFILE_INFO=1
;; ;;
--list-profiles|-l) --list-profiles|-l)
listProfiles && exit $? listProfiles && exit $?
@@ -458,7 +461,6 @@ fromSource() {
echo "Building from source is under development" echo "Building from source is under development"
git clone --depth=1 "$src_url" "$BUILDDIR/sources" git clone --depth=1 "$src_url" "$BUILDDIR/sources"
pushd "$BUILDDIR/sources/$(basename "$src_url" .git)" || return 1 pushd "$BUILDDIR/sources/$(basename "$src_url" .git)" || return 1
@@ -599,9 +601,16 @@ main() {
readInput "$@" readInput "$@"
[[ ${#PROFILE} -lt 1 ]] && echo "No profile supplied" && return 1 (( RESET )) && reset
[[ ! ${!PROFILE@a} = A ]] && echo "Profile does not exist" && return 1
declare -gn P_ARR="$PROFILE" [[ ${#PROFILES} -lt 1 ]] && echo "No profile supplied" && return 1
installDependencies
for profile in "${PROFILES[@]}"; do
[[ ! ${!profile@a} = A ]] && echo "Profile does not exist" && return 1
declare -gn P_ARR="$profile"
: "${BUILDDIR:=$SCRIPTDIR}" : "${BUILDDIR:=$SCRIPTDIR}"
: "${FILESDIR:=$BUILDDIR/files}" : "${FILESDIR:=$BUILDDIR/files}"
@@ -627,14 +636,10 @@ main() {
: "${P_ARR[sysupgrade_bin_gz]:=${P_ARR[sysupgrade_bin]}.gz}" : "${P_ARR[sysupgrade_bin_gz]:=${P_ARR[sysupgrade_bin]}.gz}"
: "${P_ARR[sysupgrade_bin_gz_fname]:=${P_ARR[sysupgrade_bin_gz]##*/}}" : "${P_ARR[sysupgrade_bin_gz_fname]:=${P_ARR[sysupgrade_bin_gz]##*/}}"
(( RESET )) && reset
if (( DEBUG )) || (( PROFILE_INFO )); then if (( DEBUG )) || (( PROFILE_INFO )); then
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
fi fi
installDependencies
# Experimental # Experimental
(( FROM_SOURCE )) && fromSource (( FROM_SOURCE )) && fromSource
@@ -649,6 +654,7 @@ main() {
[[ -v SSH_UPGRADE_PATH ]] && sshUpgrade [[ -v SSH_UPGRADE_PATH ]] && sshUpgrade
[[ -v FLASH_DEV ]] && flashImage [[ -v FLASH_DEV ]] && flashImage
fi fi
done
} }
main "$@" main "$@"