Import the new nrelease Makefile packaging and root template infrastructure
[dragonfly.git] / nrelease / installer / etc / rc.d / pfi
1 #!/bin/sh
2
3 # $DragonFly: src/nrelease/installer/etc/rc.d/pfi,v 1.1 2004/07/10 22:26:18 dillon Exp $
4 #
5
6 # PROVIDE: pfi
7 # REQUIRE: inetd
8 # KEYWORD: DragonFly
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                 echo "#@@@@@" >>/etc/rc.conf
25                 cat /etc/pfi.conf >>/etc/rc.conf
26                 if [ -r /etc/defaults/pfi.conf ]; then
27                         . /etc/defaults/pfi.conf
28                 fi
29                 . /etc/pfi.conf
30                 if [ "$pfi_script" != "" -a -x "$1/$pfi_script" ]; then
31                         $1/$pfi_script
32                 fi
33                 return 0
34         else
35                 return 1
36         fi
37 }
38
39 look_for_pfi_config_msdos()
40 {
41         [ -r /etc/pfi.conf ] && return 0
42
43         for try_device in da0s1 da1s1 fd0 fd1; do
44                 echo -n "Looking for pfi.conf on /dev/${try_device}..."
45                 if [ ! -e /dev/${try_device} ]; then
46                         ( cd /dev && ./MAKEDEV ${try_device} )
47                 fi
48                 if mount_msdos -o rdonly /dev/$try_device /mnt ; then
49                         echo -n " /dev/$try_device ok..."
50                         if get_pfi_config /mnt /dev/$try_device; then
51                                 umount /mnt
52                                 return 0
53                         fi
54                         umount /mnt
55                 fi
56                 echo " not found"
57         done
58         return 1
59 }
60
61 look_for_pfi_config_cd9660()
62 {
63         [ -r /etc/pfi.conf ] && return 0
64
65         for try_device in acd0c; do
66                 echo -n "Looking for pfi.conf on /dev/${try_device}..."
67                 if [ ! -e /dev/${try_device} ]; then
68                         ( cd /dev && ./MAKEDEV ${try_device} )
69                 fi
70                 if mount_cd9660 /dev/$try_device /mnt ; then
71                         echo -n " /dev/$try_device ok..."
72                         if get_pfi_config /mnt /dev/$try_device; then
73                                 umount /mnt
74                                 return 0
75                         fi
76                         umount /mnt
77                 fi
78                 echo " not found"
79         done
80         return 1
81 }
82
83 pfi_start()
84 {
85         echo "Starting pfi..."
86
87         # Get the pfi.conf file off the pfi media and into /etc/pfi.conf.
88
89         look_for_pfi_config_cd9660
90         look_for_pfi_config_msdos
91
92         if [ ! -r /etc/pfi.conf ]; then
93                 echo '' >/etc/pfi.conf
94         fi
95
96         if [ -r /etc/defaults/pfi.conf ]; then
97                 . /etc/defaults/pfi.conf
98         fi
99         . /etc/pfi.conf
100
101         # We can perform any pre-install tasks here by
102         # examining the contents of pfi_* variables.
103
104         # Interpret pfi_sshd_* options.  These basically add settings
105         # to /etc/ssh/sshd_config; it is assumed "sshd" will appear
106         # in pfi_rc_actions to restart sshd.
107
108         case ${pfi_sshd_permit_root_login} in
109         YES)
110                 echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
111                 ;;
112         *)
113                 ;;
114         esac
115
116         case ${pfi_sshd_permit_empty_passwords} in
117         YES)
118                 echo "PermitEmptyPasswords yes" >> /etc/ssh/sshd_config
119                 ;;
120         *)
121                 ;;
122         esac
123
124         # Interpret pfi_set_root_password.  If it is not empty, use
125         # it to set root's LiveCD password.
126
127         if [ "X$pfi_set_root_password" != "X" ]; then
128                 echo "$pfi_set_root_password" | \
129                     /usr/sbin/pw usermod root -h 0
130         fi
131
132         # Lastly, the most important pre-install task is to restart
133         # any RCNG scripts listed in pfi_rc_actions with any new
134         # settings that might have been set up by pfi.conf.
135
136         if [ "X$pfi_rc_actions" != "X" ]; then
137                 rev_actions=`reverse_list $pfi_rc_actions`
138
139                 for _rc_elem in ${rev_actions}; do
140                         echo "Stopping ${_rc_elem}..."
141                         rcstop ${_rc_elem}
142                 done
143                 for _rc_elem in ${pfi_rc_actions}; do
144                         echo "Starting ${_rc_elem}..."
145                         rcstart ${_rc_elem}
146                 done
147         fi
148
149         # Now remove the copy of pfi.conf that we tacked onto
150         # the end of rc.conf so the above would work
151
152         awk '$1=="#@@@@@" || cut { cut = 1 } !cut { print $0 }' \
153             </etc/rc.conf >/etc/rc.conf.new
154         mv /etc/rc.conf.new /etc/rc.conf
155 }
156
157 load_rc_config $name
158 run_rc_command "$1"