Merge from vendor branch OPENSSL:
[dragonfly.git] / nrelease / installer / etc / rc.d / pfi
1 #!/bin/sh
2
3 # $Id: pfi,v 1.4 2004/08/06 23:26:05 cpressey Exp $
4 # $DragonFly: src/nrelease/installer/etc/rc.d/pfi,v 1.6 2005/03/07 18:02:07 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                 if [ -r /etc/defaults/pfi.conf ]; then
26                         . /etc/defaults/pfi.conf
27                 fi
28                 . /etc/pfi.conf
29                 if [ "$pfi_script" != "" -a -x "$1/$pfi_script" ]; then
30                         $1/$pfi_script
31                 fi
32                 return 0
33         else
34                 return 1
35         fi
36 }
37
38 get_authorized_hosts()
39 {
40         [ -r /root/.ssh/authorized_hosts ] && return 0
41         if [ -r $1/authorized_hosts ]; then
42                 echo "authorized_hosts found!"
43                 mkdir -p /root/.ssh/
44                 tr -d "\r" < $1/authorized_hosts > /root/.ssh/authorized_hosts
45         fi
46 }
47
48 look_for_pfi_config_msdos()
49 {
50         [ -r /etc/pfi.conf ] && return 0
51
52         for try_device in da0s1 da1s1 fd0 fd1; do
53                 echo -n "Looking for pfi.conf on /dev/${try_device}..."
54                 if [ ! -e /dev/${try_device} ]; then
55                         ( cd /dev && ./MAKEDEV ${try_device} )
56                 fi
57                 if mount_msdos -o rdonly /dev/$try_device /mnt ; then
58                         echo -n " /dev/$try_device ok..."
59                         if get_pfi_config /mnt /dev/$try_device; then
60                                 get_authorized_hosts /mnt
61                                 umount /mnt
62                                 return 0
63                         fi
64                         umount /mnt
65                 fi
66                 echo " not found"
67         done
68         return 1
69 }
70
71 look_for_pfi_config_cd9660()
72 {
73         [ -r /etc/pfi.conf ] && return 0
74
75         for try_device in acd0c; do
76                 echo -n "Looking for pfi.conf on /dev/${try_device}..."
77                 if [ ! -e /dev/${try_device} ]; then
78                         ( cd /dev && ./MAKEDEV ${try_device} )
79                 fi
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         done
91         return 1
92 }
93
94 pfi_start()
95 {
96         echo "Starting pfi..."
97
98         # Get the pfi.conf file off the pfi media and into /etc/pfi.conf.
99
100         look_for_pfi_config_cd9660
101         look_for_pfi_config_msdos
102
103         if [ ! -r /etc/pfi.conf ]; then
104                 echo '' >/etc/pfi.conf
105         fi
106
107         # Tack pfi.conf onto the end of rc.conf, so that variables in
108         # pfi.conf are available to the rc subsystem (for pfi_rc_actions.)
109
110         cp /etc/rc.conf /etc/rc.conf.orig
111         cat /etc/pfi.conf >>/etc/rc.conf
112
113         if [ -r /etc/defaults/pfi.conf ]; then
114                 . /etc/defaults/pfi.conf
115         fi
116         . /etc/pfi.conf
117
118         # We can perform any pre-install tasks here by
119         # examining the contents of pfi_* variables.
120
121         # Interpret pfi_sshd_* options.  These basically add settings
122         # to /etc/ssh/sshd_config; it is assumed "sshd" will appear
123         # in pfi_rc_actions to restart sshd.
124
125         case ${pfi_sshd_permit_root_login} in
126         YES)
127                 echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
128                 ;;
129         without-password)
130                 echo "PermitRootLogin without-password" >> /etc/ssh/sshd_config
131                 ;;
132         forced-commands-only)
133                 echo "PermitRootLogin forced-commands-only" >> /etc/ssh/sshd_config
134                 ;;
135         *)
136                 ;;
137         esac
138
139         case ${pfi_sshd_permit_empty_passwords} in
140         YES)
141                 echo "PermitEmptyPasswords yes" >> /etc/ssh/sshd_config
142                 ;;
143         *)
144                 ;;
145         esac
146
147         # Interpret pfi_set_root_password.  If it is not empty, use
148         # it to set root's LiveCD password.
149
150         if [ "X$pfi_set_root_password" != "X" ]; then
151                 echo "$pfi_set_root_password" | \
152                     /usr/sbin/pw usermod root -h 0
153         fi
154
155         # The most important pre-install task is to restart
156         # any RCNG scripts listed in pfi_rc_actions with any new
157         # settings that might have been set up by pfi.conf.
158
159         if [ "X$pfi_rc_actions" != "X" ]; then
160                 rev_actions=`reverse_list $pfi_rc_actions`
161
162                 for _rc_elem in ${rev_actions}; do
163                         echo "Stopping ${_rc_elem}..."
164                         rcstop ${_rc_elem}
165                 done
166                 for _rc_elem in ${pfi_rc_actions}; do
167                         echo "Starting ${_rc_elem}..."
168                         rcstart ${_rc_elem}
169                 done
170         fi
171
172         # Restore the original rc.conf.
173
174         mv /etc/rc.conf.orig /etc/rc.conf
175
176         # Set up auto-login if requested.
177
178         if [ "X$pfi_autologin" != "XNONE" ]; then
179                 echo 'AL.pfi:\' >> /etc/gettytab
180                 echo "        :al=${pfi_autologin}:tc=Pc:" >> /etc/gettytab
181                 sed -i '' 's|^ttyv0.*|ttyv0 "/usr/libexec/getty AL.pfi" cons25 on secure|' /etc/ttys
182         fi
183
184         # Finally, start thttpd if the user wants to use
185         # the cgi frontend.
186
187         if [ "X$pfi_frontend" = "Xcgi" ]; then
188                 echo "Starting thttpd..."
189                 /usr/local/sbin/thttpd_wrapper &
190         fi
191 }
192
193 load_rc_config $name
194 run_rc_command "$1"