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