Subversion Repositories livecd

Rev

Rev 170 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 beyerle@PS 1
#!/bin/ash
2
#
3
# Functions library :: for Linux Live scripts 5.x.y
4
# Author: Tomas M. <http://www.linux-live.org>
5
#
169 beyerle@PS 6
# modified by Urs Beyerle
1 beyerle@PS 7
# - to allow LiveCD mounted over nfs
8
# - add scsi_mod, sd_mod for usb-storage module
9
# - only with boot option "automount", all devices in fstab are rw automounted
10
# - remove detect of CD and Floppy (done by fstab-sync)
11
# - add sr_mod (USB CDROM support)
12
# - add SATA to modprobe_usb_modules -> modprobe_usb_sata_modules
13
# - add fscache (for SL5) 
14
# - add ide-cd, sr_mod, cdrom (for SL5 cdrom support)
37 beyerle@PS 15
# - add aufs (unionfs replacement)
16
# - to allow LiveCD mounted over NFS (for diskless client)
48 beyerle@PS 17
# - add functions get_dhcp_lease() and load_network_modules()
85 beyerle@PS 18
# - add ata_piix to modprobe_usb_sata_modules
100 beyerle@PS 19
# - works with unionfs 2.x
20
# - better detection of network card in case of diskless client
126 beyerle@PS 21
# - add sg, sata_nv module
160 beyerle@PS 22
# - to allow LiveCD mounted over CIFS (for diskless client)
170 beyerle@PS 23
# - add function find_changes
1 beyerle@PS 24
#
25
 
26
# ===========================================================
27
# user interface functions
28
# ===========================================================
29
 
30
# echolog
31
# $1 = text to show and to write to /var/log/messages
32
#
33
echolog()
34
{
35
   echo "LIVECD:" "$@" >>/var/log/livedbg
36
   echo "$@"
37
}
38
 
39
# debug
40
# commands executed when debug boot parameter is present
41
#
42
debug()
43
{
44
   echo
45
   echo "====="
46
   echo ": Debugging started. Here is the root shell for you."
47
   echo ": Type your desired command or hit Ctrl+D to continue booting."
48
   echo
49
   ash
50
}
51
 
52
# header
53
# $1 = text to show
54
#
55
header()
56
{
57
   echolog "$1"
58
}
59
 
60
fatal()
61
{
62
   header "Fatal error occured - $1"
63
   echolog "Something went wrong and we can't continue booting :("
64
   echolog "You may explore the system by using simple commands like ls, lsmod, mount, etc."
65
   echolog "You may also try to hit Ctrl+D. Booting will continue. Use at your own risk."
66
   echolog "To be safe, hit Ctrl+Alt+Delete to reboot."
67
   echolog
68
   ash
69
}
70
 
71
# ===========================================================
72
# text processing functions
73
# ===========================================================
74
 
75
# egrep_o is a replacement for "egrep -o". It prints only the last
76
# matching text
77
# $1 = regular expression
78
#
79
egrep_o()
80
{
81
   cat | egrep "$1" | sed -r "s/.*($1).*/\\1/"
82
}
83
 
84
# look into cmdline and echo $1 back if $1 is set
85
# $1 = value name, case sensitive, for example livecd_subdir
86
# $2 = file to use instead /proc/cmdline, optional
87
#
88
cmdline_parameter()
89
{
90
   CMDLINE=/proc/cmdline
91
   if [ "$2" != "" ]; then CMDLINE="$2"; fi
92
   cat "$CMDLINE" | egrep_o "(^|[[:space:]]+)$1(\$|=|[[:space:]]+)" | egrep_o "$1"
93
}
94
 
95
# look into cmdline and echo value of $1 option
96
# $1 = value name, case sensitive, for example livecd_subdir
97
# $2 = file to use instead /proc/cmdline, optional
98
#
99
cmdline_value()
100
{
101
   CMDLINE=/proc/cmdline
102
   if [ "$2" != "" ]; then CMDLINE="$2"; fi
103
   cat "$CMDLINE" | egrep_o "(^|[[:space:]]+)$1=([^[:space:]]+)" | egrep_o "=.*" | cut -b 2- | tail -n 1
104
}
105
 
