installer - Several improvements
[dragonfly.git] / usr.sbin / installer / installer / installer.sh
1 #!/bin/sh
2
3 # installer - start installer frontend and backend as per pfi config.
4 # $Id: installer,v 1.20 2005/04/13 03:32:16 cpressey Exp $
5
6 ### SUBS ###
7
8 background_backend()
9 {
10         RENDEZVOUS=$1
11         TRANSPORT=$2
12         $pfi_backend -r $RENDEZVOUS -t $TRANSPORT >/dev/null 2>&1
13         RESULT=$?
14         case "$RESULT" in
15         0)
16                 ;;
17         5)
18                 $pfi_shutdown_command
19                 ;;
20         *)
21                 ;;
22         esac
23 }
24
25 installer_start()
26 {
27         # Console start sequence:
28         # - Backend (and all other logging) goes to console (ttyv0)
29         # - curses frontend starts on ttyv1.
30         # - Uses vidcontrol -s 2 to switch to ttyv1 once the frontend is up.
31
32         echo -n "Starting installer.  "
33
34         if [ -r /etc/defaults/pfi.conf ]; then
35                 . /etc/defaults/pfi.conf
36         fi
37
38         if [ -r /etc/pfi.conf ]; then
39                 echo "Reading /etc/pfi.conf ..."
40                 . /etc/pfi.conf
41         else
42                 echo "/etc/pfi.conf not found, starting interactive install."
43         fi
44
45         # We can set up any install variables and such
46         # here by examining pfi_* variables.
47
48         if [ "X$pfi_run" != "X" ]; then
49                 pfi_frontend=none
50                 $pfi_run
51         fi
52
53         case "X$pfi_dfui_transport" in
54         Xnpipe)
55                 RENDEZVOUS="installer"
56                 ;;
57         Xtcp)
58                 RENDEZVOUS="9999"
59                 ;;
60         *)
61                 echo "Unsupported DFUI transport '$pfi_dfui_transport'."
62                 return
63                 ;;
64         esac
65
66         if [ "X$pfi_frontend" = "Xauto" ]; then
67                 if [ "X$TTY_INST" = "X" ]; then
68                     if $(is_livecd); then
69                                 TTY=/dev/ttyv1
70                                 pfi_frontend="cursesvty"
71                         else
72                                 TTY=$(tty)
73                                 pfi_frontend="curseslog"
74                         fi
75                 else
76                         pfi_frontend="cursesx11"
77                 fi
78         fi
79
80         case "X$pfi_frontend" in
81         Xqt)
82                 $pfi_backend -r $RENDEZVOUS -t $pfi_dfui_transport
83                 RESULT=$?
84                 ;;
85         Xcgi)
86                 $pfi_backend -r $RENDEZVOUS -t $pfi_dfui_transport
87                 RESULT=$?
88                 ;;
89         Xcursesvty)
90                 ps auwwwxxx > /tmp/ps.txt
91                 if grep -q dfuife_curses /tmp/ps.txt; then
92                         # Frontend is already running.
93                 else
94                         ESCDELAY=$pfi_curses_escdelay \
95                             /usr/sbin/dfuife_curses \
96                                 -r $RENDEZVOUS \
97                                 -t $pfi_dfui_transport \
98                                 -b /usr/share/installer/fred.txt \
99                             2>/dev/ttyv0 <$TTY >$TTY &
100                 fi
101                 rm -f /tmp/ps.txt
102                 sleep 1
103                 vidcontrol -s 2 </dev/ttyv0
104                 $pfi_backend \
105                     -o $SOURCE_DIR \
106                     -r $RENDEZVOUS \
107                     -t $pfi_dfui_transport
108                 RESULT=$?
109                 sleep 1
110                 killall dfuife_curses
111                 vidcontrol -s 1 </dev/ttyv0
112                 ;;
113         Xcurseslog)
114                 ps auwwwxxx > /tmp/ps.txt
115                 if grep -q dfuife_curses /tmp/ps.txt; then
116                         # Frontend is already running.
117                 else
118                         ESCDELAY=$pfi_curses_escdelay \
119                             /usr/sbin/dfuife_curses \
120                                 -r $RENDEZVOUS \
121                                 -t $pfi_dfui_transport \
122                                 -b /usr/share/installer/fred.txt \
123                             2>/tmp/dfuife_curses.log <$TTY >$TTY &
124                 fi
125                 rm -f /tmp/ps.txt
126                 sleep 1
127                 $pfi_backend \
128                     -o $SOURCE_DIR \
129                     -r $RENDEZVOUS \
130                     -t $pfi_dfui_transport \
131                     >/dev/null 2>&1
132                 RESULT=$?
133                 sleep 1
134                 killall -q dfuife_curses
135                 ;;
136         Xcursesx11)
137                 ps auwwwxxx > /tmp/ps.txt
138                 if grep -q dfuife_curses /tmp/ps.txt; then
139                         echo "Frontend is already running"
140                 else
141                         ESCDELAY=$pfi_curses_escdelay \
142                         /usr/sbin/dfuife_curses \
143                         -r $RENDEZVOUS \
144                         -t $pfi_dfui_transport \
145                         -b /usr/share/installer/fred.txt \
146                         >$TTY_INST <$TTY_INST 2>&1 &
147                 fi
148                 rm -f /tmp/ps.txt
149                 sleep 1
150                 $pfi_backend -r $RENDEZVOUS -t $pfi_dfui_transport
151                 RESULT=$?
152                 sleep 1
153                 killall dfuife_curses
154                 ;;
155         Xnone)
156                 RESULT=0
157                 ;;
158         *)
159                 echo "Unknown installer frontend '$pfi_frontend'."
160                 return
161                 ;;
162         esac
163
164         case "$RESULT" in
165         0)
166                 ;;
167         5)
168                 $pfi_shutdown_command
169                 ;;
170         *)
171                 ;;
172         esac
173 }
174
175 is_livecd()
176 {
177     local _ttyv1=$(grep -w "^ttyv1" /etc/ttys)
178     local cdmnt=$(mount -t cd9660 | grep 'cd[0-9]' | cut -w -f1)
179     local guest=$(sysctl -n kern.vmm_guest)
180
181     #
182     # ttyv1 isn't configured for the LiveCD/DVD so use
183     # that as a clue for now. Vkernels will be forced
184     # to use 'curseslog' to avoid polluting its only
185     # terminal.
186     #
187     [ "${guest}" = "vkernel" ] && return 1;
188
189     if [ ! -z "${cdmnt}" -a -z "${_ttyv1}" ]; then
190         return 0        # Return success, it's a LiveCD
191     else
192         return 1
193     fi
194 }
195
196 ### MAIN ###
197
198 if [ $# -gt 1 ]; then
199         echo "usage: installer [source_directory]"
200         exit 1
201 fi
202
203 #
204 # Source directory for the installation
205 #
206 SOURCE_DIR=${sdir}/
207
208 ps auwwwxxx > /tmp/ps.txt
209 if grep -q dfuibe_installer /tmp/ps.txt; then
210         # Installer is already running. Log in normally.
211         rm -f /tmp/ps.txt
212 else
213         rm -f /tmp/ps.txt
214         installer_start
215 fi
216
217 ### END of installer ###