/[livecd-tools]/trunk/livecd-functions.sh
Gentoo

Contents of /trunk/livecd-functions.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 95 - (show annotations) (download) (as text)
Thu Jan 26 22:49:18 2006 UTC (8 years, 6 months ago) by wolf31o2
File MIME type: text/x-sh
File size: 12643 byte(s)
tts/0 -> ttyS0

1 #!/bin/bash
2 # Copyright 1999-2005 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header: /var/cvsroot/gentoo/src/livecd-tools/livecd-functions.sh,v 1.19 2006/01/26 22:49:18 wolf31o2 Exp $
5
6 # Global Variables:
7 # CDBOOT -- is booting off CD
8 # LIVECD_CONSOLE -- console that is specified to kernel commandline
9 # -- (ttyS0, tty1, etc). Only defined if passed to kernel
10 # LIVECD_CONSOLE_BAUD -- console baudrate specified
11 # LIVECD_CONSOLE_PARITY -- console parity specified
12 # LIVECD_CONSOLE_DATABITS -- console databits specified
13
14 source /sbin/functions.sh
15
16 livecd_parse_opt() {
17 case "$1" in
18 *\=*)
19 echo "$1" | cut -f2 -d=
20 ;;
21 esac
22 }
23
24 livecd_check_root() {
25 if [ "$(whoami)" != "root" ]
26 then
27 echo "ERROR: must be root to continue"
28 return 1
29 fi
30 }
31
32 livecd_get_cmdline() {
33 echo "0" > /proc/sys/kernel/printk
34 CMDLINE="$(cat /proc/cmdline)"
35 export CMDLINE
36 }
37
38 no_gl() {
39 ewarn "No OpenGL-capable card found."
40 echo
41 einfo "If you have a card that you know is supported by either the ATI or"
42 einfo "NVIDIA binary drivers, please file a bug with the output of lspci"
43 einfo "on http://bugs.gentoo.org so we can resolve this."
44 GLTYPE=xorg-x11
45 }
46
47 ati_gl() {
48 einfo "ATI card detected."
49 GLTYPE=ati
50 }
51
52 nv_gl() {
53 einfo "NVIDIA card detected."
54 GLTYPE=nvidia
55 }
56
57 get_video_cards() {
58 [ -x /sbin/lspci ] && VIDEO_CARDS="$(/sbin/lspci | grep VGA)"
59 [ -x /usr/sbin/lspci ] && VIDEO_CARDS="$(/usr/sbin/lspci | grep VGA)"
60 NUM_CARDS="$(echo ${VIDEO_CARDS} | wc -l)"
61 if [ ${NUM_CARDS} -eq 1 ]; then
62 NVIDIA=$(echo ${VIDEO_CARDS} | grep "nVidia Corporation")
63 ATI=$(echo ${VIDEO_CARDS} | grep "ATI Technologies")
64 if [ -n "${NVIDIA}" ]; then
65 NVIDIA_CARD=$(echo ${NVIDIA} | awk 'BEGIN {RS=" "} /(NV|nv)[0-9]+/ {print $1}' | cut -d. -f1 | sed 's/ //' | sed 's:[^0-9]::g')
66 if [ -n "${NVIDIA_CARD}" ]; then
67 if [ $(echo ${NVIDIA_CARD} | cut -dV -f2) -ge 4 ]; then
68 nv_gl
69 else
70 no_gl
71 fi
72 else
73 no_gl
74 fi
75 elif [ -n "${ATI}" ]; then
76 ATI_CARD=$(echo ${ATI} | awk 'BEGIN {RS=" "} /(R|RV|RS)[0-9]+/ {print $1}')
77 if [ $(echo ${ATI_CARD} | grep S) ]; then
78 ATI_CARD_S=$(echo ${ATI_CARD} | cut -dS -f2)
79 elif [ $(echo ${ATI_CARD} | grep V) ]; then
80 ATI_CARD_V=$(echo ${ATI_CARD} | cut -dV -f2)
81 else
82 ATI_CARD=$(echo ${ATI_CARD} | cut -dR -f2)
83 fi
84 if [ -n "${ATI_CARD_S}" ] && [ ${ATI_CARD_S} -ge 350 ]; then
85 ati_gl
86 elif [ -n "${ATI_CARD_V}" ] && [ ${ATI_CARD_V} -ge 250 ]; then
87 ati_gl
88 elif [ -n "${ATI_CARD}" ] && [ ${ATI_CARD} -ge 200 ]; then
89 ati_gl
90 else
91 no_gl
92 fi
93 else
94 no_gl
95 fi
96 fi
97 }
98
99 livecd_config_wireless() {
100 cd /tmp/setup.opts
101 dialog --title "SSID" --inputbox "Please enter your SSID, or leave blank for selecting the nearest open network" 20 50 2> ${iface}.SSID
102 SSID="$(cat ${iface}.SSID)"
103 if [ -n "${SSID}" ]
104 then
105 dialog --title "WEP (Part 1)" --menu "Does your network use encryption?" 20 60 7 1 "Yes" 2 "No" 2> ${iface}.WEP
106 WEP="$(cat ${iface}.WEP)"
107 case ${WEP} in
108 1)
109 dialog --title "WEP (Part 2)" --menu "Are you entering your WEP key in HEX or ASCII?" 20 60 7 1 "HEX" 2 "ASCII" 2> ${iface}.WEPTYPE
110 WEP_TYPE="$(cat ${iface}.WEPTYPE)"
111 case ${WEP_TYPE} in
112 1)
113 dialog --title "WEP (Part 3)" --inputbox "Please enter your WEP key in the form of XXXX-XXXX-XX for 64-bit or XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XX for 128-bit" 20 50 2> ${iface}.WEPKEY
114 WEP_KEY="$(cat ${iface}.WEPKEY)"
115 if [ -n "${WEP_KEY}" -a -x /usr/sbin/iwconfig ]
116 then
117 /usr/sbin/iwconfig ${iface} essid "${SSID}"
118 /usr/sbin/iwconfig ${iface} key "${WEP_KEY}"
119 fi
120 ;;
121 2)
122 dialog --title "WEP (Part 3)" --inputbox "Please enter your WEP key in ASCII form. This should be 5 or 13 characters for either 64-bit or 128-bit encryption, repectively" 20 50 2> ${iface}.WEPKEY
123 WEP_KEY="$(cat ${iface}.WEPKEY)"
124 if [ -n "${WEP_KEY}" -a -x /usr/sbin/iwconfig ]
125 then
126 /usr/sbin/iwconfig ${iface} essid "${SSID}"
127 /usr/sbin/iwconfig ${iface} key "s:${WEP_KEY}"
128 fi
129 ;;
130 esac
131 ;;
132 2)
133 /usr/sbin/iwconfig ${iface} essid "${SSID}"
134 /usr/sbin/iwconfig ${iface} key off
135 ;;
136 esac
137 fi
138 }
139
140 livecd_write_wireless_conf() {
141 cd /tmp/setup.opts
142 SSID="$(cat ${iface}.SSID)"
143 if [ -n "${SSID}" ]
144 then
145 echo "# This wireless configuration file was built by net-setup" > /etc/conf.d/wireless
146 WEP="$(cat ${iface}.WEPTYPE)"
147 case ${WEP} in
148 1)
149 WEP_TYPE="$(cat ${iface}.WEPTYPE)"
150 if [ -n "${WEP_TYPE}" ]
151 then
152 WEP_KEY="$(cat ${iface}.WEPKEY)"
153 if [ -n "${WEP_KEY}" ]
154 then
155 SSID_TRANS="$(echo ${SSID//[![:word:]]/_})"
156 case ${WEP_TYPE} in
157 1)
158 echo "key_${SSID_TRANS}=\"${WEP_KEY} enc open\"" >> /etc/conf.d/wireless
159 ;;
160 2)
161 echo "key_${SSID_TRANS}=\"s:${WEP_KEY} enc open\"" >> /etc/conf.d/wireless
162 ;;
163 esac
164 fi
165 fi
166 ;;
167 2)
168 :
169 ;;
170 esac
171 echo "preferred_aps=( \"${SSID}\" )" >> /etc/conf.d/wireless
172 echo "associate_order=\"forcepreferredonly\"" >> /etc/conf.d/wireless
173 fi
174 }
175
176 livecd_config_ip() {
177 cd /tmp/setup.opts
178 dialog --title "TCP/IP setup" --menu "You can use DHCP to automatically configure a network interface or you can specify an IP and related settings manually. Choose one option:" 20 60 7 1 "Use DHCP to auto-detect my network settings" 2 "Specify an IP address manually" 2> ${iface}.DHCP
179 DHCP="$(cat ${iface}.DHCP)"
180 case ${DHCP} in
181 1)
182 /sbin/dhcpcd -n -t 10 -h $(hostname) ${iface} &
183 ;;
184 2)
185 dialog --title "IP address" --inputbox "Please enter an IP address for ${iface}:" 20 50 "192.168.1.1" 2> ${iface}.IP
186 IP="$(cat ${iface}.IP)"
187 BC_TEMP="$(echo $IP|cut -d . -f 1).$(echo $IP|cut -d . -f 2).$(echo $IP|cut -d . -f 3).255"
188 dialog --title "Broadcast address" --inputbox "Please enter a Broadcast address for ${iface}:" 20 50 "${BC_TEMP}" 2> ${iface}.BC
189 BROADCAST="$(cat ${iface}.BC)"
190 dialog --title "Network mask" --inputbox "Please enter a Network Mask for ${iface}:" 20 50 "255.255.255.0" 2> ${iface}.NM
191 NETMASK="$(cat ${iface}.NM)"
192 dialog --title "Gateway" --inputbox "Please enter a Gateway for ${iface} (hit enter for none:)" 20 50 2> ${iface}.GW
193 GATEWAY="$(cat ${iface}.GW)"
194 dialog --title "DNS server" --inputbox "Please enter a name server to use (hit enter for none:)" 20 50 2> ${iface}.DNS
195 DNS="$(cat ${iface}.DNS)"
196 /sbin/ifconfig ${iface} ${IP} broadcast ${BROADCAST} netmask ${NETMASK}
197 if [ -n "${GATEWAY}" ]
198 then
199 /sbin/route add default gw ${GATEWAY} dev ${iface} netmask 0.0.0.0 metric 1
200 fi
201 if [ -n "${DNS}" ]
202 then
203 dialog --title "DNS Search Suffix" --inputbox "Please enter any domains which you would like to search on DNS queries (hit enter for none:)" 20 50 2> ${iface}.SUFFIX
204 SUFFIX="$(cat ${iface}.SUFFIX)"
205 echo "nameserver ${DNS}" > /etc/resolv.conf
206 if [ -n "${SUFFIX}" ]
207 then
208 echo "search ${SUFFIX}" >> /etc/resolv.conf
209 fi
210 fi
211 ;;
212 esac
213 }
214
215 livecd_write_net_conf() {
216 cd /tmp/setup.opts
217 echo "# This network configuration was written by net-setup" > /etc/conf.d/net
218 DHCP="$(cat ${iface}.DHCP)"
219 case ${DHCP} in
220 1)
221 echo "iface_${iface}=\"dhcp\"" >> /etc/conf.d/net
222 ;;
223 2)
224 IP="$(cat ${iface}.IP)"
225 BROADCAST="$(cat ${iface}.BC)"
226 NETMASK="$(cat ${iface}.NM)"
227 GATEWAY="$(cat ${iface}.GW)"
228 if [ -n "${IP}" -a -n "${BROADCAST}" -a -n "${NETMASK}" ]
229 then
230 echo "iface_eth0=\"${IP} broadcast ${BROADCAST} netmask ${NETMASK}\"" >> /etc/conf.d/net
231 if [ -n "${GATEWAY}" ]
232 then
233 echo "gateway=\"${iface}/${GATEWAY}\"" >> /etc/conf.d/net
234 fi
235 fi
236 ;;
237 esac
238 }
239
240 livecd_console_settings() {
241 # scan for a valid baud rate
242 case "$1" in
243 300*)
244 LIVECD_CONSOLE_BAUD=300
245 ;;
246 600*)
247 LIVECD_CONSOLE_BAUD=600
248 ;;
249 1200*)
250 LIVECD_CONSOLE_BAUD=1200
251 ;;
252 2400*)
253 LIVECD_CONSOLE_BAUD=2400
254 ;;
255 4800*)
256 LIVECD_CONSOLE_BAUD=4800
257 ;;
258 9600*)
259 LIVECD_CONSOLE_BAUD=9600
260 ;;
261 14400*)
262 LIVECD_CONSOLE_BAUD=14400
263 ;;
264 19200*)
265 LIVECD_CONSOLE_BAUD=19200
266 ;;
267 28800*)
268 LIVECD_CONSOLE_BAUD=28800
269 ;;
270 38400*)
271 LIVECD_CONSOLE_BAUD=38400
272 ;;
273 57600*)
274 LIVECD_CONSOLE_BAUD=57600
275 ;;
276 115200*)
277 LIVECD_CONSOLE_BAUD=115200
278 ;;
279 esac
280 if [ "${LIVECD_CONSOLE_BAUD}" = "" ]
281 then
282 # If it's a virtual console, set baud to 38400, if it's a serial
283 # console, set it to 9600 (by default anyhow)
284 case ${LIVECD_CONSOLE} in
285 tty[0-9])
286 LIVECD_CONSOLE_BAUD=38400
287 ;;
288 *)
289 LIVECD_CONSOLE_BAUD=9600
290 ;;
291 esac
292 fi
293 export LIVECD_CONSOLE_BAUD
294
295 # scan for a valid parity
296 # If the second to last byte is a [n,e,o] set parity
297 local parity
298 parity=$(echo $1 | rev | cut -b 2-2)
299 case "$parity" in
300 [neo])
301 LIVECD_CONSOLE_PARITY=$parity
302 ;;
303 esac
304 export LIVECD_CONSOLE_PARITY
305
306 # scan for databits
307 # Only set databits if second to last character is parity
308 if [ "${LIVECD_CONSOLE_PARITY}" != "" ]
309 then
310 LIVECD_CONSOLE_DATABITS=$(echo $1 | rev | cut -b 1)
311 fi
312 export LIVECD_CONSOLE_DATABITS
313 return 0
314 }
315
316 livecd_read_commandline() {
317 livecd_get_cmdline || return 1
318
319 for x in ${CMDLINE}
320 do
321 case "${x}" in
322 cdroot)
323 CDBOOT="yes"
324 export CDBOOT
325 ;;
326 cdroot\=*)
327 CDBOOT="yes"
328 export CDBOOT
329 ;;
330 console\=*)
331 local live_console
332 live_console=$(livecd_parse_opt "${x}")
333
334 # Parse the console line. No options specified if
335 # no comma
336 LIVECD_CONSOLE=$(echo ${live_console} | cut -f1 -d,)
337 if [ "${LIVECD_CONSOLE}" = "" ]
338 then
339 # no options specified
340 LIVECD_CONSOLE=${live_console}
341 else
342 # there are options, we need to parse them
343 local livecd_console_opts
344 livecd_console_opts=$(echo ${live_console} | cut -f2 -d,)
345 livecd_console_settings ${livecd_console_opts}
346 fi
347 export LIVECD_CONSOLE
348 ;;
349 esac
350 done
351 return 0
352 }
353
354 livecd_fix_inittab() {
355 if [ "${CDBOOT}" = "" ]
356 then
357 return 1
358 fi
359
360 # Create a backup
361 cp -f /etc/inittab /etc/inittab.old
362
363 # Comment out current getty settings
364 sed -i -e '/^c[0-9]/ s/^/#/' /etc/inittab
365 sed -i -e '/^s[01]/ s/^/#/' /etc/inittab
366
367 # SPARC & HPPA console magic
368 if [ "${HOSTTYPE}" = "sparc" -o "${HOSTTYPE}" = "hppa" -o "${HOSTTYPE}" = "ppc64" ]
369 then
370 # Mount openprom tree for user debugging purposes
371 if [ "${HOSTTYPE}" = "sparc" ]
372 then
373 mount -t openpromfs none /proc/openprom
374 fi
375
376 # SPARC serial port A, HPPA mux / serial
377 if [ -c "/dev/tts/0" ]
378 then
379 LIVECD_CONSOLE_BAUD=$(stty -F /dev/tts/0 speed)
380 echo "s0:12345:respawn:/sbin/agetty -nl /bin/bashlogin ${LIVECD_CONSOLE_BAUD} ttyS0 vt100" >> /etc/inittab
381 fi
382 # HPPA software PDC console (K-models)
383 if [ "${LIVECD_CONSOLE}" = "ttyB0" ]
384 then
385 mknod /dev/ttyB0 c 11 0
386 LIVECD_CONSOLE_BAUD=$(stty -F /dev/ttyB0 speed)
387 echo "b0:12345:respawn:/sbin/agetty -nl /bin/bashlogin ${LIVECD_CONSOLE_BAUD} ttyB0 vt100" >> /etc/inittab
388 fi
389 # FB / STI console
390 if [ -c "/dev/vc/1" -o -c "/dev/tts/1" -o -c "/dev/tty2" ]
391 then
392 MODEL_NAME=$(cat /proc/cpuinfo |grep "model name"|sed 's/.*: //')
393 if [ "${MODEL_NAME}" = "UML" ]
394 then
395 for x in 0 1 2 3 4 5 6
396 do
397 echo "c${x}:12345:respawn:/sbin/mingetty --noclear --autologin root tty${x}" >> /etc/inittab
398 done
399 else
400 for x in 1 2 3 4 5 6
401 do
402 echo "c${x}:12345:respawn:/sbin/mingetty --noclear --autologin root tty${x}" >> /etc/inittab
403 done
404 fi
405 fi
406 if [ -c "/dev/hvc0" ]
407 then
408 einfo "Adding hvc console to inittab"
409 echo "s0:12345:respawn:/sbin/agetty -nl /bin/bashlogin 9600 hvc0 vt320" >> /etc/inittab
410 fi
411
412
413 # The rest...
414 else
415 if [ "${LIVECD_CONSOLE}" = "tty0" -o "${LIVECD_CONSOLE}" = "" ]
416 then
417 for x in 1 2 3 4 5 6
418 do
419 echo "c${x}:12345:respawn:/sbin/agetty -nl /bin/bashlogin 38400 tty${x} linux" >> /etc/inittab
420 done
421 else
422 einfo "Adding ${LIVECD_CONSOLE} console to inittab"
423 echo "s0:12345:respawn:/sbin/agetty -nl /bin/bashlogin ${LIVECD_CONSOLE_BAUD} ${LIVECD_CONSOLE} vt100" >> /etc/inittab
424 fi
425 fi
426
427 # EFI-based machines should automatically hook up their console lines
428 if dmesg | grep -q '^Adding console on'
429 then
430 dmesg | grep '^Adding console on' | while read x; do
431 line=`echo "$x" | cut -d' ' -f4`
432 id=e`echo "$line" | grep -o '.\{1,3\}$'`
433 [ "${line}" = "${LIVECD_CONSOLE}" ] && continue # already setup above
434 case "$x" in
435 *options\ \'[0-9]*) speed=`echo "$x" | sed "s/.*options '//; s/[^0-9].*//"` ;;
436 *) speed=9600 ;; # choose a default, only matters if it is serial
437 esac
438 echo "$id:12345:respawn:/sbin/agetty -nl /bin/bashlogin ${speed} ${line} vt100" >> /etc/inittab
439 done
440 fi
441
442 # force reread of inittab
443 kill -HUP 1
444 return 0
445 }

Properties

Name Value
svn:eol-style native
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.20