106
# ===========================================================
107
# system functions
108
# ===========================================================
109
 
110
# modprobe module $1, including all dependencies, suppress all messages
111
# (own function because modprobe in busybox doesn't work with gzipped modules)
112
# $1 = module name, eg. ehci-hcd
113
# $2 = optional argument
114
#
115
modprobe_module()
116
{
117
  if [ "$1" = "" ]; then return 1; fi
118
  PRINTK=`cat /proc/sys/kernel/printk`
119
  echo "0" >/proc/sys/kernel/printk
120
 
121
  KERNEL="`uname -r`"; LSMOD=/tmp/lsmod
122
  MODULEDEPS="`cat /lib/modules/$KERNEL/modules.dep | egrep \"$1\\.ko(\\.gz)?:\"`"
123
 
124
  for MODULE in `echo $MODULEDEPS | cut -d ":" -f 2-` `echo $MODULEDEPS | cut -d ":" -f 1`; do
125
     MODULE=${MODULE%%:};   # remove : at the end, a bug 
126
     TMPMOD="/tmp/`basename $MODULE .gz`";
127
     # if the module is not loaded already
128
     if [ "`cat $LSMOD 2>/dev/null | egrep \"^$TMPMOD\\\$\"`" = "" ]; then
129
        gunzip -c $MODULE 2>/dev/null >$TMPMOD
100 beyerle@PS 130
        if [ $? -ne 0 ]; then cp $MODULE $TMPMOD; fi # can't gunzip? copy
1 beyerle@PS 131
        insmod $TMPMOD $2; err=$?
132
        ### insmod $TMPMOD $2 >/dev/null 2>/dev/null; err=$?
133
        if [ "$err" -eq 0 ]; then echo $TMPMOD >>$LSMOD; fi # module log
134
        rm $TMPMOD
135
     fi
136
  done
137
 
138
  echo "$PRINTK" >/proc/sys/kernel/printk
139
  if [ "$err" -ne 0 ]; then echolog "error inserting module $1 ($err)"; fi
140
  return $err
141
}
142
 
143
# Mount device $1 to $2
144
# $1 = /dev device to mount, eg. /dev/hda1
145
# $2 = mountpoint, eg. /mnt/hda1
146
# $3 = mount options, for example "loop", "ro", or "remount,rw"
147
#
148
mount_device()
149
{
150
  mkdir -p $2
151
  if [ "$3" != "" ]; then OPTIONS="-o $3"; else OPTIONS=""; fi
152
 
153
  PRINTK=`cat /proc/sys/kernel/printk`
154
  echo "0" >/proc/sys/kernel/printk
155
 
156
  mount -t auto $1 $2 $OPTIONS >/dev/null 2>/dev/null
157
  err=$?
158
 
159
  if [ "$err" -ne 0 ]; then rmdir $2 2>/dev/null; fi
160
  echo "$PRINTK" >/proc/sys/kernel/printk
161
  return $err
162
}
163
 
164
# ===========================================================
165
# live module functions
166
# ===========================================================
167
 
168
# Create module
169
# call mksquashfs with apropriate arguments
170
# $1 = directory which will be compressed to squashfs module
171
# $2 = output .mo file
172
# $3 = optional -keep-as-directory argument
173
#
174
create_module()
175
{
176
   mksquashfs $1 $2 $3 >/dev/null
177
   if [ $? -ne 0 ]; then return 1; fi
178
   chmod oga-x $2 # remove execute attrib
179
}
180
 
181
# Mount .mo module to destination directory
182
# $1 = path to .mo livecd compressed module
183
# $2 = destination folder
184
#
185
mount_module()
186
{
187
   mount -t squashfs -o loop,ro $1 $2
188
}
189
 
