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