From 91e181d64c047ac3e8b2f7efc344ae2b73bb2d43 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Fri, 30 Oct 2015 16:41:44 -0400 Subject: src/action/update.sh: Add more error handling --- diff --git a/src/action/update.sh b/src/action/update.sh index e119c50..477300f 100644 --- a/src/action/update.sh +++ b/src/action/update.sh @@ -22,12 +22,15 @@ get_dist() local dist='' dist_ids="$(board_get_dists)" - if [ $(printf '%s' "${dist_ids}" | wc -w | cut -d ' ' -f 1) -gt 1 ]; then + if [ $(printf '%s' "${dist_ids}" | wc -w | cut -d ' ' -f 1) -gt 1 ] + then set -- for dist_id in ${dist_ids}; do set -- "${@}" "$(dist_get_name "${dist_id}")" done - i=$(show_menu 'Select a firmware distributor' "${@}") + if ! i=$(show_menu 'Select a firmware distributor' "${@}"); then + return 1 + fi i=$(($i + 1)) dist="$(printf '%s ' ${dist_ids} | cut -d ' ' -f ${i})" else @@ -57,7 +60,9 @@ get_mirror() done <<-EOF $(dist_get_mirrors) EOF - i=$(show_menu 'Select a mirror' "${@}") + if ! i=$(show_menu 'Select a mirror' "${@}"); then + return 1 + fi i=$(($i + 1)) mirror_url="$(printf '%s ' ${mirror_urls} | cut -d ' ' -f ${i})" @@ -75,8 +80,12 @@ get_version() local i=0 local version='' - versions="$(dist_get_versions "${mirror}" "$(board_get)")" - i=$(show_menu 'Select a version' ${versions}) + if ! versions="$(dist_get_versions "${mirror}" "$(board_get)")"; then + return 1 + fi + if ! i=$(show_menu 'Select a version' ${versions}); then + return 1 + fi i=$(($i + 1)) version="$(printf '%s ' ${versions} | cut -d ' ' -f ${i})" @@ -100,19 +109,32 @@ do_update() fi # Select firmware distributor, mirror, and version. - get_dist - mirror="$(get_mirror)" - version="$(get_version "${mirror}")" + if ! get_dist; then + return 1 + fi + if ! mirror="$(get_mirror)"; then + return 1 + fi + if ! version="$(get_version "${mirror}")"; then + return 1 + fi # Get and prepare a ROM. - dist_get_rom "${mirror}" "${version}" "$(board_get_id)" - board_prepare_rom + if ! dist_get_rom "${mirror}" "${version}" "$(board_get_id)"; then + return 1 + fi + if ! board_prepare_rom; then + rm_temp 'rom' + return 1 + fi # Write the ROM to flash. info 'Installing new firmware...' if flashrom_write "$(board_get_chip)"; then info 'Firmware installation complete' sleep 5 + rm_temp 'rom' + return 1 fi # Clean up the ROM. -- cgit v0.9.1