summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2015-10-28 09:05:27 (EDT)
committer P. J. McDermott <pj@pehjota.net>2015-10-28 09:08:12 (EDT)
commit0a94d7cce10277b285beacf2d2a0a88ef1f501ea (patch)
tree5ac4032821d3bffaf37e0e6c8ae2119e35068797 /src
parent7dbf911a52b83e8afbc4c6358cfaf6492dd16630 (diff)
downloadfirman.sh-0a94d7cce10277b285beacf2d2a0a88ef1f501ea.zip
firman.sh-0a94d7cce10277b285beacf2d2a0a88ef1f501ea.tar.gz
firman.sh-0a94d7cce10277b285beacf2d2a0a88ef1f501ea.tar.bz2
do_update(): Split into multiple functions
Reduce the size of do_update() to make it less of a mess in preparation for more code.
Diffstat (limited to 'src')
-rw-r--r--src/action/update.sh64
1 files changed, 47 insertions, 17 deletions
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 <http://www.gnu.org/licenses/>.
-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
}