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