xref: /freebsd/usr.sbin/bsdinstall/startbsdinstall (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
1#!/bin/sh
2
3BSDCFG_SHARE="/usr/share/bsdconfig"
4. $BSDCFG_SHARE/common.subr || exit 1
5
6: ${BSDDIALOG_OK=0}
7: ${BSDDIALOG_CANCEL=1}
8: ${BSDDIALOG_HELP=2}
9: ${BSDDIALOG_EXTRA=3}
10: ${BSDDIALOG_ESC=5}
11: ${BSDDIALOG_ERROR=255}
12
13kbdcontrol -d >/dev/null 2>&1
14if [ $? -eq 0 ]; then
15	# Syscons: use xterm, start interesting things on other VTYs
16	TERM=xterm
17
18	# Don't send ESC on function-key 62/63 (left/right command key)
19	kbdcontrol -f 62 '' > /dev/null 2>&1
20	kbdcontrol -f 63 '' > /dev/null 2>&1
21
22	if [ -z "$EXTERNAL_VTY_STARTED" ]; then
23		# Init will clean these processes up if/when the system
24		# goes multiuser
25		touch /tmp/bsdinstall_log
26		tail -f /tmp/bsdinstall_log > /dev/ttyv2 &
27		/usr/libexec/getty autologin ttyv3 &
28		EXTERNAL_VTY_STARTED=1
29	fi
30else
31	# Serial or other console
32	echo
33	echo "Welcome to ${OSNAME}!"
34	echo
35	echo "Please choose the appropriate terminal type for your system."
36	echo "Common console types are:"
37	echo "   ansi     Standard ANSI terminal"
38	echo "   vt100    VT100 or compatible terminal"
39	echo "   xterm    xterm terminal emulator (or compatible)"
40	echo
41	echo -n "Console type [vt100]: "
42	read TERM
43	TERM=${TERM:-vt100}
44fi
45export TERM
46
47# Query terminal size; useful for serial lines.
48resizewin -z
49
50if [ -f /etc/installerconfig ]; then
51	if [ "$1" != "primary" ]; then
52		bsddialog --backtitle "${OSNAME} Installer" --title "Installing" --msgbox "${OSNAME} is being installed from a script; please use the primary console." 0 0
53		. "$0"
54	elif bsdinstall script /etc/installerconfig; then
55		bsddialog --backtitle "${OSNAME} Installer" --title "Complete" --no-cancel --ok-label "Reboot" --pause "Installation of ${OSNAME} complete! Rebooting in 10 seconds" 10 30 10
56		reboot
57	else
58		bsddialog --backtitle "${OSNAME} Installer" --title "Error" --textbox /tmp/bsdinstall_log 0 0
59	fi
60	exit
61fi
62
63bsddialog --backtitle "${OSNAME} Installer" --title "Welcome" --extra-button --extra-label "Shell" --ok-label "Install" --cancel-label "Live System" --yesno "Welcome to ${OSNAME}! Would you like to begin an installation or use the live system?" 0 0
64
65case $? in
66$BSDDIALOG_OK)	# Install
67	# If not netbooting, have the installer configure the network
68	dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
69	if [ ${dlv:=0} -eq 0 -a ! -f /etc/diskless ]; then
70		BSDINSTALL_CONFIGCURRENT=yes; export BSDINSTALL_CONFIGCURRENT
71	fi
72
73	trap true SIGINT	# Ignore cntrl-C here
74	bsdinstall
75	if [ $? -eq 0 ]; then
76		bsddialog --backtitle "${OSNAME} Installer" --title "Complete" --ok-label "Reboot" --extra-button --extra-label "Shutdown" --cancel-label "Live System" --yesno "Installation of ${OSNAME} complete! Would you like to reboot into the installed system now?" 0 0
77
78		case $? in
79		$BSDDIALOG_OK)		# Reboot
80			reboot
81			;;
82		$BSDDIALOG_EXTRA)	# Shutdown
83			shutdown -p now
84			# shutdown(8) daemonizes, with the actual signal to
85			# init(8) happening in the child, but if we exit the
86			# script then runconsoles will clean up its children
87			# thinking we're trying to go multiuser (and if the
88			# user has disabled multiple console support we'll
89			# still start trying to go multi-user, which gives
90			# confusing output on the console if the daemon is slow
91			# to run). Thus we spin while the daemon runs.
92			while true; do
93				sleep 1
94			done
95			;;
96		$BSDDIALOG_CANCEL)	# Live System
97			exit 0
98			;;
99		esac
100	else
101		. "$0"
102	fi
103	;;
104$BSDDIALOG_CANCEL)	# Live System
105	exit 0
106	;;
107$BSDDIALOG_EXTRA)	# Shell
108	clear
109	echo "When finished, type 'exit' to return to the installer."
110	/bin/sh
111	. "$0"
112	;;
113esac
114
115