summaryrefslogtreecommitdiffstats
path: root/src/action/update.sh
blob: 3d897bcfb28503752697568be610bb9ea62100fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Firmware update action
#
# Copyright (C) 2015  Patrick "P. J." McDermott
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# 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()
{
	local dists=''
	local i=0
	local dist=''
	local mirror_url=''
	local mirror_label=''
	local mirror_urls=''

	info 'Updating firmware'

	# Probe for board and chip.
	if ! flashrom_probe; then
		return 1
	fi

	# Select distributor.
	# TODO: Show names in menu labels.
	dists="$(board_get_dists)"
	if [ $(printf '%s' "${dists}" | wc -w | cut -d ' ' -f 1) -gt 1 ]; then
		i=$(show_menu 'Select a firmware distributor' ${dists})
		i=$(($i + 1))
		dist="$(printf '%s ' ${dists} | cut -d ' ' -f ${i})"
	else
		dist="$(printf '%s' ${dists})"
	fi
	select_dist "${dist}"
	info 'Distributor: %s' "${dist}"

	# Select mirror.
	# TODO: Handle show_menu() output.
	set --
	while :; do
		if ! read -r mirror_url || ! read -r mirror_label; then
			break
		fi
		mirror_urls="${mirror_urls} ${mirror_url}"
		set -- "${@}" "${mirror_label}"
	done <<-EOF
		$(dist_get_mirrors)
		EOF
	i=$(show_menu 'Select a mirror' "${@}")
	i=$(($i + 1))
	mirror_url="$(printf '%s ' ${mirror_urls} | cut -d ' ' -f ${i})"
	info 'Mirror: %s' "${mirror_url}"

	return 0
}