51af9aa21cbb18a1055c1f28b7cd9b8bd1f6de46
[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$DISPLAY" = "X" ]; then
68                         if [ "X$LIVECD" = "X" ]; then
69                                 pfi_frontend="curseslog"
70                         else
71                                 pfi_frontend="cursesvty"
72                         fi
73                 else
74                         pfi_frontend="cursesx11"
75                 fi
76         fi
77
78         case "X$pfi_frontend" in
79         Xqt)
80                 $pfi_backend -r $RENDEZVOUS -t $pfi_dfui_transport
81                 RESULT=$?
82                 ;;
83         Xcgi)
84                 $pfi_backend -r $RENDEZVOUS -t $pfi_dfui_transport
85                 RESULT=$?
86                 ;;
87         Xcursesvty)
88                 ps auwwwxxx > /tmp/ps.txt
89                 if grep -q dfuife_curses /tmp/ps.txt; then
90                         # Frontend is already running.
91                 else
92                         ESCDELAY=$pfi_curses_escdelay \
93                             /usr/sbin/dfuife_curses \
94                                 -r $RENDEZVOUS \
95                                 -t $pfi_dfui_transport \
96                                 -b /usr/share/installer/fred.txt \
97                             2>/dev/ttyv0 <$TTY >$TTY &
98                 fi
99                 rm -f /tmp/ps.txt
100                 sleep 1
101                 vidcontrol -s 2 </dev/ttyv0
102                 $pfi_backend \
103                     -o $SOURCE_DIR \
104                     -r $RENDEZVOUS \
105                     -t $pfi_dfui_transport
106                 RESULT=$?
107                 sleep 1
108                 killall dfuife_curses
109                 vidcontrol -s 1 </dev/ttyv0
110                 ;;
111         Xcurseslog)
112                 ps auwwwxxx > /tmp/ps.txt
113                 if grep -q dfuife_curses /tmp/ps.txt; then
114                         # Frontend is already running.
115                 else
116                         ESCDELAY=$pfi_curses_escdelay \
117                             /usr/sbin/dfuife_curses \
118                                 -r $RENDEZVOUS \
119                                 -t $pfi_dfui_transport \
120                                 -b /usr/share/installer/fred.txt \
121                             2>/tmp/dfuife_curses.log <$TTY >$TTY &
122                 fi
123                 rm -f /tmp/ps.txt
124                 sleep 1
125                 $pfi_backend \
126                     -o $SOURCE_DIR \
127                     -r $RENDEZVOUS \
128                     -t $pfi_dfui_transport \
129                     >/dev/null 2>&1
130                 RESULT=$?
131                 sleep 1
132                 killall -q dfuife_curses
133                 ;;
134         Xcursesx11)
135                 ps auwwwxxx > /tmp/ps.txt
136                 if grep -q dfuife_curses /tmp/ps.txt; then
137                         echo "Frontend is already running"
138                 else
139                         ESCDELAY=$pfi_curses_escdelay \
140                         /usr/sbin/dfuife_curses \
141                         -r $RENDEZVOUS \
142                         -t $pfi_dfui_transport \
143                         -b /usr/share/installer/fred.txt \
144                         >$TTY_INST <$TTY_INST 2>&1 &
145                 fi
146                 rm -f /tmp/ps.txt
147                 sleep 1
148                 $pfi_backend -r $RENDEZVOUS -t $pfi_dfui_transport
149                 RESULT=$?
150                 sleep 1
151                 killall dfuife_curses
152                 ;;
153         Xnone)
154                 RESULT=0
155                 ;;
156         *)
157                 echo "Unknown installer frontend '$pfi_frontend'."
158                 return
159                 ;;
160         esac
161
162         case "$RESULT" in
163         0)
164                 ;;
165         5)
166                 $pfi_shutdown_command
167                 ;;
168         *)
169                 ;;
170         esac
171 }
172
173 ### MAIN ###
174
175 if [ $# -gt 1 ]; then
176         echo "usage: installer [source_directory]"
177         exit 1
178 fi
179
180 # Check if we are booted from a LiveCD, DVD etc. ttyv1 isn't configured in
181 # this case, so use that as a clue for now. Also, we have to use /dev/console
182 # in vkernels.
183 #
184 _ttyv1=`grep -w "^ttyv1" /etc/ttys`
185 if [ "`sysctl -n kern.vmm_guest`" = "vkernel" ]; then
186         SOURCE_DIR=/
187         TTY=/dev/console
188 elif [ -z "$_ttyv1" ]; then
189         LIVECD=YES
190         SOURCE_DIR=/
191         TTY=/dev/ttyv1
192 elif [ $# = 1 -a -d $1 ]; then
193         SOURCE_DIR=$1/
194         TTY=/dev/`w | awk '{ print $2 }' | tail -n1`
195 else
196         SOURCE_DIR=/
197         TTY=/dev/`w | awk '{ print $2 }' | tail -n1`
198 fi
199
200 ps auwwwxxx > /tmp/ps.txt
201 if grep -q dfuibe_installer /tmp/ps.txt; then
202         # Installer is already running. Log in normally.
203         rm -f /tmp/ps.txt
204 else
205         rm -f /tmp/ps.txt
206         installer_start
207 fi
208
209 ### END of installer ###