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