190
# Insert a directory tree $2 to an union specified by $1
191
# Top-level read-write branch is specified by it's index 0
192
# $1 = union absolute path (starting with /)
193
# $2 = path to data directory
194
#
195
union_insert_dir()
196
{
100 beyerle@PS 197
   which unionctl >/dev/null 2>&1
198
   if [ $? -eq 0 ]; then
199
       # unionfs 1.x or aufs
200
       unionctl "$1" --add --after 0 --mode ro "$2"
201
   else
202
       # unionfs 2.x
203
       mount -t unionfs -o remount,add=:${2}=ro none "$1"
204
   fi
1 beyerle@PS 205
}
206
 
207
# List all modules in all directories (base, modules, optional)
208
# and filter out unneeded optional modules (not specified by load= kernel parameter)
209
# $1 = root directory of mounted DATAdir
210
#
211
list_modules()
212
{
213
   LOAD="`cmdline_value load`"
214
   ls -A1d $1/*.mo $1/*/*.mo 2>/dev/null | while read LINE; do
215
      MODNAME="`basename $LINE .mo`"
216
      if [ "$LOAD" != "*" -a "`echo $LINE | grep optional`" != "" -a "`echo $LOAD | egrep \"(^|,)$MODNAME(\\\$|,)\"`" = "" ]; then continue
217
        else echo $LINE; fi
218
   done
219
}
220
 
221
# Insert one single .mo module to the union
222
# $1 = union absolute path (starting with /)
223
# $2 = module.mo full path
224
# $3 = destination folder, where images will be mounted to
225
#
226
union_insert_module()
227
{
228
   TARGET="$3/`basename $2`"
229
   while [ -e $TARGET ]; do TARGET=$TARGET.X; done
230
   mkdir -p $TARGET
231
   mount_module $2 $TARGET
232
   if [ $? -ne 0 ]; then echo "can't read module data"; return 1; fi
233
   union_insert_dir $1 $TARGET; 
234
}
235
 
236
# Insert all .mo modules, in $2 directory and subdirectories, to the union
237
# $1 = union absolute path (starting with /)
238
# $2 = LiveCD data dir (with directories /base, /modules, etc.)
239
# $3 = destination folder, where images will be mounted to
240
#
241
union_insert_modules()
242
{
38 beyerle@PS 243
   PRINTK=`cat /proc/sys/kernel/printk`
244
   echo "0" >/proc/sys/kernel/printk
245
 
1 beyerle@PS 246
   list_modules $2 | while read MODULE; do
247
      echo " -> `basename $MODULE`"
248
      union_insert_module $1 $MODULE $3
249
   done
38 beyerle@PS 250
 
251
   echo "$PRINTK" >/proc/sys/kernel/printk
1 beyerle@PS 252
}
253
 
