Subversion Repositories livecd

Rev

Rev 246 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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