diff options
author | P. J. McDermott <pj@pehjota.net> | 2015-10-30 16:41:44 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2015-10-30 16:41:44 (EDT) |
commit | 91e181d64c047ac3e8b2f7efc344ae2b73bb2d43 (patch) | |
tree | dc8467e3a72306fdcceb7c390762302147dce6b1 | |
parent | 717e6191911c1cbec9acf889d36a4a1c53f1ad60 (diff) | |
download | firman.sh-91e181d64c047ac3e8b2f7efc344ae2b73bb2d43.zip firman.sh-91e181d64c047ac3e8b2f7efc344ae2b73bb2d43.tar.gz firman.sh-91e181d64c047ac3e8b2f7efc344ae2b73bb2d43.tar.bz2 |
src/action/update.sh: Add more error handling
-rw-r--r-- | src/action/update.sh | 42 |
1 files changed, 32 insertions, 10 deletions
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. |