aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/bsdinstall/scripts/firmware
blob: 0fc66f0a02619a6c37d702285f07929aeb1b2581 (plain) (blame)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/sh
#-
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c) 2024 The FreeBSD Foundation
#
# This software was developed by Björn Zeeb
# under sponsorship from the FreeBSD Foundation.
#

BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1

f_dprintf "%s: loading includes..." "$0"
f_include $BSDCFG_SHARE/dialog.subr
f_include $BSDCFG_SHARE/mustberoot.subr
f_include $BSDCFG_SHARE/packages/packages.subr

msg_freebsd_firmware_installation="$OSNAME Firmware Installation"
msg_freebsd_installer="$OSNAME Installer"
msg_firmware_menu_text="This menu allows you to install firmware packages for your system"
hline_arrows_space_tab_enter="Use arrows, SPACE, TAB or ENTER"
hline_ok="Press OK to continue"

dialog_menu_main()
{
	local title="$DIALOG_TITLE"
	local btitle="$DIALOG_BACKTITLE"
	local prompt="$msg_firmware_menu_text"
	local hline
	local check_list=	# Empty; filled below
	local fwlist _fw

	fwlist=`chroot $BSDINSTALL_CHROOT fwget -q -n`
	case "${fwlist}" in
	"")	# No firmware to install
		# Print a dialog with OK and a 3 line timeout bar.
		local height width rows msg

		msg="No firmware to install, continuing..."
		hline="$hline_ok"

		eval f_dialog_checklist_size height width rows \
			\"\$title\"  \
			\"\$btitle\" \
			\"\$msg\" \
			\"-\"  \
			\"n\"  \
			\"-\" \
			\"\$hline\"

		${DIALOG} --title "${title}" --backtitle "${btitle}" \
		    --hline "${hline}" \
		    --nocancel --pause "${msg}" $height $width 5
		f_dialog_menutag_store -s ""
		return $DIALOG_OK
		;;
	*)
		local desc status height width rows selected retval
		hline="$hline_arrows_space_tab_enter"

		for _fw in ${fwlist}; do
			desc="${_fw}"
			f_shell_escape "$desc" desc
			# install each firmware package by default.
			check_list="$check_list
				'$_fw' '$desc' 'on'
			"
		done

		eval f_dialog_checklist_size height width rows \
			\"\$title\"  \
			\"\$btitle\" \
			\"\$prompt\" \
			\"\$hline\"  \
			$check_list

		selected=$( eval $DIALOG		\
			--title \"\$title\"		\
			--backtitle \"\$btitle\"	\
			--separate-output		\
			--hline \"\$hline\"		\
			--ok-label \"\$msg_ok\"		\
			--cancel-label \"\$msg_cancel\"	\
			--checklist \"\$prompt\"	\
			$height $width $rows		\
			$check_list			\
			2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
		)
		retval=$?
		f_dialog_menutag_store -s "$selected"
		return $retval
		;;
	esac
}

# Initialize
f_dialog_title "$msg_freebsd_firmware_installation"
f_dialog_backtitle "$msg_freebsd_installer"

# Gather the firmware files and present them to the user
dialog_menu_main || f_die
f_dialog_menutag_fetch selected

# Nothing to install?
if [ "${selected}" == "" ]; then
	exit 0
fi

f_mustberoot_init

# pkg(8) needs name servers (unless we could use a local repo in the future).
f_quietly cp -f $BSDINSTALL_TMPETC/resolv.conf $BSDINSTALL_CHROOT/etc/

${DIALOG} --title "$DIALOG_TITLE" --backtitle "$DIALOG_BACKTITLE" \
	--infobox "Installing firmware. This may take a moment." 0 0

pkg_install_fail=
# Install each of the selected firmware packages
for fw in ${selected}; do
	# We install one at a time in case one is not avail.
	# pkg-install.8 needs an option to skip unavail.
	ASSUME_ALWAYS_YES=YES chroot $BSDINSTALL_CHROOT pkg install -qy ${fw}
	if [ $? -ne 0 ]; then
		pkg_install_fail="$pkg_install_fail $fw"
	fi
done
if [ -n "$pkg_install_fail" ]; then
	# Error(s) were likely spammed to the console; give the user a moment
	# to read them.
	sleep 5
	bsddialog --backtitle "$OSNAME Installer" --title "Error" \
	    --msgbox "Error fetching firmware file(s)$pkg_install_fail" 0 0
		exit 1
fi

# end