Subversion Repositories livecd

Rev

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

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