254
# Copy modules to RAM directory
255
# $1 = data directory
256
# $2 = target directory in RAM
257
#
258
copy_to_ram()
259
{
260
   cp -R $1/* $2
100 beyerle@PS 261
   if [ $? -ne 0 ]; then fatal "can't copy to RAM, not enough memory?"; fi
1 beyerle@PS 262
}
263
 
264
# Copy content of "rootcopy" directory on the CD to $2 (union, usually)
265
# $1 = source
266
# $2 = destination
267
#
268
copy_rootchanges()
269
{
270
   cp -a $1/rootcopy/* $2 2>/dev/null # could be empty
271
}
272
 
273
# ===========================================================
274
# discovery functions
275
# ===========================================================
276
 
277
# List all CD-ROMs
278
# by using /proc entries
279
#
280
list_cdrom_devices()
281
{
282
   if [ "`cmdline_parameter nocd`" != "" ]; then return 1; fi
283
   for CDDEVICE in `cat /proc/sys/dev/cdrom/info | head -n 3 | tail -n 1 | cut -d ":" -f 2`; do
284
      echo "/dev/$CDDEVICE"
285
   done
286
}
287
 
288
# List all partition devices
289
# take list of all partitions and output unique disks.
290
# Return empty result when nohd parameter was given.
291
#
292
list_partition_devices()
293
{
294
   if [ "`cmdline_parameter nohd`" != "" ]; then return 1; fi
295
   cat /proc/partitions | grep -v loop | sed -r "s/^[0-9[:space:]]+/\/dev\//" | grep /dev/
296
}
297
 
298
# List all disk devices
299
#
300
list_disk_devices()
301
{
302
   list_partition_devices | egrep -v "[0-9]"
303
}
304
 
305
# List all block devices
306
#
307
list_block_devices()
308
{
309
   list_cdrom_devices
310
   list_partition_devices
311
}
312
 
313
# Try to mount all disks, partitions and cdroms and Find where the LiveCD is.
314
# If LiveCD found in the device, echo dirname of it's directory,
315
# and leave the device mounted. Mounting is not ro, but without any argument.
316
# $1 = directory where devices will be mounted
317
# added: mount $NFSROOT to /$1/nfs if NFSROOT is set. and search there for LiveCD
318
#
319
find_live_data_dir()
320
{
321
   if [ "$NFSROOT" != "" ]; then 
322
      DIR="/$1/nfs"
323
      mkdir -p $DIR
108 beyerle@PS 324
      # try to mount nfs dir
161 beyerle@PS 325
      mount -t nfs -o $NFSOPT $NFSROOT $DIR
162 beyerle@PS 326
   fi
108 beyerle@PS 327
 
162 beyerle@PS 328
   if [ "$CIFSROOT" != "" ]; then
160 beyerle@PS 329
      DIR="/$1/cifs"
330
      mkdir -p $DIR
331
      # try to mount cifs dir
161 beyerle@PS 332
      mount -t cifs $CIFSROOT $DIR -o ro,$CIFSOPTS
162 beyerle@PS 333
   fi
160 beyerle@PS 334
 
162 beyerle@PS 335
   if [ "$DIR" = "" ]; then
336
       list_block_devices | while read DEVICE; do
337
	   DIR="/$1/`basename $DEVICE`"
338
	   mount_device $DEVICE $DIR
339
	   if [ $? -ne 0 ]; then continue; fi
167 beyerle@PS 340
	   # FOUND=`find $DIR -name livecd.sgn -type f | head -n 1`
341
	   FOUND=`ls -A1d $DIR/livecd.sgn $DIR/*/livecd.sgn 2>/dev/null | head -n 1`
162 beyerle@PS 342
	   if [ "$FOUND" = "" ]; then umount $DIR 2>/dev/null; rmdir $DIR 2>/dev/null
343
	   else dirname "$FOUND"; return 1; fi
344
       done
1 beyerle@PS 345
   else
167 beyerle@PS 346
       # FOUND=`find $DIR -name livecd.sgn -type f | head -n 1`
347
       FOUND=`ls -A1d $DIR/livecd.sgn $DIR/*/livecd.sgn 2>/dev/null | head -n 1`
162 beyerle@PS 348
       if [ "$FOUND" != "" ]; then 
349
	   dirname "$FOUND"
350
       fi
1 beyerle@PS 351
   fi
352
}
353
 
354
# ===========================================================
355
# hardware preparation functions
356
# ===========================================================
357
 
358
# Create block devices to /dev described by /sys entries
359
#
360
create_block_devices()
361
{
362
   echolog "creating /dev entries for block devices"
363
   ls -A1d /sys/block/*/dev /sys/block/*/*/dev 2>/dev/null | grep -v loop | while read BLOCK; do
364
      DEVICE="/dev/`basename \`dirname $BLOCK\``"
365
      if [ ! -b $DEVICE ]; then
366
         MINORMAJOR="`head -n 1 $BLOCK | tr ':' ' '`"
367
         mknod $DEVICE b $MINORMAJOR
368
      fi
369
   done
370
}
371
 
