Subversion Repositories livecd

Rev

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

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