installer - Several improvements
[dragonfly.git] / usr.sbin / installer / installer / installer.sh
CommitLineData
bfe20b28
SW
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 $
bfe20b28
SW
5
6### SUBS ###
7
8background_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
25installer_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
bfe20b28
SW
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
d07a93d3 66 if [ "X$pfi_frontend" = "Xauto" ]; then
f7df6c8e
AHJ
67 if [ "X$TTY_INST" = "X" ]; then
68 if $(is_livecd); then
69 TTY=/dev/ttyv1
20c2db9a 70 pfi_frontend="cursesvty"
f7df6c8e
AHJ
71 else
72 TTY=$(tty)
73 pfi_frontend="curseslog"
20c2db9a 74 fi
d07a93d3 75 else
20c2db9a 76 pfi_frontend="cursesx11"
d07a93d3
MD
77 fi
78 fi
79
bfe20b28
SW
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 ;;
20c2db9a 89 Xcursesvty)
bfe20b28
SW
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 \
62eab433 95 /usr/sbin/dfuife_curses \
bfe20b28
SW
96 -r $RENDEZVOUS \
97 -t $pfi_dfui_transport \
62eab433 98 -b /usr/share/installer/fred.txt \
20c2db9a 99 2>/dev/ttyv0 <$TTY >$TTY &
bfe20b28
SW
100 fi
101 rm -f /tmp/ps.txt
102 sleep 1
103 vidcontrol -s 2 </dev/ttyv0
20c2db9a
SW
104 $pfi_backend \
105 -o $SOURCE_DIR \
106 -r $RENDEZVOUS \
107 -t $pfi_dfui_transport
bfe20b28
SW
108 RESULT=$?
109 sleep 1
110 killall dfuife_curses
111 vidcontrol -s 1 </dev/ttyv0
112 ;;
20c2db9a
SW
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)
bfe20b28
SW
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 \
62eab433 142 /usr/sbin/dfuife_curses \
bfe20b28
SW
143 -r $RENDEZVOUS \
144 -t $pfi_dfui_transport \
62eab433 145 -b /usr/share/installer/fred.txt \
bfe20b28
SW
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
f7df6c8e
AHJ
175is_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
bfe20b28
SW
196### MAIN ###
197
20c2db9a
SW
198if [ $# -gt 1 ]; then
199 echo "usage: installer [source_directory]"
200 exit 1
bfe20b28
SW
201fi
202
20c2db9a 203#
f7df6c8e
AHJ
204# Source directory for the installation
205#
206SOURCE_DIR=${sdir}/
bfe20b28
SW
207
208ps auwwwxxx > /tmp/ps.txt
209if grep -q dfuibe_installer /tmp/ps.txt; then
210 # Installer is already running. Log in normally.
211 rm -f /tmp/ps.txt
212else
213 rm -f /tmp/ps.txt
214 installer_start
215fi
216
217### END of installer ###