372
# modprobe kernel modules needed for the LiveCD
373
#
374
modprobe_essential_modules()
375
{
376
   echolog "starting loop device support"
109 beyerle@PS 377
   modprobe_module loop max_loop=32
1 beyerle@PS 378
   echolog "starting cdrom support"
379
   modprobe_module ide_cd
380
   modprobe_module ide-cd
381
   modprobe_module sr_mod
382
   modprobe_module cdrom
383
   echolog "starting cdrom filesystem support"
384
   modprobe_module isofs
385
   echolog "starting squashfs support"
386
   modprobe_module squashfs
37 beyerle@PS 387
   echolog "starting unionfs/aufs support"
1 beyerle@PS 388
   modprobe_module unionfs
37 beyerle@PS 389
   modprobe_module aufs
1 beyerle@PS 390
   echolog "starting vfat support"
120 beyerle@PS 391
   # modprobe_module nls_cp437
392
   # modprobe_module nls_iso8859-1
393
   # modprobe_module nls_iso8859-2
1 beyerle@PS 394
   modprobe_module vfat
395
   echolog "starting ntfs support"
396
   modprobe_module ntfs
166 beyerle@PS 397
   modprobe_module nls_utf8
1 beyerle@PS 398
   create_block_devices
399
}
400
 
401
 
402
# modprobe kernel modules needed for USB masstorage devices
403
#
404
modprobe_usb_sata_modules()
405
{
406
   echolog "starting USB and SATA support"
407
   modprobe_module ehci-hcd
408
   modprobe_module ohci-hcd
409
   modprobe_module uhci-hcd
410
   modprobe_module scsi_mod
411
 
412
   modprobe_module libata
85 beyerle@PS 413
   modprobe_module ata_piix
1 beyerle@PS 414
   modprobe_module ahci
126 beyerle@PS 415
   modprobe_module sata_nv
116 beyerle@PS 416
   modprobe_module sg
1 beyerle@PS 417
 
418
   modprobe_module sd_mod
419
   modprobe_module sr_mod
420
   modprobe_module usb-storage
163 beyerle@PS 421
   echolog "waiting for USB devices, max 8 seconds"
422
   sleep 8
1 beyerle@PS 423
   create_block_devices
424
}
425
 
426
# modprobe nfs kernel modules
427
#
428
modprobe_nfs_modules()
429
{
430
   echolog "starting nfs support"
431
   modprobe_module lockd
432
   modprobe_module fscache
433
   modprobe_module nfs_acl
434
   modprobe_module nfs
435
}
436
 
160 beyerle@PS 437
# modprobe cifs kernel module
438
#
439
modprobe_cifs_modules()
440
{
441
  echolog "starting cifs support"
442
  modprobe_module cifs
443
}
444
 
1 beyerle@PS 445
# enable/disable CD autoejecting when unmounted
446
# $1 = 1|0 ... enable|disable
447
#
448
cd_autoeject()
449
{
450
   echo $1 >/proc/sys/dev/cdrom/autoeject
451
}
452
 
453
# Disable DMA if nodma boot parameter is present
454
#
455
setup_dma()
456
{
457
   if [ ! "`cmdline_parameter nodma`" = "" ]; then
458
      for DEVICE in `list_cdrom_devices` `list_disk_devices`; do
459
         echolog "setting DMA support off for $DEVICE"
460
         hdparm -d 0 $DEVICE
461
      done
462
   fi
463
}
464
 
465
# create correct fstab file in $1/etc/fstab and create apropriate
466
# mount directories in $1
467
# $1 = root directory (union)
468
#
469
activate_fstab()
470
{
471
   mkdir -p $1/etc
472
   FSTAB="$1/etc/fstab"
473
   echo "tmpfs            /                tmpfs       defaults         0   0" >$FSTAB
474
   echo "devpts           /dev/pts         devpts      gid=5,mode=620   0   0" >>$FSTAB
475
   echo "proc             /proc            proc        defaults         0   0" >>$FSTAB
476
 
48 beyerle@PS 477
   # all the rest will be done by runlast or by fstab-sync
478
   # search for SWAP done later in /etc/rc.sysinit
479
}
1 beyerle@PS 480
 
481
 
