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

Contents of /trunk/livecd-functions.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 58 - (hide annotations) (download) (as text)
Fri Jun 10 13:12:00 2005 UTC (9 years, 6 months ago) by wolf31o2
File MIME type: text/x-sh
File size: 10847 byte(s)
Removing broken get_baselayout_ver funtion.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20