Add various improvements to the "pre-flight installer":
[dragonfly.git] / nrelease / installer / usr / local / bin / installer
1 #!/bin/sh
2
3 # installer - start installer frontend and backend as per pfi config.
4 # $Id: installer,v 1.5 2004/08/11 19:37:07 cpressey Exp $
5 # $DragonFly: src/nrelease/installer/usr/local/bin/installer,v 1.6 2004/11/11 20:30:05 cpressey Exp $
6
7 ### SUBS ###
8
9 background_backend()
10 {
11         RENDEZVOUS=$1
12         TRANSPORT=$2
13         cp /usr/local/sbin/dfuibe_installer /var/run/dfuibe_installer
14         /var/run/dfuibe_installer -r $RENDEZVOUS -t $TRANSPORT >/dev/null 2>&1
15         RESULT=$?
16         case "$RESULT" in
17         0)
18                 ;;
19         5)
20                 $pfi_shutdown_command
21                 ;;
22         *)
23                 ;;
24         esac
25 }
26
27 installer_start()
28 {
29         # Console start sequence:
30         # - Backend (and all other logging) goes to console (ttyv0)
31         # - curses frontend starts on ttyv1.
32         # - Uses vidcontrol -s 2 to switch to ttyv1 once the frontend is up.
33
34         echo -n "Starting installer.  "
35
36         if [ -r /etc/defaults/pfi.conf ]; then
37                 . /etc/defaults/pfi.conf
38         fi
39
40         if [ -r /etc/pfi.conf ]; then
41                 echo "Reading /etc/pfi.conf ..."
42                 . /etc/pfi.conf
43         else
44                 echo "/etc/pfi.conf not found, starting interactive install."
45         fi
46
47         # We can set up any install variables and such
48         # here by examining pfi_* variables.
49
50         if [ "X$pfi_run" != "X" ]; then
51                 pfi_frontend=none
52                 $pfi_run
53         fi
54
55         case "X$pfi_dfui_transport" in
56         Xcaps)
57                 sysctl kern.caps_enabled=1
58                 RENDEZVOUS="installer"
59                 ;;
60         Xnpipe)
61                 RENDEZVOUS="installer"
62                 ;;
63         Xtcp)
64                 RENDEZVOUS="9999"
65                 ;;
66         *)
67                 echo "Unsupported DFUI transport '$pfi_dfui_transport'."
68                 return
69                 ;;
70         esac
71
72         if [ "X$SERIAL" = "XYES" ]; then
73                 background_backend $RENDEZVOUS $pfi_dfui_transport &
74                 sleep 1
75                 /usr/local/sbin/dfuife_curses -r $RENDEZVOUS \
76                     -t $pfi_dfui_transport \
77                     -b /usr/local/share/dfuife_curses/fred.txt \
78                     2>/dev/null
79                 pfi_frontend=none
80         fi
81
82         case "X$pfi_frontend" in
83         Xcgi)
84                 cp /usr/local/sbin/dfuibe_installer /var/run/dfuibe_installer
85                 /var/run/dfuibe_installer -r test -t $pfi_dfui_transport
86                 RESULT=$?
87                 ;;
88         Xcurses)
89                 ps auwwwxxx > /tmp/ps.txt
90                 if grep -q dfuife_curses /tmp/ps.txt; then
91                         # Frontend is already running.
92                 else
93                         /usr/local/sbin/dfuife_curses -r $RENDEZVOUS \
94                             -t $pfi_dfui_transport \
95                             -b /usr/local/share/dfuife_curses/fred.txt \
96                             2>/dev/ttyv0 </dev/ttyv1 >/dev/ttyv1 &
97                 fi
98                 rm -f /tmp/ps.txt
99                 sleep 1
100                 vidcontrol -s 2
101                 cp /usr/local/sbin/dfuibe_installer /var/run/dfuibe_installer
102                 /var/run/dfuibe_installer -r $RENDEZVOUS -t $pfi_dfui_transport
103                 RESULT=$?
104                 sleep 1
105                 killall dfuife_curses
106                 vidcontrol -s 1
107                 ;;
108         Xnone)
109                 RESULT=0
110                 ;;
111         *)
112                 echo "Unknown installer frontend '$pfi_frontend'."
113                 return
114                 ;;
115         esac
116
117         case "$RESULT" in
118         0)
119                 ;;
120         5)
121                 $pfi_shutdown_command
122                 ;;
123         *)
124                 ;;
125         esac
126 }
127
128 ### MAIN ###
129
130 if [ "X$1" = "Xserial" ]; then
131         SERIAL=YES
132 fi
133
134 TTY=`w | awk '{ print $2 }' | tail -n1`
135 if [ "tty$TTY" = "ttyd0" ]; then
136         SERIAL=YES
137 fi
138
139 ps auwwwxxx > /tmp/ps.txt
140 if grep -q dfuibe_installer /tmp/ps.txt; then
141         # Installer is already running. Log in normally.
142         rm -f /tmp/ps.txt
143 else
144         rm -f /tmp/ps.txt
145         installer_start
146 fi
147
148 ### END of installer ###