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