173 beyerle@PS 482
# find partition and/or folder that stores the changes
170 beyerle@PS 483
# return false, if changes not set or changes folder/partition not found
484
find_changes()
485
{
173 beyerle@PS 486
    echolog "looking for changes on $CHANGESVAL"
170 beyerle@PS 487
 
488
    CHANGESDEV="`echo "$CHANGESVAL" | egrep -o "^/dev/[^/]+"`"
489
    CHANGESFOLDER="`echo "$CHANGESVAL" | sed -r 's:^/dev/[^/]+(.*):\1:'`"
490
    # (re-)define CHANGES if CHANGESFOLDER is set
491
    if [ "$CHANGESFOLDER" != "" ]; then CHANGES=$MEMORY/$CHANGESFOLDER; fi
492
 
173 beyerle@PS 493
    # we may need usb and sata support
170 beyerle@PS 494
    modprobe_usb_sata_modules
495
 
496
    # device defined?
497
    if [ "$CHANGESDEV" != "" ]; then
498
	mount_device $CHANGESDEV $MEMORY
499
	return
500
    fi 
501
 
502
    # if no device is specified, search all devices for folder CHANGESFOLDER
503
    list_block_devices | while read DEVICE; do
504
	mount_device $DEVICE $MEMORY
505
	if [ $? -ne 0 ]; then continue; fi
173 beyerle@PS 506
	FOUND_FOLDER=`ls -1d $MEMORY/$CHANGESFOLDER 2>/dev/null`
170 beyerle@PS 507
	if [ "$FOUND_FOLDER" = "" ]; then 
508
	    umount $MEMORY 2>/dev/null
509
	else
510
	    echo "found folder $CHANGESFOLDER on $DEVICE"
511
	    return
512
	fi
513
    done
514
}
515
 
516
 
48 beyerle@PS 517
# ===========================================================
518
# functions used for LiveCD on NFS 
519
# ===========================================================
1 beyerle@PS 520
 
37 beyerle@PS 521
# load network modules, if NFSROOT is set
169 beyerle@PS 522
# Urs Beyerle
48 beyerle@PS 523
#
100 beyerle@PS 524
 
147 beyerle@PS 525
# network devices found ?
526
#
527
found_nic()
528
{
529
    found="1"
530
    for iface in eth0 eth1 eth2 eth3 eth4 eth5; do
531
	# nic already found ?
532
	echo $FOUND_IFACE | grep -q $iface 
533
	if [ $? -ne 0 ]; then
534
	    ifconfig $iface > /dev/null 2>&1
535
	    if [ $? -eq 0 ]; then 
536
		FOUND_IFACE="$FOUND_IFACE $iface"
537
		found="0"
538
	    fi
539
	fi
540
    done
541
    return $found
542
}
543
 
104 beyerle@PS 544
# 1. load network driver defined by kernel parameter nic
545
#
546
load_network_module_nic()
37 beyerle@PS 547
{
147 beyerle@PS 548
    NIC="`cmdline_value nic`"
549
    if [ -n "$NIC" ]; then
100 beyerle@PS 550
	echolog "load module $NIC"
104 beyerle@PS 551
	modprobe_module $NIC
100 beyerle@PS 552
    fi
104 beyerle@PS 553
}
100 beyerle@PS 554
 
555
 
