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