From 0a94d7cce10277b285beacf2d2a0a88ef1f501ea Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Wed, 28 Oct 2015 09:05:27 -0400 Subject: do_update(): Split into multiple functions Reduce the size of do_update() to make it less of a mess in preparation for more code. --- (limited to 'src/action') diff --git a/src/action/update.sh b/src/action/update.sh index cf437b6..cc3293f 100644 --- a/src/action/update.sh +++ b/src/action/update.sh @@ -15,25 +15,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -do_update() +get_dist() { local dist_ids='' local i=0 local dist='' - local mirror_url='' - local mirror_label='' - local mirror_urls='' - local versions='' - local version='' - - info 'Updating firmware' - - # Probe for board and chip. - if ! flashrom_probe; then - return 1 - fi - # Select distributor. dist_ids="$(board_get_dists)" if [ $(printf '%s' "${dist_ids}" | wc -w | cut -d ' ' -f 1) -gt 1 ]; then set -- @@ -47,9 +34,19 @@ do_update() dist="$(printf '%s' ${dist_ids})" fi select_dist "${dist}" + info 'Distributor: %s' "${dist}" - # Select mirror. + return 0 +} + +get_mirror() +{ + local mirror_url='' + local mirror_label='' + local mirror_urls='' + local i=0 + set -- while :; do if ! read -r mirror_url || ! read -r mirror_label; then @@ -63,14 +60,47 @@ do_update() i=$(show_menu 'Select a mirror' "${@}") i=$(($i + 1)) mirror_url="$(printf '%s ' ${mirror_urls} | cut -d ' ' -f ${i})" + info 'Mirror: %s' "${mirror_url}" - # Select version. - versions="$(dist_get_versions "${mirror_url}" "$(board_get)")" + printf '%s' "${mirror_url}" + return 0 +} + +get_version() +{ + local mirror="${1}" + shift 1 + local versions='' + local i=0 + local version='' + + versions="$(dist_get_versions "${mirror}" "$(board_get)")" i=$(show_menu 'Select a version' ${versions}) i=$(($i + 1)) version="$(printf '%s ' ${versions} | cut -d ' ' -f ${i})" + info 'Version: %s' "${version}" + printf '%s' "${version}" + return 0 +} + +do_update() +{ + local mirror='' + local version='' + + info 'Updating firmware' + + # Probe for board and chip. + if ! flashrom_probe; then + return 1 + fi + + get_dist + mirror="$(get_mirror)" + version="$(get_version "${mirror}")" + return 0 } -- cgit v0.9.1