147 beyerle@PS 556
# 2. auto probe for network card drivers
104 beyerle@PS 557
#
558
load_network_module_auto()
559
{
560
    echolog "auto-detection of network driver ..."
147 beyerle@PS 561
    FOUND_NICS=""
104 beyerle@PS 562
    KERNEL="`uname -r`"
563
    NETDRIVERS="`find /lib/modules/$KERNEL/kernel/drivers/net | grep -v mii | grep .ko | cut -d"/" -f8 | cut -d"." -f1 | uniq`"
564
    for driver in $NETDRIVERS; do
148 beyerle@PS 565
       	modprobe_module $driver > /dev/null 2>&1
147 beyerle@PS 566
	found_nic
567
	if [ $? -eq 0 ]; then
568
	    echolog "found network card $driver"
569
	    echolog "load module $driver"
570
	    FOUND_NICS="$FOUND_NICS $driver"
571
	else
572
	    rmmod $driver > /dev/null 2>&1
573
	fi
104 beyerle@PS 574
    done
575
 
576
    # clean up: remove unused modules until driver "mii"
147 beyerle@PS 577
    LOADED_DRIVERS="`lsmod | grep -v Module | cut -d" " -f1`"
104 beyerle@PS 578
    for driver in $LOADED_DRIVERS; do
579
	[ "$driver" = "mii" ]  && break
580
	[ "$driver" = "ntfs" ] && break
581
	[ "$driver" = "vfat" ] && break
147 beyerle@PS 582
	do_not_remove=""
583
	for nic in $FOUND_NICS; do
584
	    echo $driver | grep -q $nic 
585
	    [ $? -eq 0 ] && do_not_remove="$driver"
586
	done
148 beyerle@PS 587
	[ ! $do_not_remove ] && rmmod $driver > /dev/null 2>&1
104 beyerle@PS 588
    done
37 beyerle@PS 589
}
590
 
147 beyerle@PS 591
# 3. detecting network card from pcitable list
592
#
593
load_network_module_pcitable()
594
{
595
    PCITABLE=/bin/pcitable
596
    NICS=`lspci -n | awk '/Class 0200/ {print $4}' | tr ':' ' ' \
597
	| while read x y ; do grep "0x$x.*0x$y" $PCITABLE \
598
	| awk '$3 !~ /"unknown"/ {print $3}' | tr -d '"' ; done`
599
 
600
    if [ -n "$NICS" ]; then
601
	echolog "found network card(s): $NICS"
602
	for driver in $NICS; do
603
	    echolog "load module $driver"
604
	    modprobe_module $driver
605
	done
606
    fi
607
}
608
 
104 beyerle@PS 609
# 4. ask the user for a network driver
610
#
611
load_network_module_ask()
612
{
613
    echo "ERROR: No network card detected!"
614
    echo "Type in your network card driver (e.g. tg3, e1000). "
615
    echo "Or ask your system administrator for help."
616
    echo -n "Network card driver: "
617
    read driver
148 beyerle@PS 618
    echo "load module $driver"
104 beyerle@PS 619
    modprobe_module $driver
620
}
621
 
622
# Try to find a network driver
623
#
624
load_network_modules()
625
{
163 beyerle@PS 626
    echolog "load network modules"
627
 
147 beyerle@PS 628
    # mii maybe need by NIC driver
104 beyerle@PS 629
    modprobe_module mii
630
 
147 beyerle@PS 631
    FOUND_IFACE=""
104 beyerle@PS 632
    load_network_module_nic
149 beyerle@PS 633
    found_nic          || load_network_module_auto
148 beyerle@PS 634
    [ "$FOUND_IFACE" ] || load_network_module_pcitable
635
    [ "$FOUND_IFACE" ] || load_network_module_ask
104 beyerle@PS 636
 
637
    # remove mii, if not needed
638
    rmmod mii > /dev/null 2>&1
639
}
640
 
147 beyerle@PS 641
 
37 beyerle@PS 642
# get DHCP lease
169 beyerle@PS 643
# Urs Beyerle
48 beyerle@PS 644
#
37 beyerle@PS 645
get_dhcp_lease()
646
{
647
    # create /dev/urandom (needed by udhcpc)
648
    mknod /dev/urandom c 1 9
147 beyerle@PS 649
 
650
    for iface in eth0 eth1 eth2 eth3 eth4 eth5; do
651
	# interface up ?
652
	ifconfig $iface > /dev/null 2>&1
653
	if [ $? -eq 0 ]; then
148 beyerle@PS 654
	    # get dhcp lease
655
	    echolog "try to get DHCP lease on $iface"
656
	    udhcpc --now --quit --interface=$iface --script=/bin/udhcpc.script
657
	    [ $? -eq 0 ] && return
658
	    echo "ERROR: couldn't get DHCP lease on $iface."
147 beyerle@PS 659
	fi
102 beyerle@PS 660
    done
37 beyerle@PS 661
}