xref: /dragonfly/nrelease/root/etc/rc.d/pfi (revision 6e278935)
1#!/bin/sh
2
3# $Id: pfi,v 1.12 2005/03/07 06:18:21 cpressey Exp $
4# $DragonFly: src/nrelease/installer/etc/rc.d/pfi,v 1.8 2005/12/10 00:11:08 swildner Exp $
5#
6
7# PROVIDE: pfi
8# REQUIRE: mountoptional
9
10. /etc/rc.subr
11
12name=pfi
13start_cmd="pfi_start"
14stop_cmd=":"
15
16get_pfi_config()
17{
18	[ -r /etc/pfi.conf ] && return 0
19
20	if [ -r $1/pfi.conf ]; then
21		echo " found!"
22		tr -d "\r" < $1/pfi.conf > /etc/pfi.conf
23		echo "pfi_found_on_device='$2'" >> /etc/pfi.conf
24
25		# If the pfi.conf says to run a custom script from the pfi
26		# media, run it now, so that it has access to the pfi media.
27
28		if [ -r /etc/defaults/pfi.conf ]; then
29			. /etc/defaults/pfi.conf
30		fi
31		. /etc/pfi.conf
32		if [ "$pfi_script" != "" -a -x "$1/$pfi_script" ]; then
33			$1/$pfi_script
34		fi
35		return 0
36	else
37		return 1
38	fi
39}
40
41get_authorized_hosts()
42{
43	[ -r /root/.ssh/authorized_hosts ] && return 0
44	if [ -r $1/authorized_hosts ]; then
45		echo "authorized_hosts found!"
46		mkdir -p /root/.ssh/
47		tr -d "\r" < $1/authorized_hosts > /root/.ssh/authorized_hosts
48	fi
49}
50
51look_for_pfi_config_msdos()
52{
53	[ -r /etc/pfi.conf ] && return 0
54
55	for try_device in da0s1 da1s1 da8s1 fd0 fd1; do
56		if [ -c /dev/${try_device} ]; then
57			echo -n "Looking for pfi.conf on /dev/${try_device}..."
58			if mount_msdos -o rdonly /dev/$try_device /mnt ; then
59				echo -n " /dev/$try_device ok..."
60				if get_pfi_config /mnt /dev/$try_device; then
61					get_authorized_hosts /mnt
62					umount /mnt
63					return 0
64				fi
65				umount /mnt
66			fi
67			echo " not found"
68		fi
69	done
70	return 1
71}
72
73look_for_pfi_config_cd9660()
74{
75	[ -r /etc/pfi.conf ] && return 0
76
77	for try_device in acd0 cd0 acd1 cd1; do
78		if [ -c /dev/${try_device} ]; then
79			echo -n "Looking for pfi.conf on /dev/${try_device}..."
80			if mount_cd9660 /dev/$try_device /mnt ; then
81				echo -n " /dev/$try_device ok..."
82				if get_pfi_config /mnt /dev/$try_device; then
83					get_authorized_hosts /mnt
84					umount /mnt
85					return 0
86				fi
87				umount /mnt
88			fi
89			echo " not found"
90		fi
91	done
92	return 1
93}
94
95pfi_start()
96{
97	echo "Starting pfi..."
98
99	# Get the pfi.conf file off the pfi media and into /etc/pfi.conf.
100
101	look_for_pfi_config_cd9660
102	look_for_pfi_config_msdos
103
104	# If the search was not successful, stub out a dummy pfi.conf.
105
106	if [ ! -r /etc/pfi.conf ]; then
107		echo '' >/etc/pfi.conf
108	fi
109
110	# Append the contents of pfi.conf onto rc.conf, so that settings
111	# (such as ifconfig_dc0="DHCP") will be picked up by pfi_rc_actions.
112
113	cp /etc/rc.conf /etc/rc.conf.orig
114	cat /etc/pfi.conf >>/etc/rc.conf
115
116	# Read in the pfi.conf we either found or created for ourselves.
117
118	if [ -r /etc/defaults/pfi.conf ]; then
119		. /etc/defaults/pfi.conf
120	fi
121	. /etc/pfi.conf
122
123	# We can perform any pre-install tasks here by
124	# examining the contents of pfi_* variables.
125
126	# Interpret pfi_sshd_* options.  These basically add settings
127	# to /etc/ssh/sshd_config; it is assumed "sshd" will appear
128	# in pfi_rc_actions to restart sshd.
129
130	case ${pfi_sshd_permit_root_login} in
131	YES)
132		echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
133		;;
134	without-password)
135		echo "PermitRootLogin without-password" >> /etc/ssh/sshd_config
136		;;
137	forced-commands-only)
138		echo "PermitRootLogin forced-commands-only" >> /etc/ssh/sshd_config
139		;;
140	*)
141		;;
142	esac
143
144	case ${pfi_sshd_permit_empty_passwords} in
145	YES)
146		echo "PermitEmptyPasswords yes" >> /etc/ssh/sshd_config
147		;;
148	*)
149		;;
150	esac
151
152	# Interpret pfi_set_root_password.  If it is not empty, use
153	# it to set root's LiveCD password.
154
155	if [ "X$pfi_set_root_password" != "X" ]; then
156		echo "$pfi_set_root_password" | \
157		    /usr/sbin/pw usermod root -h 0
158	fi
159
160	# The most important pre-install task is to restart
161	# any RCNG scripts listed in pfi_rc_actions with any new
162	# settings that might have been set up by pfi.conf.
163
164	if [ "X$pfi_rc_actions" != "X" ]; then
165		rev_actions=`reverse_list $pfi_rc_actions`
166
167		for _rc_elem in ${rev_actions}; do
168			echo "Stopping ${_rc_elem}..."
169			rcstop ${_rc_elem}
170		done
171		for _rc_elem in ${pfi_rc_actions}; do
172			echo "Starting ${_rc_elem}..."
173			rcstart ${_rc_elem}
174		done
175	fi
176
177	# Restore the original rc.conf.
178
179	mv /etc/rc.conf.orig /etc/rc.conf
180
181	# Set up auto-login if requested.
182
183	if [ "X$pfi_autologin" != "XNONE" ]; then
184		echo 'AL.pfi:\' >> /etc/gettytab
185		echo "        :al=${pfi_autologin}:tc=Pc:" >> /etc/gettytab
186		sed -i '' 's|^ttyv0.*|ttyv0 "/usr/libexec/getty AL.pfi" cons25 on secure|' /etc/ttys
187	fi
188
189	# Finally, start thttpd if the user wants to use
190	# the cgi frontend.
191
192	if [ "X$pfi_frontend" = "Xcgi" ]; then
193		echo "Starting thttpd..."
194		/usr/local/sbin/thttpd_wrapper &
195	fi
196}
197
198load_rc_config $name
199run_rc_command "$1"
200