eaecac3541dcf8b27b75c73817c9ff0f350bddc8
[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.8 2005/12/10 00:11:08 swildner Exp $
5 #
6
7 # PROVIDE: pfi
8 # REQUIRE: mountoptional
9
10 . /etc/rc.subr
11
12 name=pfi
13 start_cmd="pfi_start"
14 stop_cmd=":"
15
16 get_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
41 get_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
51 look_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                 echo -n "Looking for pfi.conf on /dev/${try_device}..."
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 acd0 cd0 acd1 cd1; do
76                 echo -n "Looking for pfi.conf on /dev/${try_device}..."
77                 if mount_cd9660 /dev/$try_device /mnt ; then
78                         echo -n " /dev/$try_device ok..."
79                         if get_pfi_config /mnt /dev/$try_device; then
80                                 get_authorized_hosts /mnt
81                                 umount /mnt
82                                 return 0
83                         fi
84                         umount /mnt
85                 fi
86                 echo " not found"
87         done
88         return 1
89 }
90
91 pfi_start()
92 {
93         echo "Starting pfi..."
94
95         # Get the pfi.conf file off the pfi media and into /etc/pfi.conf.
96
97         look_for_pfi_config_cd9660
98         look_for_pfi_config_msdos
99
100         # If the search was not successful, stub out a dummy pfi.conf.
101
102         if [ ! -r /etc/pfi.conf ]; then
103                 echo '' >/etc/pfi.conf
104         fi
105
106         # Append the contents of pfi.conf onto rc.conf, so that settings
107         # (such as ifconfig_dc0="DHCP") will be picked up by pfi_rc_actions.
108
109         cp /etc/rc.conf /etc/rc.conf.orig
110         cat /etc/pfi.conf >>/etc/rc.conf
111
112         # Read in the pfi.conf we either found or created for ourselves.
113
114         if [ -r /etc/defaults/pfi.conf ]; then
115                 . /etc/defaults/pfi.conf
116         fi
117         . /etc/pfi.conf
118
119         # We can perform any pre-install tasks here by
120         # examining the contents of pfi_* variables.
121
122         # Interpret pfi_sshd_* options.  These basically add settings
123         # to /etc/ssh/sshd_config; it is assumed "sshd" will appear
124         # in pfi_rc_actions to restart sshd.
125
126         case ${pfi_sshd_permit_root_login} in
127         YES)
128                 echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
129                 ;;
130         without-password)
131                 echo "PermitRootLogin without-password" >> /etc/ssh/sshd_config
132                 ;;
133         forced-commands-only)
134                 echo "PermitRootLogin forced-commands-only" >> /etc/ssh/sshd_config
135                 ;;
136         *)
137                 ;;
138         esac
139
140         case ${pfi_sshd_permit_empty_passwords} in
141         YES)
142                 echo "PermitEmptyPasswords yes" >> /etc/ssh/sshd_config
143                 ;;
144         *)
145                 ;;
146         esac
147
148         # Interpret pfi_set_root_password.  If it is not empty, use
149         # it to set root's LiveCD password.
150
151         if [ "X$pfi_set_root_password" != "X" ]; then
152                 echo "$pfi_set_root_password" | \
153                     /usr/sbin/pw usermod root -h 0
154         fi
155
156         # The most important pre-install task is to restart
157         # any RCNG scripts listed in pfi_rc_actions with any new
158         # settings that might have been set up by pfi.conf.
159
160         if [ "X$pfi_rc_actions" != "X" ]; then
161                 rev_actions=`reverse_list $pfi_rc_actions`
162
163                 for _rc_elem in ${rev_actions}; do
164                         echo "Stopping ${_rc_elem}..."
165                         rcstop ${_rc_elem}
166                 done
167                 for _rc_elem in ${pfi_rc_actions}; do
168                         echo "Starting ${_rc_elem}..."
169                         rcstart ${_rc_elem}
170                 done
171         fi
172
173         # Restore the original rc.conf.
174
175         mv /etc/rc.conf.orig /etc/rc.conf
176
177         # Set up auto-login if requested.
178
179         if [ "X$pfi_autologin" != "XNONE" ]; then
180                 echo 'AL.pfi:\' >> /etc/gettytab
181                 echo "        :al=${pfi_autologin}:tc=Pc:" >> /etc/gettytab
182                 sed -i '' 's|^ttyv0.*|ttyv0 "/usr/libexec/getty AL.pfi" cons25 on secure|' /etc/ttys
183         fi
184
185         # Finally, start thttpd if the user wants to use
186         # the cgi frontend.
187
188         if [ "X$pfi_frontend" = "Xcgi" ]; then
189                 echo "Starting thttpd..."
190                 /usr/local/sbin/thttpd_wrapper &
191         fi
192 }
193
194 load_rc_config $name
195 run_rc_command "$1"