source: MondoRescue/branches/stable/mindi/mindi@ 1530

Last change on this file since 1530 was 1530, checked in by Bruno Cornec, 17 years ago

Support for swap with UUID on VMWare ESX 3 at least with dumpuuid

  • Property svn:keywords set to Rev Id
File size: 115.6 KB
Line 
1#!/bin/bash
2
3# $Id: mindi 1530 2007-07-06 14:36:26Z bruno $
4#
5#-----------------------------------------------------------------------------
6# mindi - mini-Linux distro based on the user's filesystem & distribution
7#
8# Mindi can create a multi-floppy boot/root kit. The first floppy is the boot
9# disk: it contains a kernel, a ramdisk etc. The second disk is data disk #1;
10# the third disk is data disk #2; and so it goes.
11#
12# See http://www.mondorescue.org for details.
13#-----------------------------------------------------------------------------
14
15### Which arch are we on (useful for ia64 port)
16ARCH=`/bin/arch`
17
18#RUN_AFTER_INITIAL_BOOT_PHASE="echo \"Who lives in a pineapple under the sea?\" > /tmp/spongebob.squarepants.txt"
19 # after booting from floppy/CD image but before
20 # accessing auxiliary data disks (or the rest of
21 # the CD), the initscript will run the above command.
22
23RUN_AFTER_BOOT_PHASE_COMPLETE="ide-opt"
24 # after the emergency boot process is complete but
25 # before the init script runs mondorestore, it will
26 # run this command.
27
28MINDI_REV=RRR
29MINDI_VER=VVV
30
31MINDI_VERSION=${MINDI_VER}-r$MINDI_REV
32MINDI_PREFIX=XXX
33MINDI_CONF=YYY
34MINDI_SBIN=${MINDI_PREFIX}/sbin
35MINDI_LIB=LLL
36
37MINDI_CONFIG_DIST="$MINDI_CONF/mindi.conf.dist"
38if [ ! -f $MINDI_CONFIG_DIST ]; then
39 echo "Unable to find $MINDI_CONFIG_DIST. Please reinstall mindi"
40 exit -1
41fi
42md5sum --status -c "$MINDI_CONF/mindi.conf.dist.md5"
43if [ $? -ne 0 ]; then
44 echo "$MINDI_CONF/mindi.conf.dist md5 checksum incorrect. Please reinstall mindi"
45 exit -1
46fi
47. $MINDI_CONFIG_DIST
48
49MINDI_CONFIG="$MINDI_CONF/mindi.conf"
50if [ ! -f $MINDI_CONFIG ] && [ "_$1" = "_" ]; then
51 echo "No $MINDI_CONFIG file found using sensible values from $MINDI_CONFIG_DIST"
52else
53 if [ "_$1" = "_" ]; then
54 echo "Using $MINDI_CONFIG as additional config file to $MINDI_CONFIG_DIST"
55 fi
56 . $MINDI_CONFIG
57fi
58
59#
60# Manages defaults coming from conf files
61#
62INTERACTIVE="$mindi_interactive"
63
64if [ "$INTERACTIVE" = "yes" ]; then
65 # do you want to be prompted to write
66 # floppy images out to floppy disks?
67 # if 'no', images will not be written to floppies
68 PROMPT_WRITE_BOOT_FLOPPIES="yes"
69
70 # Ask if you want to make a CD Image to be written?
71 # if this is set to 'no', then the image will be created automatically
72 PROMPT_MAKE_CD_IMAGE="yes"
73
74 # Ask if you want to make a USB Image to be written?
75 # if this is set to 'no', then the image will be created automatically
76 PROMPT_MAKE_USB_IMAGE="yes"
77
78 # If set to "no", you will be prompted for whether or not
79 # you want to use your own kernel, or the supplied default.
80 # If "yes" mindi will automatically use your own kernel.
81 USE_OWN_KERNEL="no"
82fi
83
84EXTRA_SPACE=$mindi_extra_space
85BOOT_SIZE=$mindi_boot_size
86DEPLIST_DIR="$MINDI_CONF/deplist.d"
87DEPLIST_FILE="$MINDI_CONF/$mindi_deplist_file"
88WRITE_BOOT_FLOPPIES="$mindi_write_boot_floppy"
89PROMPT_MAKE_CD_IMAGE="$mindi_write_cd"
90PROMPT_MAKE_USB_IMAGE="$mindi_write_usb"
91PROMPT_MAKE_TAPE_IMAGE="$mindi_write_tape"
92USE_OWN_KERNEL="$mindi_use_own_kernel"
93MINDI_CACHE="$mindi_cache_dir"
94FORCE_DUAL_FLOPPIES="$mindi_dual_floppies"
95TMPDIR="$mindi_tmp_dir"
96FDDEVICE="$mindi_fd_device"
97USBDEVICE="$mindi_usb_device"
98TAPEDEV="$mindi_tape_device"
99ADDITIONAL_BOOT_PARAMS="$mindi_boot_params"
100MY_FSTAB="$mindi_etc_fstab"
101LOGFILE="$mindi_log_file"
102FLOPPY_MODS="$mindi_floppy_mods"
103TAPE_MODS="$mindi_tape_mods"
104SCSI_MODS="$mindi_scsi_mods"
105IDE_MODS="$mindi_ide_mods"
106PCMCIA_MODS="$mindi_pcmcia_mods"
107USB_MODS="$mindi_usb_mods"
108CDROM_MODS="$TAPE_MODS $FLOPPY_MODS $IDE_MODS $mindi_cdrom_mods $USB_MODS $PCMCIA_MODS"
109NET_MODS="$mindi_net_mods"
110EXTRA_MODS="$CDROM_MODS $mindi_extra_mods $mindi_additional_mods"
111DENY_MODS="mindi_deny_mods"
112FORCE_MODS="mindi_force_mods"
113
114BOOT_MEDIA_MESSAGE="$mindi_boot_msg"
115FDISK=$MINDI_SBIN/parted2fdisk
116
117# Now we can create what we need
118export MINDI_TMP=`mktemp -d $TMPDIR/mindi.XXXXXXXXXX`
119
120# ----------------------------------------------------------------------------
121
122
123AbortHere() {
124 [ "$mountpoint" ] && umount $mountpoint 2>> $LOGFILE
125 Die "Program is terminating in response to signal received from OS/user"
126}
127
128
129HackSyslinuxFile() {
130 local incoming
131 incoming=`ReadLine`
132 while [ "$incoming" ] ; do
133 echo -en "$incoming" | sed s/24000/$1/
134 if [ "`echo "$incoming" | grep append`" ] ; then
135 echo -en " $ADDITIONAL_BOOT_PARAMS"
136 fi
137 echo -en "\n"
138 incoming=`ReadLine`
139 done
140 if [ -e "$MINDI_LIB/memtest.img" ] ; then
141 echo -en "label memtest\n kernel memdisk\n append initrd=memtest.img\n\n"
142 fi
143}
144
145
146Aborted() {
147 trap SIGHUP SIGTERM SIGTRAP SIGINT
148 [ "$MINDI_CACHE" != "" ] && rm -f $MINDI_CACHE/mindi*img $MINDI_CACHE/*gz $MINDI_CACHE/mindi.iso
149 [ "$minidir_root" != "" ] && rm -Rf $minidir_root/*
150 Die "User abort."
151}
152
153
154AddFileToDir() {
155 local filename minidir_root noof_disks diskno res filesize disksize would_occupy zipsize complevel cutoff compressed_fname siz
156 filename=$1
157 minidir_root=$2
158 noof_disks=$3
159
160 diskno=$noof_disks
161 mkdir -p $minidir_root/$diskno
162 [ "$LAST_COMPRESSED_SIZE" = "" ] && LAST_COMPRESSED_SIZE=0
163 if [ ! -e "$filename" ] ; then
164 if [ -h "$filename" ] ; then
165 cp --parents -pRdf $filename $minidir_root/$diskno 2>> $LOGFILE
166 return $noof_disks
167 else
168 Die "AddFileToDir asked me to add $filename, which does not exist. Oops! Did you run out of disk space or is your Linux distro severely broken?"
169 fi
170 fi
171
172 # move to the disk that has room on it (or end up using the last, if all full)
173 while [ "$diskno" -lt "40" ] ; do
174 mkdir -p $minidir_root/$diskno
175 filesize=`du -sk $filename | cut -f1`
176 cp --parents -Rdf $filename $minidir_root/$diskno 2>> $LOGFILE
177 if [ "$filesize" -le "4" ] ; then
178 siz=$filesize
179 elif [ ! -f "$filename" ] ; then
180 siz=0
181 else
182 siz=`grep -m 1 "$filename.gz$" $minidir_root/compressed/compressed.txt | cut -f1`
183 [ "$siz" = "" ] && Die "FIXME - can't find $filename's size."
184 siz=$(($siz-2));# to allow for sectors & the fact that they round up
185 fi
186 [ ! "$siz" ] && siz=4
187 [ "$siz" -lt "0" ] && siz=0
188 LAST_COMPRESSED_SIZE=$(($LAST_COMPRESSED_SIZE+$siz))
189 [ "$LAST_COMPRESSED_SIZE" -le "$MAX_COMPRESSED_SIZE" ] &&return $diskno
190 echo "disk=$diskno siz=$LAST_COMPRESSED_SIZE" >> $LOGFILE
191 LAST_COMPRESSED_SIZE=0
192 rm -f $minidir_root/$diskno/$filename
193 diskno=$(($diskno+1))
194 done
195 return 0 ; # failed
196}
197
198
199AddKeyboardMappingFile() {
200 local mappath r included_list included_item i res ii sss
201 mappath=$1
202 KBDEPTH=$(($KBDEPTH+1))
203 [ "$KBDEPTH" -gt "128" ] && Die "Edit $MINDI_SBIN/mindi and disable FindAndAddUserKeyboardMappingFile (line 2160, approx.)"
204 if [ -e "$bigdir/$mappath" ] ; then
205 echo "$mappath already added" >> $LOGFILE
206 return
207 elif [ -d "$bigdir/$mappath" ] ; then
208 echo "Cannot add $mappath: it's a directory. Sorry."
209 return
210 fi
211 echo "Added kbd map $mappath" >> $LOGFILE
212 if [ ! -e "$mappath" ] ; then
213 mappath=`grep "i[3-8]86" $MINDI_TMP/keymaps.find | grep "$locale[^r][^/]" | grep -vx " *#.*"`
214 if [ ! -e "$mappath" ] ; then
215 LogIt "Cannot add $mappath: kbd map file not found"
216 return
217 fi
218 else
219 echo -en "`basename $mappath | tr '.' '#' | sed s/#kmap#gz// | sed s/#inc#gz//` " | tr '#' '.'
220 fi
221
222 mkdir -p $bigdir/etc
223 cp --parents -pRdf $mappath $bigdir 2>> $LOGFILE || LogIt "AKMF -- Could not copy $mappath to $bigdir"
224 if [ "`echo $mappath | grep -F ".gz"`" ] ; then
225 included_list=`gzip -dc $mappath | grep -Fi include | sed s/'"'// | sed s/'"'// | cut -d' ' -f2`
226 else
227 included_list=`grep -Fi include $mappath | sed s/'"'// | sed s/'"'// | cut -d' ' -f2`
228 fi
229 for included_item in $included_list ; do
230 if [ ! -e "$included_item" ] ; then
231 sss=`grep -F "${included_item}.inc" $MINDI_TMP/keymaps.find`
232 [ "$sss" = "" ] && sss=`grep -F "$included_item" $MINDI_TMP/keymaps.find`
233 for ii in $sss ; do
234 [ -e "$ii" ] && AddKeyboardMappingFile $ii
235 done
236 else
237 AddKeyboardMappingFile $included_item
238 fi
239 done
240}
241
242
243ChopUpAndCopyFile() {
244 local filename slicesize outdir res biggienumber filesize sliceno noof_slices testfile scratchfile
245 filename=$1
246 outdir=$2
247 slicesize=$3
248 biggienumber=$4
249
250 [ -d "$filename" ] && Die "Cannot chop up $filename: it's a directory. Please amend $DEPLIST_FILE accordingly."
251 mkdir -p $outdir
252
253 sliceno=0
254 scratchfile=$MINDI_TMP/blah.$$.dat
255 cp -f $filename $scratchfile 2>> $LOGFILE || Die "CUACF -- cannot copy $filename to $scratchfile - did you run out of disk space?"
256 [ "`head $scratchfile -n1 | grep -F "bin/sh"`" != "" ] && StripComments $scratchfile "-$filename-"
257 [ "`echo "$filename" | grep -F "etc/termcap"`" != "" ] && StripComments $scratchfile "-$filename-"
258 if [ "`echo "$filename" | grep -F "lib/modules/" | grep "\.*o\.gz"`" != "" ] ; then
259 mv $scratchfile $scratchfile.gz
260 gunzip -f $scratchfile || LogIt "Cannot gunzip $scratchfile.gz"
261 filename=`echo "$filename" | tr '.' '#' | sed s/#o#gz/#o/ | sed s/#ko#gz/#ko/ | tr '#' '.'`
262 fi
263 filesize=`du -sk $scratchfile | cut -f1`
264 noof_slices=$(($filesize/$slicesize))
265 echo "$filename" > $outdir/slice-$biggienumber.name
266 echo "$filesize" > $outdir/slice-$biggienumber.size
267 [ -x "$scratchfile" ] && StripExecutable $scratchfile "-$filename-"
268 while [ "$sliceno" -le "$noof_slices" ] ; do
269 dd if=$scratchfile skip=$(($sliceno*$slicesize)) of=$outdir/slice-$biggienumber.`printf "%03d" $sliceno` bs=1k count=$slicesize &> /dev/null
270 sliceno=$(($sliceno+1))
271 done
272 rm -f $scratchfile
273}
274
275
276CopyBootBFile() {
277 local copy_to copy_from possible_locations liloc
278 copy_to=$1
279 copy_from=/boot/boot.b
280 liloc=`which lilo.real 2>/dev/null`
281 [ $liloc ] || liloc=`which lilo 2>/dev/null`
282 if [ $liloc ]; then
283 if ! [ `strings $liloc | grep "boot\.b"` ]; then
284 LogIt "boot.b files built into lilo; I'll create a dummy."
285 > $copy_to
286 return 0
287 fi
288 fi
289 if [ ! -f "$copy_from" ] ; then
290 LogIt "OK, you don't have a /boot/boot.b file, which is odd because\n most _good_ Linux distributions come with one, even if it's only a softlink"
291 copy_from=`grep install= /etc/lilo.conf | grep "\.b" | cut -d'=' -f2`
292 if [ ! -f "$copy_from" ] ; then
293 LogIt "Nor can I find it from your /etc/lilo.conf file. This is very odd."
294 copy_from=`FindSensibleBootBFile`
295 LogIt "I'm going to use '$copy_from'"
296 fi
297 fi
298 cp -f $copy_from $copy_to 2>> $LOGFILE || LogIt "CBBF -- warning -- cannot find your boot.b file. That's it, I quit... (j/k)"
299}
300
301
302CopyDependenciesToDirectory() {
303 local outdir incoming fname filesize counter d found
304 outdir=$1
305 mkdir -p $outdir
306 incoming=`ReadLine`
307 counter=0
308 while [ "$incoming" != "" ] ; do
309 # Non absolute file names should not arrive till here => skipped
310 if [ `echo "$incoming" | cut -c1` != '/' ]; then
311 LogIt "Unable to handle $incoming"
312 incoming=`ReadLine`
313 continue
314 fi
315 # no parent directory of incoming should be a link, copy is not possible in that case
316 d=`dirname "$incoming"`
317 found="false"
318 while [ $d != "/" -a $found = "false" ]; do
319 [ -h "$d" ] && found="true"
320 d=`dirname "$d"`
321 done
322 if [ -d "$incoming" ] && [ ! -h "$incoming" ]; then
323 find $incoming/* -maxdepth 0 2> /dev/null | CopyDependenciesToDirectory $outdir
324 elif [ -e "$incoming" ] && [ $found = "false" ]; then
325 filesize=`du -sk $incoming | cut -f1`
326 if [ "$filesize" -gt "$(($CHOPSIZE*2))" ] && [ ! -h "$incoming" ] ; then
327 ChopUpAndCopyFile $incoming $outdir $CHOPSIZE $BIGNO
328 BIGNO=$(($BIGNO+1))
329 else
330 cp --parents -Rdf $incoming $outdir 2> /dev/null || Die "Cannot copy $incoming to $outdir - did you run out of disk space?"
331 if [ "`echo "$incoming" | grep "lib/modules/.*\..*o\.gz"`" != "" ] ; then
332 gunzip -f $outdir/$incoming || LogIt "Cannot gunzip $outdir/$incoming"
333 fi
334 [ -x "$outdir" ] && StripExecutable $outdir "-$filename-"
335 fi
336 counter=$(($counter+1))
337 if [ "$counter" -ge "5" ] ; then
338 counter=0
339 echo -en "."
340 fi
341 fi
342 incoming=`ReadLine`
343 done
344}
345
346
347CopyImageToDisk() {
348 local image dev procno res comment
349 image=$1
350 dev=$2
351 comment=$3
352 [ ! -f "$image" ] && [ ! -b "$image" ] && Die "Image $image does not exist. Did you run out of disk space?"
353 Prompt "About to write $comment. Please press ENTER."
354 echo -en "Formatting disk..."
355 if which fdformat > /dev/null ; then
356 fdformat -n $dev > /dev/null 2> /dev/null || Die "Cannot format $dev - is your Linux distro broken?"
357 elif which superformat > /dev/null ; then
358 superformat $dev > /dev/null 2> /dev/null || Die "Cannot format $dev - is your Linux distro broken?"
359 else
360 Die "Please install either fdformat or superformat."
361 fi
362 echo -en "\nWriting $comment"
363 if echo $image | grep "mindi-[r|b]oot\.1440" &> /dev/null ; then
364 cat $image > $dev &
365 else
366 dd if=$image of=$dev &> /dev/null &
367 fi
368 procno=$!
369 ps $procno > /dev/null 2> /dev/null
370 while [ "$?" -eq "0" ] ; do
371 sleep 3
372 echo -en "."
373 ps $procno > /dev/null 2> /dev/null
374 done
375 echo -e "$DONE"
376 LogIt "$comment has been written."
377}
378
379
380CountItemsIn() {
381 local r
382 r=0
383 for q in $1 ; do
384 r=$(($r+1))
385 done
386 echo $r
387}
388
389
390CreateDataDiskImagesFromTarballs() {
391 local tardir outdir diskno noof_disks kp
392 tardir=$1
393 outdir=$2
394 noof_disks=$3
395
396 mkdir -p $outdir
397 diskno=1
398 echo -en "Creating data disk "
399 while [ "$diskno" -le "$noof_disks" ] ; do
400 echo -en "#$diskno..."
401 cp -f $tardir/$diskno.tar.gz $outdir 2>> $LOGFILE || LogIt "[line 424] Cannot copy $tardir/$diskno.tar.gz to $outdir"
402 CreateOneDataDiskImage $tardir/$diskno.tar.gz $outdir/mindi-data-$diskno.img $diskno $noof_disks
403 diskno=$(($diskno+1))
404 done
405 mv -f $tardir/all.tar.gz $outdir
406 du -sk $outdir/*gz >> $LOGFILE
407 echo -e "$DONE"
408}
409
410
411
412CreateOneDataDiskImage() {
413 local tarball imagefile dev diskno noof_disks mountpoint
414 tarball=$1
415 imagefile=$2
416 diskno=$3
417 noof_disks=$4
418
419 mountpoint=$MINDI_TMP/mountpoint.$$
420 mkdir -p $mountpoint
421 dd if=/dev/zero of=$imagefile bs=1k count=1440 &> /dev/null || LogIt "Cannot dd (CODI)"
422 echo "Creating ext2 filesystem on $imagefile" >> $LOGFILE
423 mke2fs -N 12 -F $imagefile &> /dev/null || Die "Unable to create an ext2 file system on $imagefile"
424 mount -t ext2 -o loop $imagefile $mountpoint || Die "Can't loopmount $imagefile to $mountpoint! The reason may be missing support for loopfs or ext2 (or both) in the running kernel."
425 mv $tarball $mountpoint/
426 if [ "$?" -ne "0" ] ; then
427 umount $mountpoint
428 rmdir $mountpoint
429 Die "Tarball $tarball is too big for disk! (CODI)\nAdjust mindi_max_compressed_size in your $MINDI_CONFIG"
430 fi
431 [ "$diskno" -eq "$noof_disks" ] && echo "This is the last disk ($diskno=$noof_disks)" >> $mountpoint/LAST-DISK
432 umount $mountpoint || LogIt "Cannot umount (CODI)"
433 rmdir $mountpoint || LogIt "Cannot rmdir (CODI)"
434}
435
436# Last function called before exiting
437# Parameter is exit code value
438MindiExit() {
439 local my_partitions
440
441 echo "Mindi $MINDI_VERSION is exiting" >> $LOGFILE
442 echo "End date : `date`" >> $LOGFILE
443 if [ _"$MONDO_SHARE" != _"" ] ; then
444 echo "------------- mindi logfile included -------------------------" >> /var/log/mondoarchive.log
445 cat $LOGFILE >> /var/log/mondoarchive.log
446 echo "--------------------------------------------------------------">> /var/log/mondoarchive.log
447 fi
448
449 sync
450 cd /
451
452 # Unmount whtat could remain mounted
453 my_partitions=`mount | grep -F $$ | cut -f1 -d' '`
454 [ "$my_partitions" != "" ] && umount $my_partitions
455 # Clean temporary files only when standalone mindi
456 if [ _"$MINDI_TMP" != _"$MONDO_TMP" ]; then
457 rm -Rf $MINDI_TMP
458 fi
459 exit $1
460}
461
462Die() {
463 local i
464 if [ "$1" = "" ] ; then
465 LogIt "FATAL ERROR"
466 else
467 LogIt "FATAL ERROR. $1"
468 fi
469
470 LogIt "Please e-mail a copy of $LOGFILE to the mailing list."
471 LogIt "See http://www.mondorescue.org for more information."
472 LogIt "WE CANNOT HELP unless you enclose that file.\n"
473 MindiExit -1
474}
475
476
477DropOptimizedLibraries() {
478 local outdir filelist list_of_optimized_libraries optimized_lib_name vanilla_lib_name reason msg resolved res
479 filelist=$1
480 outdir=$2
481
482 list_of_optimized_libraries=`grep "lib/i[5-7]86/" $filelist`
483 if [ "$list_of_optimized_libraries" = "" ] ; then
484 return 0
485 fi
486 echo -en "Dropping i686-optimized libraries if appropriate"
487 for optimized_lib_name in $list_of_optimized_libraries ; do
488 echo -en "."
489 reason=""
490 vanilla_lib_name=`echo "$optimized_lib_name" | sed -e 's/i[5-7]86//' -e 's/cmov//' -e 's/nosegneg//' | tr -s '/' '/'`
491 echo "$vanilla_lib_name" >> $filelist
492 resolved=$vanilla_lib_name
493 echo "Adding $resolved to filelist" >> $LOGFILE
494 resolved=`ReadAllLink $resolved`
495 echo "Adding $resolved to filelist" >> $LOGFILE
496 mkdir -p $outdir$optimized_lib_name > /dev/null 2> /dev/null
497 rmdir $outdir$optimized_lib_name > /dev/null 2> /dev/null
498 ln -sf $vanilla_lib_name $outdir$optimized_lib_name
499 echo "Excluding $optimized_lib_name" >> $LOGFILE
500 grep -Fvx "$optimized_lib_name" "$filelist" > $filelist.tmp
501 echo "Replacing it with $vanilla_lib_name" >> $LOGFILE
502 echo "$vanilla_lib_name" >> $filelist.tmp
503 mv -f $filelist.tmp $filelist
504 done
505 $AWK '{ print $1; }' $filelist | sort -u > $filelist.tmp
506 mv -f $filelist.tmp $filelist
507 echo -e "$DONE"
508}
509
510
511FindAndAddUserKeyboardMappingFile() {
512 local r res mapfile mappath included_item included_list keyfile mp locale
513 LogIt "Analyzing your keyboard's configuration."
514 KEYDIR=/lib/kbd
515 [ ! -e "$KEYDIR" ] && KEYDIR=/usr/share/kbd # Slackware
516 [ ! -e "$KEYDIR" ] && KEYDIR=/usr/lib/kbd
517 [ ! -e "$KEYDIR" ] && KEYDIR=/usr/share
518 if [ ! -e "$KEYDIR" ] ; then
519 LogIt "Keyboard mapping directory not found. I shall use default map at boot-time."
520 return 0
521 fi
522 if [ -e "/etc/sysconfig/keyboard" ] ; then
523 echo "Red Hat-style config detected." >> $LOGFILE
524 keyfile=/etc/sysconfig/keyboard
525 elif [ -e "/etc/rc.d/rc.keymap" ] ; then
526 echo "Slackware-style config detected." >> $LOGFILE
527 keyfile=/etc/rc.d/rc.keymap
528 elif [ -e "/etc/rc.config" ] ; then
529 echo "Debian-style config detected." >> $LOGFILE
530 keyfile=/etc/rc.config
531 elif [ -e "/etc/console/boottime.kmap.gz" ] ; then
532 echo "Debian-style config detected." >> $LOGFILE
533 echo -en "Adding the following keyboard mapping tables: "
534 mkdir -p $bigdir/tmp
535 echo "keymap-lives-here=/etc/console/boottime.kmap.gz" >> $MINDI_TMP/mondo-restore.cfg
536 KBDEPTH=0
537 mkdir -p $bigdir/etc/console
538 cp /etc/console/boottime.kmap.gz $bigdir/etc/console 2>> $LOGFILE
539 echo -e "$DONE"
540 return 0
541 elif [ -e "/etc/conf.d/keymaps" ] ; then
542 echo "Gentoo-style config detected." >> $LOGFILE
543 keyfile=/etc/conf.d/keymaps
544 else
545 echo -en "Searching for rc.config ..."
546 keyfile=`find /etc -name rc.config | head -n1`
547 if [ "$keyfile" = "" ] || [ ! -e "$keyfile" ] ; then
548 LogIt "Unknown config detected. Default keyboard map will be used."
549 return
550 else
551 echo "Found $keyfile" >> $LOGFILE
552 fi
553 fi
554 if [ ! -e "$KEYDIR/keymaps" ] ; then
555 LogIt "Keyboard mapping directory not found. Default keyboard map will be used."
556 return
557 fi
558 echo "keyfile=$keyfile" >> $LOGFILE
559 locale=`grep -F KEYTABLE "$keyfile" | tr -d '"' |cut -d'=' -f2`
560 [ ! "$locale" ] && locale=`grep '.map$' "$keyfile" | sed 's/^.* //'` # Slackware
561 [ ! "$locale" ] && locale=`grep -E '^KEYMAP=' "$keyfile" | tr -d '"' |cut -d'=' -f2` # Gentoo
562 echo "locale=$locale" >> $LOGFILE
563 #
564 # Process the keymaps dir once for all
565 # AddKeyboardMappingFile will use it recursively
566 #
567 find $KEYDIR/keymaps > $MINDI_TMP/keymaps.find
568 mp=`grep "i[3-8]86" $MINDI_TMP/keymaps.find | grep -F "/${locale}." | grep -vx " *#.*"`
569 [ ! "$mp" ] && mp=`grep "i[3-8]86" $MINDI_TMP/keymaps.find | grep "$locale[^r][^/]" | grep -vx " *#.*"`
570 # If we have multiple keymaps then log it !!
571 echo "$mp" | grep -q " "
572 if [ $? -eq 0 ]; then
573 echo "WARNING: Multiple keymaps found: $mp" | tee -a $LOGFILE
574 echo "The following one will be used" >> $LOGFILE
575 fi
576 for i in $mp ; do
577 mappath=$i
578 [ -e "$i" ] && [ ! -d "$i" ] && break
579 done
580 if [ ! -e "$mappath" ] || [ -d "$mappath" ] ; then
581 mappath=$(locate */kbd/keymaps/*/$locale)
582 fi
583 echo "mappath = $mappath" >> $LOGFILE
584 if [ ! -e "$mappath" ] || [ -d "$mappath" ] ; then
585 LogIt "Keyboard mapping file not found. Default keyboard map will be used."
586 return
587 fi
588 echo -en "Adding the following keyboard mapping tables: "
589 mkdir -p $bigdir/tmp
590 echo "keymap-lives-here=$mappath" >> $MINDI_TMP/mondo-restore.cfg
591 KBDEPTH=0
592 AddKeyboardMappingFile $mappath
593 echo -e "$DONE"
594 rm -f $MINDI_TMP/keymaps.find
595 return 0
596}
597
598
599FindIsolinuxBinary() {
600 ISOLINUX=/usr/lib/isolinux.bin
601 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/lib/syslinux/isolinux.bin
602 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/lib64/syslinux/isolinux.bin
603 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/share/syslinux/isolinux.bin
604 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/share/lib/syslinux/isolinux.bin
605 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/share/lib64/syslinux/isolinux.bin
606 [ ! -e "$ISOLINUX" ] && ISOLINUX=`locate isolinux.bin | grep -x "/.*/isolinux.bin"`
607 [ ! -e "$ISOLINUX" ] && Die "Please install isolinux first. If your syslinux RPM doesn't include isolinux, you may download an isolinux RPM from Mondo's website - go to http://www.mondorescue.com and click on 'Download'"
608 echo "Found isolinux.bin at $ISOLINUX" >> $LOGFILE
609}
610
611
612FindLiloBinary() {
613 if which lilo &> /dev/null ; then
614 if which lilo.real > /dev/null 2> /dev/null ; then
615 LILO_EXE=lilo.real
616 LogIt "lilo.real found; will be used instead of lilo (*grumble* *mutter*)"
617 else
618 LILO_EXE=lilo
619 fi
620 $LILO_EXE -V | grep -F "21.6" > /dev/null && Die "Please upgrade LILO. Your version has a serious bug. If you're not _using_ LILO, fine, uninstall it. :)"
621 else
622 LILO_EXE=`which false`
623 fi
624}
625
626
627FindSensibleBootBFile() {
628 local i out last
629 out=""
630 last=""
631 for i in `find /boot -type f | grep -v chain | grep -v os2 | sort -u` ; do
632 if [ "`strings $i 2> /dev/null | head -n1`" = "LILO" ] ; then
633 out="$out $i"
634 last="$i"
635 fi
636 done
637 echo "$last"
638}
639
640
641FindSpecificModuleInPath() {
642 local modpaths pwd line
643 pwd=`pwd`
644 if [ "$YOUR_KERNEL_SUCKS" ] ; then
645 cd $MINDI_TMP
646 else
647 cd /
648 fi
649 if [ ! -e "$1" ] ; then
650 LogIt "WARNING - cannot search specific path '$1'"
651 return 1
652 fi
653 modpaths=`find $1 -name $2.*o -type f`
654 [ "$?" -ne "0" ] && Die "find $1 -name $2.o -type f --- failed"
655 [ "$modpaths" = "" ] && modpaths=`find $1 -name $2.o.gz -type f`
656 [ "$modpaths" = "" ] && modpaths=`find $1 -name $2.ko.gz -type f`
657 [ "$modpaths" = "" ] && modpaths=`find $1 -name $2 -type f`
658 echo "$modpaths"
659 cd $pwd
660}
661
662
663GenerateGiantDependencyList() {
664 local incoming loc fname list_of_files i tempfile outfile progress filelist res r mapfile mappath included_list included_item old_pwd tempdepfile modres noof_lines lvmversion lvmresolved
665
666 echo -en "Analyzing dependency requirements"
667 outfile=$1
668 tempfile=$MINDI_TMP/$$.txt
669 incoming=`ReadLine`
670
671 > $tempfile
672 progress=0
673 res=0
674 noof_lines=$2
675 while [ "$incoming" != "" ] ; do
676 if echo "$incoming" | grep -x " *#.*" &> /dev/null ; then
677 incoming=`ReadLine`
678 continue
679 fi
680 if [ "$incoming" = "LVMFILES:" ] ; then
681 break
682 fi
683 filelist=`GenerateListForFile "$incoming"`
684 r=$?
685 [ "$r" -ne "0" ] && LogIt "$incoming not found"
686 res=$(($res+$r))
687# echo "'$incoming' generates filelist '$filelist'" >> $LOGFILE
688 for fname in $filelist ; do
689 [ "$fname" != "" ] && echo "$fname" >> $tempfile
690 done
691 progress=$(($progress+1))
692 echo -en "\r\t\t\t\t\t\t\t\t"
693 i=$(($progress*100))
694 i=$(($i/$noof_lines))
695 echo -en "$i"
696 echo -en "%"
697 modres=$(($progress%4))
698 [ "$modres" -eq "0" ] && echo -en "\t/"
699 [ "$modres" -eq "1" ] && echo -en "\t-"
700 [ "$modres" -eq "2" ] && echo -en "\t\\"
701 [ "$modres" -eq "3" ] && echo -en "\t|"
702 incoming=`ReadLine`
703 done
704 if [ "$incoming" = "LVMFILES:" ] ; then
705 incoming=`ReadLine`
706 lvmversion=""
707 while [ "$incoming" != "" ] ; do
708 if echo "$incoming" | grep -x " *#.*" &> /dev/null ; then
709 incoming=`ReadLine`
710 continue
711 fi
712 filelist=`GenerateListForFile "$incoming"`
713 for tool in $filelist ; do
714 lvmresolved=`readlink -f $tool`
715 if [ "$tool" = "$lvmresolved" ]; then
716 echo "$tool" >> $tempfile
717 elif echo "$lvmresolved" | grep "lvmiopversion" &> /dev/null ; then
718 if [ "$lvmversion" = "" ] ; then
719 lvmversion=`$lvmresolved`
720 echo "$lvmresolved" >> $tempfile
721 fi
722 toolstripped=`echo $tool | $AWK -F / '{print $NF;}'`
723 if [ "$lvmversion" = "200" ]; then
724 # pvdata and lvmcreate_initrd don't exist in LVM2
725 case "$toolstripped" in
726 "pvdata")
727 continue
728 ;;
729 "lvmcreate_initrd")
730 continue
731 ;;
732 esac
733 fi
734 toolpath="/sbin/lvm-"$lvmversion"/"$toolstripped
735 if [ -e "$toolpath" ] ; then
736 echo "$toolpath" >> $tempfile
737 echo "$tool" >> $tempfile
738 else
739 toolpath="/lib/lvm-"$lvmversion"/"$toolstripped
740 fi
741 if [ -e "$toolpath" ] ; then
742 echo "$toolpath" >> $tempfile
743 echo "$tool" >> $tempfile
744 else
745 echo "Where are your LVM-Tools? Couldn't find $tool"
746 fi
747 else
748 echo "$tool" >> $tempfile
749 fi
750 done
751 progress=$(($progress+1))
752 echo -en "\r\t\t\t\t\t\t\t\t"
753 i=$(($progress*100))
754 i=$(($i/$noof_lines))
755 echo -en "$i"
756 echo -en "%"
757 modres=$(($progress%4))
758 [ "$modres" -eq "0" ] && echo -en "\t/"
759 [ "$modres" -eq "1" ] && echo -en "\t-"
760 [ "$modres" -eq "2" ] && echo -en "\t\\"
761 [ "$modres" -eq "3" ] && echo -en "\t|"
762 incoming=`ReadLine`
763 done
764 fi
765 echo -en "$DONE\nMaking complete dependency list"
766
767 tr -s '/' '/' < $tempfile | sort -u > $tempfile.new
768 mv -f $tempfile.new $tempfile
769 > $outfile.pre
770 progress=0
771 noof_lines=`cat $tempfile | wc -l`
772 for fname in `cat $tempfile` ; do
773 echo "$fname" >> $outfile.pre
774 LocateDeps $fname >> $outfile.pre
775 progress=$(($progress+1))
776 echo -en "\r\t\t\t\t\t\t\t\t"
777 i=$(($progress*100))
778 i=$(($i/$noof_lines))
779 echo -en "$i"
780 echo -en "%"
781 modres=$(($progress%4))
782 [ "$modres" -eq "0" ] && echo -en "\t/"
783 [ "$modres" -eq "1" ] && echo -en "\t-"
784 [ "$modres" -eq "2" ] && echo -en "\t\\"
785 [ "$modres" -eq "3" ] && echo -en "\t|"
786 done
787 if [ _"$MONDO_SHARE" != _"" ]; then
788 mkdir -p $bigdir/tmp
789 mkdir -p $bigdir/sbin
790 mkdir -p $bigdir/bin
791 if [ -e "$MINDI_TMP/post-nuke.tgz" ] ; then
792 LogIt "\nIncorporating post-nuke tarball"
793 old_pwd=`pwd`
794 cd $bigdir
795 tar -zxf $MINDI_TMP/post-nuke.tgz || LogIt "Error occurred when untarring post-nuke tarball"
796 cd $old_pwd
797 fi
798 if cp -f $MINDI_TMP/mondo*restore $bigdir/usr/bin 2>> $LOGFILE ; then
799 LocateDeps $bigdir/usr/bin/mondo*restore >> $outfile.pre
800 else
801 LogIt "Cannot find mondo*restore in mondo's tempdir, $MINDI_TMP"
802 LogIt "I bet you've got a spare copy of Mondo or Mindi floating around on your system."
803 LogIt "If Mindi was called by Mondo then send me a bug report.\n It not, type 'ps ax' to see which Mondo-related process is still running;\n then kill it. :-)\n Finally, run Mindi again."
804 Die "Odd."
805 fi
806 fi
807 tr ' ' '\n' < $outfile.pre | tr -s '/' '/' | grep -Fvx "" | sort -u | grep -Ev "/libX11|/libXext|/libXi|/libgtk|/libgdk" > $outfile
808 rm -f $tempfile $outfile.pre
809 [ "$res" -eq "0" ] && echo -e "\r\t\t\t\t\t\t\t\t$DONE" || echo "\nFailed."
810 return $res
811}
812
813
814GenerateListForFile() {
815 local files_found loc fname incoming i res
816 incoming="$1"
817 files_found=""
818 res=0
819
820 for fname in $incoming ; do
821 files_found="$files_found `LocateFile $fname`"
822 done
823
824 echo "$files_found" | tr ' ' '\n' | sort -u | tr '\n' ' '
825}
826
827
828# Returns all disk devices which are part of a raid array
829GetAllRaidMembers() {
830 $AWK "/^[[:space:]]*#/ {next} /^[[:space:]]*device/ if(\$2) {print \$2}" < /etc/raidtab
831}
832
833
834GetFileSizeList() {
835 local i
836 for i in `find $1 -type d -o -print` ; do
837 du -sk $i
838 done
839}
840
841
842GetHomeDir() {
843 local res loc
844 loc=`which $1 2>/dev/null`
845 res=`file $loc | $AWK '{print $NF;}'`
846 dirname $res
847}
848
849
850# Check kernel filesystem capabilites for accessing initrd image
851#
852# Interface definition:
853# param #1: absolute path to kernel image
854GetInitrdFilesystemToUse() {
855
856 # interface test: make sure we have one parameter
857 if [ $# -ne 1 ]; then
858 Die "GetInitrdFilesystemToUse(): Expected 1 parameter, got $#."
859 fi
860
861 # interface parameters
862 local lvKernelImage=$1
863
864 # local constants (filesystem magic strings)
865 local lcMagicCramfs="<3>cramfs: wrong magic"
866 local lcMagicExt2fs="<3>EXT2-fs: blocksize too small for device."
867 local lcMagicInitfs="<6>checking if image is initramfs..."
868
869 # local variables
870 local lvOffset
871 local lvScanRes
872 local lvUseFilesystem
873
874 # say where we are.
875 echo " GetInitrdFilesystemToUse(): called with parameter: $lvKernelImage.\n" >> $LOGFILE
876
877 # verify that file exists
878 [ ! -f $lvKernelImage ] && Die "File $lvKernelImage not found. Terminating."
879
880 # get offet of gzip magic "1f8b0800" in file
881 lvOffset=`od -vA n -t x1 $lvKernelImage | tr -d '[:space:]' | awk '{ print match($0, "1f8b0800")}'`
882 [ $lvOffset -eq 0 ] && Die "gzip magic not found in file $lvKernelImage. Terminating."
883 lvOffset=`expr $lvOffset / 2`
884 echo " GetInitrdFilesystemToUse(): gzip magic found at lvOffset $lvOffset.\n" >> $LOGFILE
885
886 # scan kernel image for initrd filessystem support
887 lvScanRes=`dd ibs=1 skip=$lvOffset if=$lvKernelImage obs=1M 2>/dev/null | gunzip -c 2> /dev/null | strings | grep -e "$lcMagicCramfs" -e "$lcMagicExt2fs" -e "$lcMagicInitfs"`
888
889 # determine which filesystem to use for initrd image: ext2fs, gzip'ed cpio (initramfs ) or cramfs
890 if [ `echo $lvScanRes | grep -c "$lcMagicExt2fs"` -eq 1 ]; then
891 lvUseFilesystem="ext2fs"
892 elif [ `echo $lvScanRes | grep -c "$lcMagicInitfs"` -eq 1 ]; then
893 lvUseFilesystem="initramfs"
894 elif [ `echo $lvScanRes | grep -c "$lcMagicCramfs"` -eq 1 ]; then
895 lvUseFilesystem="cramfs"
896 else
897 lvUseFilesystem="UNSUPPORTED"
898 fi
899
900 # say what we are using
901 echo " GetInitrdFilesystemToUse(): Filesytem to use for initrd is $lvUseFilesystem.\n" >> $LOGFILE
902
903 # return file system to use
904 echo "$lvUseFilesystem"
905
906}
907
908# Searches parent raid device of given disk device
909# $1: disk device (i.e. /dev/hda1)
910GetParentRaidDev() {
911 $AWK "/^[[:space:]]*#/ {next} /^[[:space:]]*raiddev/ {dev=\$2} /^[[:space:]]*device/ {if(\$2==\"$1\") {print dev; exit}}" < /etc/raidtab
912}
913
914
915# Searches members of raid device
916# $1: raid device (/dev/md...)
917GetRaidDevMembers() {
918 $AWK "/^[[:space:]]*#/ {next} /^[[:space:]]*raiddev/ {if(dev) exit; if(\$2 == \"$1\") dev=\$2} /^[[:space:]]*device/ {if(dev) {print \$2}}" < /etc/raidtab
919}
920
921
922HackPathsToFailsafe() {
923 local incoming newpath kver stub i pwd
924 kver=`uname -r`
925 incoming=`ReadLine`
926 pwd=`pwd`
927 cd $MINDI_TMP
928 while [ "$incoming" != "" ] ; do
929 stub=`basename $incoming`
930 newpath=`FindSpecificModuleInPath lib/modules/$FAILSAFE_KVER $stub`
931 for i in $newpath ; do
932 echo "$i"
933 done
934 read incoming
935 done
936 cd $pwd
937}
938
939
940ListAllPartitions() {
941 local res currline partition all_partitions ap_orig remaining i j
942
943 grep -vx " *#.*" $MY_FSTAB | grep -vx " *none.*" | $AWK '/^\/dev\/[imhs]d||^LABEL\=\/|^UUID=/ && !/fdd|cdr|zip|floppy/ {print $1}'
944 [ -e "/etc/raidtab" ] && $AWK '/^ *device/ {print $2}' /etc/raidtab
945 return
946}
947
948
949ListImagesForUser() {
950 local path fname
951 path=$1
952 echo -en "In the directory '$path' you will find the images:-\n"
953 for fname in `ls $path | grep -F mindi-` ; do
954 printf "%19s " $fname
955 done
956 echo " "
957}
958
959
960ListKernelModulePaths() {
961 local module_list module fname oss r kern
962 oss="/root/oss/modules"
963 module_list="$MODULES"
964 # Remove unwanted modules from list
965 for i in $DENY_MODS; do
966 module_list=`echo ${module_list} | tr ' ' '\n' | grep -Ev "^${i}$" | tr '\n' ' '`
967 done
968###
969### Sq-Modification ... Use kernelname for module search path if specified
970###
971 # kern="`uname -r`"
972 if [ "${kernelname}" != "" -a "${kernelname}" != "FAILSAFE" ]
973 then
974 kern=${kernelname}
975 else
976 kern="`uname -r`"
977 fi
978###
979### Sq-Mod End
980###
981 for module in $module_list $EXTRA_MODS ; do
982 r=`find /lib/modules/$kern -type f | grep "/${module}\..*o" | tail -n1`
983 echo "module $module --> $r" >> $LOGFILE
984 [ "$r" ] && echo "$r"
985 [ -f "$oss" ] && find $oss | grep -F $module
986 done
987 find /lib/modules/$kern/modules.* -type f 2> /dev/null
988 [ -f "$oss" ] && find $oss.* 2> /dev/null
989}
990
991
992LocateDeps() {
993 local incoming fname deps
994 incoming="$1"
995 for fname in $incoming ; do
996 if [ ! -e "$fname" ] ; then
997 echo "WARNING - $fname does not exist; cannot be LDD'd." >> $LOGFILE
998 if echo $fname | grep lvm &> /dev/null ; then
999 echo "This warning only affects you if you are using LVM." >> $LOGFILE
1000 if echo "$MODULES" | grep lvm &> /dev/null ; then
1001 echo "I think you are, so please take heed!" >> $LOGFILE
1002 else
1003 echo "I don't think you are, so don't worry about it." >> $LOGFILE
1004 fi
1005 fi
1006 elif [ -h "$fname" ] && [ -x "$fname" ] ; then
1007 echo "$fname is softlink" >> $LOGFILE
1008 else
1009 ldd $fname 2> /dev/null | ProcessLDD
1010 fi
1011 done
1012}
1013
1014
1015# Give all symlinks recursively of a full path name
1016ReadAllLink() {
1017 file="$1"
1018
1019 if [ ! -h $file ]; then
1020 echo "$file"
1021 return 0
1022 fi
1023
1024 link=`readlink -f $file`
1025 d=`dirname $file`
1026 if [ ! -e "$link" -a ! -e "$d/$link" ]; then
1027 echo "Problem with dead link on $file -> $link" >> $LOGFILE
1028 fi
1029 if [ -h "$d" ]; then
1030 echo "$link $d"
1031 else
1032 echo "$link"
1033 fi
1034}
1035
1036
1037LocateFile() {
1038 local i path fname_to_find location output resolved tmp stub cache_id loclist
1039 fname_to_find="$1"
1040 # It's an absolute path
1041 if echo "$fname_to_find" | grep -x "/.*" ; then
1042 output="$fname_to_find"
1043 if [ -h "$output" ] ; then
1044 output="`ReadAllLink $output` $output"
1045 fi
1046 echo "$output"
1047 return 0
1048 fi
1049 # It's not an absolute path
1050 output=""
1051 for path in /etc /usr /usr/bin /usr/sbin /bin /usr/X11R6/bin /sbin /usr/local/bin /usr/local/sbin `find /usr/lib /lib /usr/local/lib /usr/X11R6/lib /usr/lib64 /lib64 /usr/local/lib64 /usr/X11R6/lib64 -type d -maxdepth 1 2> /dev/null` ; do
1052 #for path in /etc /usr /usr/bin /usr/sbin /bin /usr/X11R6/bin /sbin /usr/local/bin /usr/local/sbin /usr/lib /usr/lib64 /usr/lib64/* /lib /lib64 /lib64/* /usr/local/lib /usr/local/lib64 /usr/local/lib64/* /usr/X11R6/lib /usr/X11R6/lib64 /usr/X11R6/lib64/* ; do
1053 [ -h "$path" ] && continue
1054 [ ! -e "$path/$fname_to_find" ] && continue
1055 output="$path/$fname_to_find $output"
1056 if [ -h "$path/$fname_to_find" ] ; then
1057 output="`ReadAllLink $path/$fname_to_find` $output"
1058 fi
1059 done
1060 if [ "$output" = "" ] ; then
1061 return 1
1062 fi
1063 echo "$output"
1064 return 0
1065}
1066
1067
1068LogIt() {
1069 if [ -e /dev/stderr ] ; then
1070 echo -e "$1" >> /dev/stderr
1071 elif [ -e /usr/bin/logger ] ; then
1072 /usr/bin/logger -s $1
1073 fi
1074 echo -e "$1" >> $LOGFILE
1075}
1076
1077
1078MakeModuleLoadingScript() {
1079 local module fname params modpath kver outerloop i modpaths kver searchpath list_to_echo j
1080 tmpmodprobe_flag=$1
1081 outfile=$2
1082 > $outfile || Die "Cannot create empty $outfile"
1083 echo -en "#\041/bin/sh\n\n" >> $outfile
1084 echo "echo -en \"Loading your modules...\"" >> $outfile
1085 if [ "$YOUR_KERNEL_SUCKS" ] ; then
1086 kver=$FAILSAFE_KVER
1087 cd $MINDI_TMP
1088 searchpath=lib/modules/$kver
1089 else
1090###
1091### Sq-Modification ... Use kernelname for module search path if specified
1092###
1093 #kver=`uname -r`
1094 if [ "${kernelname}" != "" ]
1095 then
1096 kver=${kernelname}
1097 else
1098 kver=`uname -r`
1099 fi
1100###
1101### Sq-Modification end
1102###
1103 searchpath=/lib/modules/$kver
1104 fi
1105
1106 echo -en "for outerloop in 1 2 3 4 5 ; do\necho -en \".\"\n" >> $outfile
1107 # BERLIOS: That code is duplicated - Should be done once only
1108 list_to_echo="$MODULES"
1109 # Remove unwanted modules from list
1110 for i in $DENY_MODS; do
1111 list_to_echo=`echo ${list_to_echo} | tr ' ' '\n' | grep -Ev "^${i}$" | tr '\n' ' '`
1112 done
1113
1114 # Make temporary modprobe.conf file if we are told so
1115 if [ "$tmpmodprobe_flag" = "Y" ] ; then
1116 infile="$MINDI_TMP/modprobe.conf.mindi"
1117 find /etc/modprobe.d -maxdepth 1 -name "*" -xtype f -print0 | xargs -0 cat > $infile
1118 else
1119 infile="/etc/modules.conf"
1120 fi
1121 for module in $list_to_echo $EXTRA_MODS ; do
1122 params=`sed -n "s/^options \\+$module \\+//p" $infile`
1123 modpaths=`FindSpecificModuleInPath $searchpath $module`
1124 for i in $modpaths ; do
1125 echo "MyInsmod $i $params > /dev/null 2> /dev/null" \
1126 | tr '.' '#' \
1127 | sed s/#o#gz/#o/ \
1128 | sed s/#o#gz/#o/ \
1129 | sed s/#ko#gz/#ko/ \
1130 | sed s/#ko#gz/#ko/ \
1131 | tr '#' '.' >> $outfile
1132 echo -en "$i added to module list.\n" >> $LOGFILE
1133 done
1134 done
1135 echo -en "done\n" >> $outfile
1136 echo "echo \"Done.\"" >> $outfile
1137 chmod +x $outfile
1138 cd /
1139 # Remove temporary modprobe.conf file if we have created one
1140 if [ "$tmpmodprobe_flag" = "Y" ] ; then
1141 rm -f $infile
1142 fi
1143}
1144
1145
1146MakeMountlist() {
1147 local scratchdir mountlist all_partitions current_partition \
1148partition_size partition_format outstring partition_number \
1149partition_mountpt c_p lwm_info psz lvm_dev unofficial_outstring \
1150absolute_partition old_partition_fmt current_lvolume
1151
1152 echo "Your raw fstab file looks like this:" >> $LOGFILE
1153 echo "------------------------------------" >> $LOGFILE
1154 cat $MY_FSTAB >> $LOGFILE
1155 echo "Your mountlist will look like this:" | tee -a $LOGFILE
1156 echo "-----------------------------------" >> $LOGFILE
1157
1158# scratchdir, mountlist(OUT)
1159 scratchdir=$MINDI_TMP
1160 mountlist=$1
1161
1162# NB: partition = device
1163# NB: mountpt = where the device is mounted
1164
1165 [ -e "$MY_FSTAB" ] || Die "Cannot find your fstab file ($MY_FSTAB)"
1166
1167 [ "$mountlist" != "" ] && rm -Rf $mountlist
1168 > $mountlist
1169 all_partitions=""
1170
1171 if [ $LVM != "false" ]; then
1172 echo -en "Analyzing LVM...\n"
1173 $MINDI_LIB/analyze-my-lvm > $MINDI_TMP/lvm.res
1174 if [ $? -ne 0 ]; then
1175 LVM="false"
1176 fi
1177 all_partitions=`cat $MINDI_TMP/lvm.res | grep -F ">>>" | cut -d' ' -f2-32`
1178 fi
1179 all_partitions="$all_partitions `ListAllPartitions 2> /dev/null`"
1180# echo "all partitions = $all_partitions" > /dev/stderr
1181 for i in $IMAGE_DEVS ; do
1182 mount | grep -F "$i " > /dev/null 2> /dev/null && Die "Sorry, $i is already mounted! CANNOT DO IMAGEDEV on it if it's mounted."
1183 done
1184 [ "$IMAGE_DEVS" != "" ] && all_partitions="`echo "$all_partitions $IMAGE_DEVS" | tr ' ' '\n' | sort -u | tr '\n ' ' '`"
1185 printf " %-15s %-15s %-15s %-15s %-15s %-15s\n" DEVICE MOUNTPOINT FORMAT "SIZE (MB)" LABEL UUID | tee -a $LOGFILE
1186 useless_dev="/dev/floppy /dev/fd0h1440 /dev/fd0H1440 /dev/cdrom /dev/cdrom/cdrom /dev/cdrom/cdrom1 /dev/cdrom/cdrom2 /dev/cdrom0 /dev/cdrom1 /dev/cdrom2 /dev/cdrom3 /dev/cdrw /dev/scd /dev/ram :/ /dev/sr0 /dev/sr1 /dev/cdrom1"
1187 for c_p in $all_partitions ; do
1188 [ "`echo "$useless_dev" | grep -F "$c_p"`" != "" ] || [ "`echo "$c_p" | grep ":"`" != "" ] && continue
1189 [ "`echo "$c_p" | grep -x "/dev/cdroms.*"`" ] && continue
1190 if [ -h "$c_p" ] && [ "`echo "$c_p" | grep -F "/dev/hd"`" = "" ] && [ "`echo "$c_p" | grep -F "/dev/sd"`" = "" ] && [ "`echo "$c_p" | grep -F "/dev/md"`" = "" ] ; then
1191 current_partition=`readlink -f $c_p`
1192 [ "`echo "$current_partition" | grep -F "/dev/mapper"`" != "" ] && current_partition="$c_p"
1193 [ "`echo "$useless_dev" | grep -F "$current_partition"`" ] && continue
1194 else
1195 current_partition="$c_p"
1196 fi
1197 [ "$c_p" = "none" ] && continue
1198 redhat_label=""
1199 uuid=""
1200 absolute_partition=`readlink -f $c_p`
1201 partition_mountpt=`tr -s '\t' ' ' < $MY_FSTAB | /bin/grep -w "$current_partition" | /bin/grep -vx " *#.*" | $AWK '{print $2}' | head -n1`
1202
1203 # Detects noauto partitions not mounted and exclude them
1204 partition_option=`tr -s '\t' ' ' < $MY_FSTAB | /bin/grep -w "$current_partition" | /bin/grep -vx " *#.*" | $AWK '{print $4}' | head -n1`
1205 if [ "`echo "$partition_option" | grep -i noauto`" != "" ] && [ "`mount | grep -w "$partition_mountpt"`" = "" ] ; then
1206 continue
1207 fi
1208
1209 # This part tries to retrieve the correct device from a LABEL line in /etc/fstab
1210 # current_partition contains only first column of /etc/fstab
1211 if [ "`echo "$current_partition" | /bin/grep -i "LABEL="`" != "" ]; then
1212 str_to_find_fmt_with=$current_partition
1213 redhat_label=`echo "$current_partition" | cut -d'=' -f2`
1214 actual_dev=""
1215
1216 # 1st try, findfs - the RHEL way of finding labels and their partitions
1217 if [ -x "/sbin/findfs" ]; then
1218 actual_dev=`/sbin/findfs LABEL=${redhat_label} 2> /dev/null`
1219 fi
1220
1221 # 2nd try : blkid, the good way for all LABEL except swap
1222 if [ "x$actual_dev" = "x" -a -x "/sbin/blkid" ]; then
1223 actual_dev=`/sbin/blkid | /bin/grep "$redhat_label" | grep LABEL= | cut -d':' -f1`
1224 # For LVM FS it will give a /dev/dm-# which should then be converted
1225 if [ $LVM = "v2" ] && [ "`echo $actual_dev | grep '/dev/dm'`" ]; then
1226 major=`/bin/ls -l $actual_dev | $AWK '{print $5}'`
1227 minor=`/bin/ls -l $actual_dev | $AWK '{print $6}'`
1228 for dev in `ls /dev/mapper/*`; do
1229 major1=`/bin/ls -l $dev | $AWK '{print $5}'`
1230 minor1=`/bin/ls -l $dev | $AWK '{print $6}'`
1231 if [ $major1 = $major ] && [ $minor1 = $minor ]; then
1232 actual_dev=`/bin/ls -l $dev | $AWK '{print $10}'`
1233 break
1234 fi
1235 done
1236 fi
1237 fi
1238
1239 # 3rd try, which works on a standard partition (ext2/3), but not on swap
1240 # For LVM gives a /dev/mapper entry
1241 if [ "x$actual_dev" = "x" ]; then
1242 actual_dev=`/bin/mount -l | /bin/grep "\[$redhat_label\]" | cut -d' ' -f1`
1243 fi
1244
1245 # 4th try, with vol_id
1246 # SWAP only
1247 if [ "x$actual_dev" = "x" -a -x "/sbin/vol_id" ]; then
1248 list_swaps=`cat /proc/swaps | /bin/grep "/dev/" | $AWK '{ print $1 }' `
1249 for dev_swap in $list_swaps ; do
1250 dev_exists=`/sbin/vol_id $dev_swap | /bin/grep "$redhat_label"`
1251 if [ "x$dev_exists" != "x" ]; then
1252 actual_dev=$dev_swap
1253 break;
1254 fi
1255 done
1256 fi
1257
1258 # 5th try : pre-formated LABEL. Format is : LABEL=SWAP-mydevice or SW-mydevice. e.g. : LABEL=SWAP-hda5
1259 # LABEL=SW-cciss/c0d0p3 (RDP)
1260 # or could be a string that isn't a complete device name (eg. LABEL =SWAP-cciss/c0d0p)
1261 # SWAP only
1262 if [ "x$actual_dev" = "x" -a _"`echo $current_partition | /bin/grep -iE 'LABEL=SWAP|LABEL=SW-'`" != _"" ]; then
1263 for try_dev in `tail +2 /proc/swaps | cut -d' ' -f1`
1264 do
1265 # Location of the swap label for kernel 2.6
1266 try_dev_label=`dd bs=1 count=16 skip=1052 if=$try_dev 2> /dev/null`
1267 if [ "x$try_dev_label" = "x$redhat_label" ]; then
1268 actual_dev=$try_dev
1269 fi
1270 done
1271 fi
1272
1273 # Check if one of all those tries has known success
1274 if [ "x$actual_dev" != "x" ]; then
1275 current_partition=$actual_dev
1276 else
1277 Die "Your system uses a LABEL partition ($current_partition), but you lack the tool to support it.\nPlease replace labels with their correct devices in $MY_FSTAB or install findfs|blkid|vol_id"
1278 fi
1279 # This part tries to retrieve the correct device from a UUID line in /etc/fstab
1280 # current_partition contains only first column of /etc/fstab
1281 elif [ "`echo "$current_partition" | /bin/grep -i "UUID="`" != "" ]; then
1282 str_to_find_fmt_with=$current_partition
1283 uuid=`echo "$current_partition" | cut -d'=' -f2`
1284 actual_dev=""
1285
1286 # 1st try, findfs - the RHEL way of finding labels and their partitions
1287 if [ -x "/sbin/findfs" ]; then
1288 actual_dev=`/sbin/findfs UUID=${uuid} 2> /dev/null`
1289 fi
1290
1291 # 2nd try : blkid, the good way for all UUID except swap
1292 if [ "x$actual_dev" = "x" -a -x "/sbin/blkid" ]; then
1293 actual_dev=`/sbin/blkid | /bin/grep "$uuid" | grep UUID= | cut -d':' -f1`
1294 # For LVM FS it will give a /dev/dm-# which should then be converted
1295 if [ $LVM = "v2" ] && [ "`echo $actual_dev | grep '/dev/dm'`" ]; then
1296 major=`/bin/ls -l $actual_dev | $AWK '{print $5}'`
1297 minor=`/bin/ls -l $actual_dev | $AWK '{print $6}'`
1298 for dev in `ls /dev/mapper/*`; do
1299 major1=`/bin/ls -l $dev | $AWK '{print $5}'`
1300 minor1=`/bin/ls -l $dev | $AWK '{print $6}'`
1301 if [ $major1 = $major ] && [ $minor1 = $minor ]; then
1302 actual_dev=`/bin/ls -l $dev | $AWK '{print $10}'`
1303 break
1304 fi
1305 done
1306 fi
1307 fi
1308
1309 # 3th try, with vol_id
1310 if [ "x$actual_dev" = "x" -a -x "/sbin/vol_id" ]; then
1311 list_dev=`mount | /bin/grep -E '^/' | $AWK '{ print $1 }' `
1312 for dev in $list_dev ; do
1313 dev_exists=`/sbin/vol_id $dev | /bin/grep "$uuid"`
1314 if [ "x$dev_exists" != "x" ]; then
1315 actual_dev=$dev
1316 break;
1317 fi
1318 done
1319 fi
1320
1321 # 4th try, with dumpuuid (VMWare only ?) for swap
1322 if [ "x$actual_dev" = "x" -a -x "/sbin/dumpuuid" ]; then
1323 list_dev=`cat /proc/swaps | /bin/grep -E '^/' | $AWK '{ print $1 }' `
1324 for dev in $list_dev ; do
1325 dev_exists=`/sbin/dumpuuid $dev | /bin/grep "$uuid"`
1326 if [ "x$dev_exists" != "x" ]; then
1327 actual_dev=$dev
1328 break;
1329 fi
1330 done
1331 fi
1332
1333 # Check if one of all those tries has known success
1334 if [ "x$actual_dev" != "x" ]; then
1335 current_partition=$actual_dev
1336 else
1337 Die "Your system uses a UUID partition ($current_partition), but you lack the tool to support it.\nPlease replace labels with their correct devices in $MY_FSTAB or install findfs|blkid|vol_id"
1338 fi
1339 else
1340 str_to_find_fmt_with=$current_partition
1341 fi
1342
1343 partition_format=`$AWK '$1 == "'"$str_to_find_fmt_with"'" {print $3}' $MY_FSTAB`
1344 # Some distributions such as Debian do not put /dev/<VG>/<LV> in fstab
1345 # for LVM partitions but use /dev/mapper/<VG>-<LV> instead. Fortunately,
1346 # the former is then a link to the latter, so we test whether
1347 # $current_partition is actually such a link or not and set
1348 # $current_lvolume accordingly. On Debian you may find more than one answer
1349 # so we remove the one corresponding to /dev/.static
1350 # On RedHat even if the device name is different (/dev/mapper/<VG><LV>), the
1351 # principle is the same and we need to find the link to it as well.
1352 # Note that $current_lvolume may well be an
1353 # ordinary device. It is just to make sure that we feed the right value
1354 # into any of the LVM tools if possible.
1355
1356 current_lvolume="$current_partition"
1357 if [ $LVM = "v2" ] && [ "`echo $current_partition | grep -E '^/dev/mapper/'`" ]; then
1358 # .static dir are a Debian specificity
1359 current_lvolume="`find /dev -lname "$current_partition" | grep -Ev '^/dev/\.static/'`"
1360 echo $current_lvolume | grep -q ' '
1361 if [ $? -eq 0 ]; then
1362 echo "WARNING: Multiple Logical Volumes found. Report to dev team" >> $LOGFILE
1363 fi
1364 fi
1365 #
1366 # End of LVM device style variation code (other than $current_lvolume).
1367
1368 if [ $LVM != "false" ] && [ "`$LVMCMD lvdisplay $current_lvolume 2> /dev/null`" ]; then
1369 # Size computed via LVM not directly
1370 partition_size="lvm"
1371 else
1372 partition_size=`SizeOfPartition $current_partition`
1373 [ "`echo "$current_partition" | grep "[0-9]"`" = "" ] && continue
1374 [ "`echo "$current_partition" | grep -c "^/"`" -ne "1" ] && continue
1375 if [ "$partition_format" = "swap" ] || [ "$partition_mountpt" = "swap" ] ; then
1376 partition_size=`grep -Fv "Priority" /proc/swaps | tr -s '\t' ' ' | grep -F "$current_partition" | $AWK '{print $3}'`
1377 [ "$partition_mountpt" != "swap" ] && partition_mountpt="swap"
1378 [ "$partition_format" != "swap" ] && partition_format="swap"
1379 if [ "$partition_size" = "" ] ; then
1380 totalsize=0
1381 items=0
1382 for i in `tr -s ' ' '\t' < /proc/swaps | grep -Fv "Filename" | cut -f3` ; do
1383 totalsize=$(($totalsize+$i))
1384 items=$(($items+1))
1385 done
1386 [ "$items" -gt "0" ] && partition_size=$(($totalsize/$items)) || partition_size=0
1387 [ "$partition_size" -lt "125000" ] && partition_size=125000
1388 echo "I'm guessing $c_p is $(($partition_size/1024))MB" >> $LOGFILE
1389 fi
1390 fi
1391 fi
1392 [ "$partition_mountpt" = "swap" ] && partition_format="swap"
1393 [ "$partition_format" = "swap" ] && partition_mountpt="swap"
1394 if [ "$partition_mountpt" = "" ] ; then
1395 if [ "`$LVMCMD pvdisplay $current_lvolume 2> /dev/null`" != "" ] ; then
1396 if [ "`grep -F device /etc/raidtab 2> /dev/null | grep -w $current_partition`" ] ; then
1397 partition_mountpt="raid"
1398 partition_format="raid"
1399 else
1400 partition_mountpt="lvm"
1401 partition_format="lvm"
1402 fi
1403 fi
1404 fi
1405 psz=$partition_size
1406 echo "Examining $current_partition (mount=$partition_mountpt fmt=$partition_format psz=$psz)" >> $LOGFILE
1407 [ "$psz" != "lvm" ] && psz=$(($psz/1024))
1408 if [ "`echo " $IMAGE_DEVS " | grep -F " $current_partition "`" != "" ] ; then
1409 partition_mountpt="image"
1410 old_partition_fmt=$partition_format
1411 partition_format="`$FDISK -l 2>> $LOGFILE | tr '*' ' ' | tr '+' ' ' | tr -s ' ' '\t' | grep -w "$absolute_partition" | cut -f5`"
1412 partition_size=$(($partition_size+1)); # just in case
1413 if [ "$partition_format" = "Linux" ] ; then
1414 echo "Are you imaging a mounted swap partition? Silly..." >> $LOGFILE
1415 echo "Reverting format from $old_partition_fmt to $partition_format" >> $LOGFILE
1416 partition_format=$old_partition_fmt
1417 fi
1418 fi
1419 if [ "$EXCLUDE_DEVS" ] && [ "`echo " $EXCLUDE_DEVS " | grep -F " $current_partition "`" ] || [ "`echo " $EXCLUDE_DEVS " | grep " $current_partition "`" ] ; then
1420 echo "Excluding $current_partition from mountlist" >> $LOGFILE
1421 continue
1422 fi
1423 if [ ! "$partition_mountpt" ] ; then
1424 echo "------- $FDISK -l $qq log ------------" >> $LOGFILE
1425 for qq in "" `find /dev/ida/c*d* ! -name '*p*'` ; do
1426 partition_format=`$FDISK -l $qq 2>> $LOGFILE | grep -w "$c_p" | sed 's/12/|/' | tr -s '\t' ' ' | cut -d'|' -f2 | cut -d' ' -f2-9`
1427 [ "$partition_format" ] && break
1428 done
1429 echo "------- $FDISK log end ------------" >> $LOGFILE
1430 if [ "$partition_format" = "Compaq diagnostics" ] ; then
1431 partition_format="compaq"
1432 elif [ ! "`grep -F device /etc/raidtab 2> /dev/null | grep -w $current_partition`" ] ; then
1433 LogIt "Unable to find mountpoint of $current_partition - ignoring"
1434 continue
1435 fi
1436 fi
1437 partition_format="`echo "$partition_format" | cut -d',' -f1`"; # in case user has ext3,ext2 or something dumb like that
1438 [ "$partition_format" = "auto" ] && partition_format="`mount | grep -w $current_partition | $AWK '{print$5;}'`"; # in case user uses 'auto' (dumb!)
1439 unofficial_outstring=`printf "\t%-15s %-15s %-15s %7s %-15s %-15s\n" $current_partition $partition_mountpt $partition_format $psz "$redhat_label" $uuid`
1440 if [ "$current_partition" = "" ] ; then
1441 echo "Unknown partition (outstring = $unofficial_outstring)" >> $LOGFILE
1442 elif [ "$partition_mountpt" = "" ] && [ -f "/etc/raidtab" ] ; then
1443 if [ "`grep -F device /etc/raidtab 2>/dev/null | grep -F $current_partition`" ] ; then
1444 partition_mountpt=raid
1445 partition_format=raid
1446 printf "\t%-15s %-15s %-15s %7s %-15s %-15s\n" $current_partition $partition_mountpt $partition_format $psz "$redhat_label" $uuid | tee -a $LOGFILE
1447 printf "%s %s %s %s %s %s\n" $current_partition $partition_mountpt $partition_format $partition_size "$redhat_label" $uuid >> $mountlist
1448 else
1449 echo "Unknown mountpoint (outstring = $unofficial_outstring)" >> $LOGFILE
1450 fi
1451 elif [ "$partition_format" = "" ] ; then
1452 echo "Unknown format (outstring = $unofficial_outstring)" >> $LOGFILE
1453 elif [ "$partition_size" = "" ] ; then
1454 echo "Unknown partition size (outstring = $unofficial_outstring)" >> $LOGFILE
1455 elif [ "$partition_mountpt" = "/proc" ] || [ "$partition_mountpt" = "/dev/pts" ] ; then
1456 continue
1457 else
1458 if [ "$partition_format" = "dos" ] || [ "$partition_format" = "msdos" ] ; then
1459 echo "Stupid bastard..." >> $LOGFILE
1460 partition_format="vfat"
1461 fi
1462 printf "\t%-15s %-15s %-15s %7s %-15s %-15s\n" $current_partition $partition_mountpt $partition_format $psz "$redhat_label" $uuid | tee -a $LOGFILE
1463 printf "%s %s %s %s %s %s\n" $current_partition $partition_mountpt $partition_format $partition_size "$redhat_label" $uuid >> $mountlist
1464 fi
1465 done
1466}
1467
1468
1469MakeSureNumberIsInteger() {
1470 res=`echo "$1" | tr -s '\-[0-9]' ' '`
1471 if [ "$res" != " " ] && [ "$res" != "" ] ; then
1472 echo "result = '$res'"
1473 Die "$1 should be an integer"
1474 fi
1475}
1476
1477
1478MakeSyslinuxMessageFile() {
1479 mkdir -p $1
1480 rmdir $1
1481 echo -en " " > $1
1482 if [ "`grep -Fi "debian" /etc/issue.net 2> /dev/null`" ] ; then
1483 sed s/ZZZZZ/$MINDI_VERSION/ $MINDI_LIB/msg-txt | sed s/YYYYY/"Mondo Rescue"/ | sed s/XXXXX/"a cousin of"/ | sed s%DDDDD%"Debian GNU\/`uname -s` `cut -d ' ' -f 3 /etc/issue.net` `hostname`"% | sed s/KKKKK/"Kernel `uname -r` on a `uname -m`"/ | sed s/TTTTT/"`LC_TIME=C date`"/ >> $1.tmp
1484 else
1485 sed s/ZZZZZ/$MINDI_VERSION/ $MINDI_LIB/msg-txt | sed s/YYYYY/"Mondo Rescue"/ | sed s/XXXXX/"a cousin of"/ | sed s/DDDDD/"`grep -i "linux" /etc/issue.net | head -n1 | tr -s ' ' ' '`"/ | sed s/KKKKK/"`grep -i "kernel" /etc/issue.net | head -n1 | tr -s ' ' ' '`"/ | sed s/TTTTT/"`LC_TIME=C date`"/ | sed s/' '\\r' 'on' 'an' '\/' '`uname -r`' 'on' 'an' '`uname -m`/ >> $1.tmp
1486 fi
1487 sed s/%r/"`uname -r`"/ $1.tmp | sed s/%t/"`hostname`"/ > $1
1488 rm -f $1.tmp
1489 if [ "$CDRECOVERY" != "yes" ] ; then
1490 if [ "$NFS_DEV" != "" ] ; then
1491 echo -en "Press <enter> to continue.\n" >> $1
1492 elif [ ! "$MINDI_TMP" ] ; then
1493 echo -en "FYI, this is _not_ a Mondo Rescue CD.\n" >> $1
1494 if [ -e "$MINDI_LIB/memtest.img" ] ; then
1495 echo -en "Type 'memtest' <Enter> to test your PC's memory intensively.\nJust press <Enter> to go to the main test menu.\n" >> $1
1496 fi
1497 else
1498 echo -en "$BOOT_MEDIA_MESSAGE" >> $1
1499 fi
1500 else
1501 echo -en " \
1502To restore your disk to factory defaults, type 'RESTORE' <enter>.\n\
1503CAUTION: THIS WILL ERASE YOUR WHOLE DISK !!!\n" >> $1
1504 fi
1505}
1506
1507
1508MoveHyperlinkSensibly() {
1509 local filename minidir_root resides_on_diskno noof_disks old_diskno d old_pwd
1510 filename=$1
1511 minidir_root=$2
1512 resides_on_diskno=$3
1513 noof_disks=$4
1514
1515 [ -h "$minidir_root/$resides_on_diskno/$filename" ] || Die "$filename isn't a softlink (or doesn't exist): how can I move it sensibly?"
1516
1517 old_diskno=$resides_on_diskno
1518 d=1
1519 while [ "$d" -le "$noof_disks" ] ; do
1520 if [ "$d" -ne "$old_diskno" ] ; then
1521 old_pwd=`pwd`
1522 cd $minidir_root/$old_diskno
1523 cp --parents -Rdf $filename $minidir_root/$d/ 2>> $LOGFILE || Die "Can't move $filename (sensibly) from $old_diskno to $d"
1524 rm -f $filename
1525 cd $old_pwd
1526 fi
1527# when the softlink is resolvable, our work here is done
1528 [ -e "$minidir_root/$d/$filename" ] && return 0
1529 old_diskno=$d
1530 d=$(($d+1))
1531 done
1532 return 1
1533}
1534
1535
1536OfferToCopyImagesToDisks() {
1537 local imagesdir i imagename dev count boot_dev data_dev
1538 imagesdir=$1
1539 boot_dev=$2
1540 data_dev=$3
1541
1542 echo -en "Would you like to create boot+data floppy disks now (y/[n]) ?"
1543 read i
1544 [ "$i" != "y" ] && [ "$i" != "Y" ] && return
1545 mount | grep -F /dev/fd > /dev/null && Die "Please unmount your floppies first."
1546 echo "WARNING! THIS WILL ERASE YOUR FLOPPY DISKS."
1547 [ ! -e "$boot_dev" ] && Die "Cannot find $boot_dev - is your Linux distro broken?"
1548 [ ! -e "$data_dev" ] && Die "Cannot find $data_dev - is your Linux distro broken?"
1549 find $imagesdir -type f > $MINDI_TMP/imagesdir.files
1550 i=`grep -F "/mindi-root.1" $MINDI_TMP/imagesdir.files 2> /dev/null`
1551 j=`grep -F "/mindi-boot" $MINDI_TMP/imagesdir.files | grep -Ev "2880|$BOOT_SIZE"`
1552 if [ "$i" ] ; then
1553 CopyImageToDisk $j $data_dev "boot disk"
1554 CopyImageToDisk $i $data_dev "root disk"
1555 else
1556 CopyImageToDisk $j $boot_dev "boot/root disk"
1557 fi
1558 count=1
1559 for i in `grep -F mindi-data $MINDI_TMP/imagesdir.files` ; do
1560 CopyImageToDisk $i $data_dev "data disk #$count"
1561 count=$(($count+1))
1562 done
1563 rm -f $MINDI_TMP/imagesdir.files
1564}
1565
1566
1567OfferToMakeBootableISO() {
1568 local i old_pwd
1569 if [ "$PROMPT_MAKE_CD_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
1570 echo -en "Shall I make a bootable CD image? (y/[n]) "
1571 read i
1572 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1573 fi
1574 if [ _"$MINDI_TMP" = _"" ]; then
1575 Die "MINDI_TMP undefined"
1576 fi
1577 rm -Rf $MINDI_TMP/iso
1578 mkdir -p $MINDI_TMP/iso/{images,archives,isolinux}
1579 cp -f $1/*.img $1/*.gz $MINDI_TMP/iso/images 2>> $LOGFILE || LogIt "OfferToMakeBootableISO: Cannot copy $i to $MINDI_TMP/iso/images"
1580 old_pwd=`pwd`
1581 cd $MINDI_TMP/iso
1582 echo "mindi_lib = $MINDI_LIB" >> $LOGFILE
1583 for i in memdisk memtest.bin memtest.img ; do
1584 j=$MINDI_LIB/$i
1585 k=$MINDI_TMP/iso/isolinux
1586 if [ -e "$j" ] ; then
1587 LogIt "Copying $j to $k"
1588 cp -f $j $k 2> /dev/null || Die "Failed to copy $j to $k"
1589 cp -f $j $MINDI_TMP 2> /dev/null || Die "Failed to copy $j to $MINDI_TMP"
1590 if [ _"$MONDO_SHARE" != _"" ]; then
1591 cp -f $j $MONDO_ROOT 2>> $LOGFILE || Die "Failed to copy $j to $MONDO_ROOT"
1592 fi
1593 fi
1594 done
1595 MakeSyslinuxMessageFile $MINDI_TMP/iso/isolinux/message.txt
1596 cp $kernelpath $MINDI_TMP/iso/isolinux/vmlinuz 2> /dev/null || Die "Cannot copy vmlinuz ($kernelpath) to mindi tmp ($MINDI_TMP/iso/isolinux/vmlinuz). Did you run out of disk space?"
1597 cp $MINDI_TMP/mindi.rdz $MINDI_TMP/iso/isolinux/initrd.img 2>> $LOGFILE
1598 if [ _"$MONDO_SHARE" != _"" ]; then
1599 cp $kernelpath $MONDO_ROOT/vmlinuz 2> /dev/null || Die "Cannot copy vmlinuz ($kernelpath) to mondo root ($MONDO_ROOT/vmlinuz). Did you run out of disk space?"
1600 cp $MINDI_TMP/mindi.rdz $MONDO_ROOT/initrd.img 2> /dev/null || Die "Cannot copy mindi.rdz ($MINDI_TMP/mindi.rdz) to mondo root ($MONDO_ROOT/vmlinuz). Did you run out of disk space?"
1601
1602 fi
1603 [ -e "$iso_cfg_file" ] || Die "FIXME - unable to find $iso_cfg_file - this should never occur"
1604 cd $MINDI_TMP/iso/isolinux
1605 cat $iso_cfg_file | HackSyslinuxFile $ramdisk_size $MINDI_TMP/iso > isolinux.cfg || Die "Cannot copy isolinux.cfg to $MINDI_TMP/iso/isolinux - did you run out of disk space?"
1606 if [ "$NFS_DEV" != "" ] ; then
1607 perl -pi -e 's/interactive/iso/' isolinux.cfg
1608 fi
1609 if [ "$ARCH" != "ia64" ] ; then
1610 cp $ISOLINUX isolinux.bin 2> /dev/null || Die "Cannot copy isolinux.bin ($ISOLINUX) to $MINDI_TMP/iso/isolinux - did you run out of disk space?"
1611 cp $ISOLINUX ../ 2>> $LOGFILE
1612 fi
1613 cd $MINDI_TMP/iso
1614 if [ "$ARCH" != "ia64" ] ; then
1615 if [ _"$MONDO_SHARE" != _"" ]; then
1616 cp -f $MINDI_TMP/iso/isolinux/{isolinux.cfg,initrd.img,vmlinuz,isolinux.bin,message.txt} $MONDO_ROOT 2> /dev/null || Die "Cannot copy core files to ramdisk for boot disk (under $MONDO_ROOT). Did you run out of disk space?"
1617 cp -f $MONDO_SHARE/autorun . 2>> $LOGFILE
1618 fi
1619 mkisofs -U -J -r -o $MINDI_CACHE/mindi.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table . > /dev/null 2> $MINDI_TMP/mkisofs.log
1620 else
1621 mkisofs -J -r -o $MINDI_CACHE/mindi.iso -b images/mindi-bootroot.$BOOT_SIZE.img -c isolinux/boot.cat -no-emul-boot . > /dev/null 2> $MINDI_TMP/mkisofs.log
1622 fi
1623 if [ "$?" -ne "0" ] ; then
1624 echo "----------- mkisofs's errors --------------" >> $LOGFILE
1625 cat $MINDI_TMP/mkisofs.log >> $LOGFILE
1626 echo "mkisofs returned the following errors:-"
1627 cat $MINDI_TMP/mkisofs.log
1628 LogIt "Failed to create ISO image."
1629 else
1630 echo "Created bootable ISO image at $MINDI_CACHE/mindi.iso" >> $LOGFILE
1631 fi
1632 rm -f $MINDI_TMP/mkisofs.log
1633 cd $old_pwd
1634}
1635
1636
1637OfferToMakeBootableUSB() {
1638 local i old_pwd
1639 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
1640 echo "Shall I make a bootable USB image ?"
1641 echo -en "WARNING: This will erase all content on $USBDEVICE (y/[n]) "
1642 read i
1643 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1644 fi
1645 if [ _"$MINDI_TMP" = _"" ]; then
1646 Die "MINDI_TMP undefined"
1647 fi
1648 rm -Rf $MINDI_TMP/usb
1649 mkdir -p $MINDI_TMP/usb
1650 USBPART="${USBDEVICE}1"
1651
1652 echo -en "Transforming $USBDEVICE in a Bootable device "
1653 echo -en "."
1654 echo "Transforming $USBDEVICE in a Bootable device" >> $LOGFILE
1655 echo "Checking $USBDEVICE" >> $LOGFILE
1656 $FDISK -l $USBDEVICE 2>&1 >> $LOGFILE
1657 if [ $? -ne 0 ]; then
1658 echo "Unable to access $USBDEVICE" | tee -a $LOGFILE
1659 echo "Make sure your USB device is pluged in" | tee -a $LOGFILE
1660 MindiExit -1
1661 fi
1662 echo -en "."
1663 echo "Erasing $USBDEVICE" >> $LOGFILE
1664 $FDISK $USBDEVICE 2>&1 >> $LOGFILE << EOF
1665d
1666d
1667d
1668d
1669n
1670p
16711
1672
1673
1674t
1675b
1676a
16771
1678w
1679EOF
1680 if [ $? -ne 0 ]; then
1681 echo "Unable to create a vfat Filesystem on $USBDEVICE" | tee -a $LOGFILE
1682 echo "Make sure your USB device is pluged in" | tee -a $LOGFILE
1683 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1684 MindiExit -1
1685 fi
1686 echo -en "."
1687 echo "Creating a vfat filesystem on $USBPART" >> $LOGFILE
1688 mkfs -t vfat $USBPART 2>&1 >> $LOGFILE
1689 if [ $? -ne 0 ]; then
1690 echo "Unable to create a vfat filesystem on $USBPART" | tee -a $LOGFILE
1691 echo "Make sure your USB device is pluged in and partitioned ($USBPART must exist on it)" | tee -a $LOGFILE
1692 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1693 MindiExit -1
1694 fi
1695 echo -en "."
1696 echo "Mounting $USBPART on $MINDI_TMP/usb" >> $LOGFILE
1697 mount $USBPART $MINDI_TMP/usb 2>> $LOGFILE
1698 if [ $? -ne 0 ]; then
1699 echo "Unable to mount $USBPART on $MINDI_TMP/usb" | tee -a $LOGFILE
1700 echo "Make sure your USB device is pluged in, partitioned and formated ($USBPART must exist on it)" | tee -a $LOGFILE
1701 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1702 MindiExit -1
1703 fi
1704 echo -en "."
1705 mkdir -p $MINDI_TMP/usb/{images,archives}
1706 cp -f $1/*.img $1/*.gz $MINDI_TMP/usb/images 2>> $LOGFILE || LogIt "OfferToMakeBootableUSB: Cannot copy $i to $MINDI_TMP/iso/images"
1707 echo -en "."
1708 old_pwd=`pwd`
1709 cd $MINDI_TMP/usb
1710 echo "mindi_lib = $MINDI_LIB" >> $LOGFILE
1711 for i in memdisk memtest.bin memtest.img ; do
1712 j=$MINDI_LIB/$i
1713 k=$MINDI_TMP/usb
1714 if [ -e "$j" ] ; then
1715 LogIt "Copying $j to $k"
1716 cp -f $j $k 2> /dev/null || Die "Failed to copy $j to $k"
1717 cp -f $j $MINDI_TMP 2> /dev/null || Die "Failed to copy $j to $MINDI_TMP"
1718 if [ _"$MONDO_SHARE" != _"" ]; then
1719 cp -f $j $MONDO_ROOT 2>> $LOGFILE || Die "Failed to copy $j to $MONDO_ROOT"
1720 fi
1721 fi
1722 done
1723 echo -en "."
1724 MakeSyslinuxMessageFile $MINDI_TMP/usb/message.txt
1725 echo -en "."
1726 cp $kernelpath $MINDI_TMP/usb/vmlinuz 2> /dev/null || Die "Cannot copy vmlinuz ($kernelpath) to mindi tmp ($MINDI_TMP/usb/syslinux/vmlinuz). Did you run out of disk space?"
1727 echo -en "."
1728 cp $MINDI_TMP/mindi.rdz $MINDI_TMP/usb/initrd.img 2>> $LOGFILE
1729 echo -en "."
1730 if [ _"$MONDO_SHARE" != _"" ]; then
1731 cp $kernelpath $MONDO_ROOT/vmlinuz 2> /dev/null || Die "Cannot copy vmlinuz ($kernelpath) to mondo root ($MONDO_ROOT/vmlinuz). Did you run out of disk space?"
1732 cp $MINDI_TMP/mindi.rdz $MONDO_ROOT/initrd.img 2> /dev/null || Die "Cannot copy mindi.rdz ($MINDI_TMP) to mondo root ($MONDO_ROOT/initrd.img). Did you run out of disk space?"
1733
1734 fi
1735 echo -en "."
1736 [ -e "$iso_cfg_file" ] || Die "FIXME - unable to find $iso_cfg_file - this should never occur"
1737 cat $sys_cfg_file | HackSyslinuxFile $ramdisk_size $MINDI_TMP/usb > syslinux.cfg || Die "Cannot copy syslinux.cfg from mindi_home to $MINDI_TMP/usb - did you run out of disk space?"
1738 echo -en "."
1739 if [ "$NFS_DEV" != "" ] ; then
1740 perl -pi -e 's/interactive/iso/' syslinux.cfg
1741 fi
1742 cd $old_pwd
1743 echo -en "."
1744 if [ "$ARCH" != "ia64" ] ; then
1745 if [ _"$MONDO_SHARE" != _"" ]; then
1746 cp -f $MINDI_TMP/usb/{syslinux.cfg,initrd.img,vmlinuz,message.txt} $MONDO_ROOT 2>> $LOGFILE || Die "Cannot copy core files to ramdisk for boot disk (under $MONDO_ROOT). Did you run out of disk space?"
1747 cp -f $MONDO_SHARE/autorun $MONDO_ROOT 2>> $LOGFILE
1748 fi
1749 umount $MINDI_TMP/usb
1750 syslinux $USBPART 2>> $MINDI_TMP/syslinux.log
1751 else
1752 echo "No USB boot support for ia64" | tee -a $LOGFILE
1753 umount $MINDI_TMP/usb
1754 MindiExit -1
1755 fi
1756 echo -en "."
1757 if [ "$?" -ne "0" ] ; then
1758 echo "----------- syslinux's errors --------------" |tee -a $LOGFILE
1759 cat $MINDI_TMP/syslinux.log |tee -a $LOGFILE
1760 LogIt "Failed to create USB image."
1761 else
1762 echo -e "$DONE"
1763 echo "Created bootable USB image on $USBDEVICE" >> $LOGFILE
1764 fi
1765 rm -f $MINDI_TMP/syslinux.log
1766 #
1767 # If mondoarchive, then tranfer $MINDI_CACHE content to the USB device
1768 # and mount that device under that mountpoint instead
1769 # Has to be done at the end here.
1770 #
1771 if [ _"$MONDO_SHARE" != _"" ]; then
1772 mount $USBPART $MINDI_TMP/usb 2>> $LOGFILE
1773 mv $MINDI_CACHE/* $MINDI_TMP/usb
1774 umount $MINDI_TMP/usb
1775 mount $USBPART $MINDI_CACHE
1776 fi
1777}
1778
1779
1780PluralOrNot() {
1781 [ "$1" -gt "1" ] && echo -en "s"
1782}
1783
1784
1785MakeMessageFile() {
1786 local disksize
1787 disksize=$1
1788 if [ "`grep -Fi "debian" /etc/issue.net 2> /dev/null`" ] ; then
1789 sed s/ZZZZZ/$MINDI_VERSION/ $MINDI_LIB/msg-txt | sed s/YYYYY/"Mondo Rescue"/ | sed s/XXXXX/"a cousin of"/ | sed s%DDDDD%"Debian GNU\/`uname -s` `cut -d ' ' -f 3 /etc/issue.net` `hostname`"% | sed s/KKKKK/"Kernel `uname -r` on a `uname -m`"/ | sed s/TTTTT/"`LC_TIME=C date`"/
1790 else
1791 sed s/ZZZZZ/$MINDI_VERSION/ $MINDI_LIB/msg-txt | sed s/YYYYY/"Mondo Rescue"/ | sed s/XXXXX/"a cousin of"/ | sed s/DDDDD/"`grep -i "linux" /etc/issue.net | head -n1 | tr -s ' ' ' '`"/ | sed s/KKKKK/"`grep -i "kernel" /etc/issue.net | head -n1 | tr -s ' ' ' '`"/ | sed s/TTTTT/"`LC_TIME=C date`"/ | sed s/' 'r' 'on' 'an' 'm/' '`uname -r`' 'on' 'an' '`uname -m`/
1792 fi
1793 if [ "$disksize" -gt "2880" ] ; then
1794 if [ _"$MONDO_SHARE" != _"" ]; then
1795 if [ "$CDRECOVERY" != "yes" ] ; then
1796 if [ "$NFS_DEV" != "" ] ; then
1797 echo -en "Press <enter> to continue.\n"
1798 elif [ ! "$MINDI_TMP" ] ; then
1799 echo -en "FYI, this is _not_ a Mondo Rescue CD.\n"
1800 else
1801 echo -en "$BOOT_MEDIA_MESSAGE"
1802 fi
1803 fi
1804 fi
1805 fi
1806 if [ "$CDRECOVERY" = "yes" ] ; then
1807 echo -en "\
1808To restore your disk to factory defaults, type 'RESTORE' <enter>.\n\
1809CAUTION: THIS WILL ERASE YOUR WHOLE DISK !!!\n"
1810 fi
1811 echo -en "\n\n\n"
1812}
1813
1814
1815write_full_floppy_of_kernel() {
1816 local mtpt image old_pwd res disksize
1817
1818 res=0
1819 old_pwd=`pwd`
1820 KERN_DISK_MADE=1
1821 disksize=$3
1822 rand1=$RANDOM
1823 rand2=$RANDOM
1824 image=$MINDI_TMP/$rand1.$rand2.img
1825 mtpt=$MINDI_TMP/$rand1.$rand2.mtpt
1826 dd if=/dev/zero of=$image bs=1k count=$disksize &> /dev/null
1827 echo "Creating ext2 filesystem on $image" >> $LOGFILE
1828 mke2fs -N 26 -F $image &> /dev/null || Die "Unable to create an ext2 file system on $image"
1829 mkdir -p $mtpt
1830 mount -o loop $image $mtpt
1831 cd $mtpt
1832 mkdir -p {dev,tmp,boot}
1833 cp -f $1 vmlinuz 2>> $LOGFILE
1834 if [ "$?" -ne "0" ] ; then
1835 LogIt "Failed to copy $1 to ramdisk"
1836 cd $old_pwd
1837 umount $mtpt
1838 rmdir $mtpt
1839 rm $image
1840 return 1
1841 fi
1842
1843 rdev vmlinuz 2,0
1844 rdev -R vmlinuz 0
1845 rdev -r vmlinuz 49152
1846
1847 tar -zxf $MINDI_LIB/dev.tgz || LogIt "Cannot untar dev.tgz"
1848 # BERLIOS : Useless and generating errors on CentOS ? (losetup miss a param)
1849 #losetup /dev/loop0 > /dev/null 2> /dev/null
1850 #[ "$?" -eq "0" ] || losetup /dev/loop0 -d || Die "Please free up /dev/loop0 by typing 'losetup /dev/loop0 -d'.\nReboot if necessary."
1851 CopyBootBFile $mtpt/boot.b
1852
1853 MakeLiloConfFile $disksize >> bdlilo.conf
1854
1855 chmod 644 bdlilo.conf
1856 MakeMessageFile $disksize > message
1857 lilo -v -C bdlilo.conf -r $mtpt
1858 res=$?
1859
1860 cd $old_pwd
1861 umount $mtpt
1862 mv -f $image $2
1863 rmdir $mtpt
1864
1865 return $res
1866}
1867
1868
1869MakeLiloConfFile() {
1870 local disksize options i ooo
1871 disksize=$1
1872 options=""
1873
1874 if [ "$ARCH" != "ia64" ] ; then
1875 echo -en "boot=/dev/loop0\ndisk=/dev/loop0\n"
1876 fi
1877 if [ "$disksize" -eq "2880" ] ; then
1878 echo -en "bios=0x00\nsectors=36\nheads=2\ncylinders=80\n"
1879 elif [ "$disksize" -gt "2880" ] ; then
1880 /bin/true
1881 else
1882 echo -en "bios=0x00\nsectors=18\nheads=2\ncylinders=80\n"
1883 fi
1884 if [ "$ARCH" != "ia64" ] ; then
1885 echo -en "install=/boot.b\nmap=/boot.map\n"
1886 fi
1887 if [ "$CDRECOVERY" = "yes" ] ; then
1888 echo -en "default=RESTORE\n"
1889 elif [ "$disksize" -gt "2880" ] && [ _"$MONDO_SHARE" != _"" ]; then
1890 if [ "$NFS_DEV" != "" ] ; then
1891 echo -en "default=iso\n"
1892 else
1893 echo -en "default=interactive\n"
1894 fi
1895 else
1896 echo -en "default=expert\n"
1897 fi
1898
1899 echo -en "prompt\n"
1900 if [ "$ARCH" != "ia64" ] ; then
1901 echo -en "vga=normal\nbackup=/dev/null\nmessage=/message\n"
1902 fi
1903 if [ "$CDRECOVERY" != "yes" ] ; then
1904 echo -en "timeout=300\n"
1905 fi
1906 echo -en "\n"
1907 if [ "$CDRECOVERY" = "yes" ] ; then
1908 options="RESTORE expert"
1909 elif [ "$disksize" -gt "2880" ] ; then
1910 if [ _"$MONDO_SHARE" != _"" ]; then
1911 if [ "$NFS_DEV" != "" ] ; then
1912 options="iso"
1913 else
1914 options="interactive expert compare iso nuke isonuke"
1915# hda hdb hdc hdd"
1916 fi
1917 else
1918 options="expert"
1919 fi
1920 else
1921 options="expert"
1922 fi
1923 for i in $options ; do
1924 ooo=$i
1925 [ "$ooo" = "RESTORE" ] && ooo="nuke"
1926 if [ "$ARCH" = "ia64" ] ; then
1927 rootpart="root=/dev/ram0\n\t"
1928 else
1929 rootpart=""
1930 fi
1931 outstr="image=/vmlinuz\n\tlabel=$i\n\tinitrd=/mindi.rdz\n\t${rootpart}append=\" rw ramdisk=$ramdisksize ramdisk_size=$ramdisksize maxcpus=1 $ooo_mode $ADDITIONAL_BOOT_PARAMS"
1932
1933 outstr=$outstr" $ooo_mode"
1934 outstr=$outstr"\"\n"
1935 if [ "$disksize" = "1440" ] ; then
1936 echo -en "$outstr" | sed s/initrd=.*// | grep -v root=
1937 else
1938 echo -en "$outstr"
1939 fi
1940 done
1941}
1942
1943
1944PrepareBootDiskImage_LILO() {
1945 local disksize imagesdir dev imagefile mountpoint fname i kernelpath ramdisksize cfg_file testpath options retval outstr old_pwd ooo max_kernel_size liloconf
1946 imagesdir=$1
1947 disksize=$2
1948 kernelpath=$3
1949 ramdisksize=$4
1950
1951 retval=0
1952 [ ! -e "$kernelpath" ] && Die "PBDI - cannot find $kernelpath kernel"
1953 echo -en "Making "$disksize"KB boot disk..."
1954 TurnTgzIntoRdz $MINDI_LIB/rootfs $MINDI_TMP/mindi.rdz $ramdisksize $disksize `du -sk $kernelpath | cut -f1` || Die "Could not turn rootfs into mindi.rdz; are you SURE your kernel supports loopfs?"
1955 if [ "$ARCH" != "ia64" ] ; then
1956 [ "$disksize" != "2880" ] && [ "$disksize" != "$BOOT_SIZE" ] && Die "PDBI - disksize is $disksize - bad size"
1957 fi
1958 echo -en "..."
1959 imagefile=$imagesdir/mindi-bootroot.$disksize.img
1960 mountpoint=$MINDI_TMP/mountpoint.$$
1961 mkdir -p $mountpoint
1962 dd if=/dev/zero of=$imagefile bs=1k count=$disksize &> /dev/null || Die "Cannot dd blank file"
1963 if [ "$ARCH" = "ia64" ] ; then
1964 mkdosfs $imagefile >> $LOGFILE 2>> $LOGFILE
1965 t=vfat
1966 else
1967 echo "Creating ext2 filesystem on $imagefile" >> $LOGFILE
1968 mke2fs -N 26 -m 0 -F $imagefile &> /dev/null || Die "Unable to create an ext2 file system on $imagefile"
1969 t=ext2
1970 fi
1971 mount -t $t -o loop $imagefile $mountpoint || LogIt "Cannot mount (PBDI)"
1972 # copy Mindi's skeleton fs & lilo/syslinux/whatever stuff into it
1973 mkdir -p $mountpoint/etc
1974 if [ "$ARCH" != "ia64" ] ; then
1975 liloconf=$mountpoint/etc/lilo.conf
1976 else
1977 liloconf=$mountpoint/elilo.conf
1978 fi
1979 old_pwd=`pwd`
1980 cd $mountpoint
1981 if [ "$ARCH" != "ia64" ] ; then
1982 tar -zxf $MINDI_LIB/dev.tgz || LogIt "Cannot untar dev.tgz"
1983 fi
1984 cd $old_pwd
1985 # BERLIOS : Useless and generating errors on CentOS ? (losetup miss a param)
1986 #losetup /dev/loop0 > /dev/null 2> /dev/null
1987 #[ "$?" -eq "0" ] || losetup /dev/loop0 -d || Die "Please free up /dev/loop0 by typing 'losetup /dev/loop0 -d'.\nReboot if necessary."
1988 CopyBootBFile $mountpoint/boot.b
1989
1990 MakeLiloConfFile $disksize > $liloconf
1991
1992 # Copy it so that CD-ROM menu entry is satisfied
1993 if [ "$ARCH" = "ia64" ] ; then
1994 mountefi=0
1995 df -T | grep /boot/efi | grep -q vfat
1996 if [ $? -ne 0 ]; then
1997 mount /boot/efi
1998 if [ $? -ne 0 ]; then
1999 echo "You have to mount your EFI partition when using mindi"
2000 MindiExit -1
2001 fi
2002 mountefi=1
2003 fi
2004 cp /boot/efi/elilo.efi $mountpoint
2005 cp $liloconf $mountpoint/elilo.efi $mountpoint/efi/boot
2006 if [ $mountefi -eq 1 ]; then
2007 umount /boot/efi 2>&1 > /dev/null
2008 fi
2009 fi
2010
2011 echo "Copying $MINDI_TMP/mindi.rdz to $mountpoint..." >> $LOGFILE
2012 cp -f $MINDI_TMP/mindi.rdz $mountpoint 2>> $LOGFILE
2013 if [ "$?" -ne "0" ] ; then
2014 LogIt "Failed to copy $MINDI_TMP/mindi.rdz to $mountpoint"
2015 cat $MINDI_TMP/mtpt.$$ >> $LOGFILE
2016 LogIt "Please unload some of your modules and try again."
2017 rm -f $MINDI_TMP/mtpt.$$
2018 LogIt "Cannot incorporate mindi.rdz in bootdisk (kernel / modules too big?)"
2019 retval=$(($retval+1))
2020 fi
2021 MakeMessageFile $disksize > $mountpoint/message
2022
2023 mkdir -p $mountpoint/tmp
2024 cp -f $MINDI_TMP/mondo-restore.cfg $mountpoint/tmp &> /dev/null
2025 if [ -e "$MINDI_LIB/memtest.img" ] ; then
2026 echo -en "image=/memtest.bin\nlabel=memtest\nn" >> $liloconf
2027 echo -en "image=/memdisk\nlabel=memtest\nappend=\"initrd=memtest.img\"\n" >> $liloconf
2028# echo "Yep, this is a multi-function CD" > $mountpoint/MULTIFUNC
2029 fi
2030
2031 # copy the kernel across
2032 [ "$mountpoint" != "" ] && rm -Rf $mountpoint/lost+found
2033 dd if=/dev/zero of=$mountpoint/zero bs=1k count=16 &> /dev/null
2034 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`
2035 cp -f $kernelpath $mountpoint/vmlinuz > /dev/null 2> /dev/null
2036 if [ "$?" -ne "0" ] || [ "$FORCE_DUAL_FLOPPIES" = "yes" ] ; then
2037 echo "Files at mountpoint ($mountpoint) :-" >> $LOGFILE
2038 du -sk $mountpoint/* >> $LOGFILE
2039 echo "--- end of list of files ---" >> $LOGFILE
2040 echo -en "Kernel size = `du -sk $kernelpath | cut -f1` K\nRamdisk free = $free_space K\n\
2041Sorry, your kernel is too big for a boot/root floppy.\nI'll try the new boot/root two-disk thingy.\n" >> $LOGFILE
2042 rm -f $mountpoint/vmlinuz
2043 cd $old_pwd
2044 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
2045 rmdir $mountpoint || LogIt "Cannot rmdir (PBDI)"
2046 # losetup /dev/loop0 -d
2047 res=0
2048 write_full_floppy_of_kernel $kernelpath $imagesdir/mindi-boot.1440.img 1440
2049 res=$(($res+$?))
2050 cp -f $MINDI_TMP/mindi.rdz $imagesdir/mindi-root.1440.img 2>> $LOGFILE
2051 res=$(($res+$?))
2052 rm -f $imagefile
2053 if [ "$res" -ne "0" ]; then
2054 LogIt "WARNING - failed to create 1.44MB boot/root floppies"
2055 rm -f $imagesdir/mindi-*.1440.img
2056 fi
2057 return $res
2058 fi
2059 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`
2060 max_kernel_size=$(($free_space+`du -sk $kernelpath | cut -f1`))
2061 echo "Free space left on floppy = $free_space KB" >> $LOGFILE
2062 echo "Max kernel size on $disksize KB floppy (est'd) = $max_kernel_size K" >> $LOGFILE
2063# make it bootable
2064 rm -f $mountpoint/zero
2065 [ -e "$MINDI_LIB/memdisk" ] && cp -f $MINDI_LIB/memdisk $mountpoint 2>> $LOGFILE
2066 if [ "$disksize" -gt "2880" ] && [ ! "$KERN_DISK_MADE" ] ; then
2067 if [ "$ARCH" != "ia64" ] ; then
2068 $LILO_EXE -r $mountpoint >> $LOGFILE 2>> $LOGFILE
2069 else
2070 /bin/true
2071 fi
2072 elif [ ! "$KERN_DISK_MADE" ] ; then
2073# 12/28/2001 - if 1.72MB floppy then don't use LILO's optimizations at all
2074 $LILO_EXE -r $mountpoint >> $LOGFILE 2>> $LOGFILE
2075 else
2076 echo "Not running LILO. It's not that kind of disk." >> $LOGFILE
2077 fi
2078
2079 # BERLIOS does not test necessarily what it expects
2080 if [ $? -ne "0" ] ; then
2081 if [ "`grep -F "/tmp/dev.0" $LOGFILE`" ] ; then
2082 LogIt "The '/tmp/dev.0' error is NOT Mindi's fault. It is LILO's."
2083 LogIt "Please reboot your PC as a workaround."
2084 Die "LILO sneezed and Mindi caught a cold. Please read the README / FAQ."
2085 fi
2086 echo "$LILO_EXE -r $mountpoint ...failed."
2087 echo -en "Press ENTER to continue."; read line
2088 LogIt "Cannot run lilo on $mountpoint\nPlease upgrade/downgrade your version of LILO. It has a bug."
2089 retval=$(($retval+1))
2090 fi
2091 cp -f $liloconf $MINDI_TMP/lilo.conf 2>> $LOGFILE
2092 if [ "$ARCH" = "ia64" ] ; then
2093 cp `dirname $kernelpath`/*.efi $mountpoint 2>> $LOGFILE
2094 fi
2095 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
2096 echo -en "..."
2097 rmdir $mountpoint || LogIt "Cannot rmdir (PBDI)"
2098 if [ "$retval" -eq "0" ] ; then
2099 echo -en "...$DONE\n"
2100 if [ "$KERN_DISK_MADE" ] ; then
2101 LogIt "$disksize KB boot disks were created OK\n"
2102 fi
2103 else
2104 echo -en "...failed\n"
2105 LogIt $disksize"KB boot disk was NOT created\n"
2106 rm -f $imagefile
2107 fi
2108 [ "$retval" -ne "0" ] && LogIt "PrepareBootDiskImage() is returning nonzero"
2109 return $retval
2110}
2111
2112
2113PrepareBootDiskImage_SYSLINUX() {
2114 local disksize imagesdir dev imagefile mountpoint fname i kernelpath ramdisksize cfg_file testpath options retval outstr old_pwd ooo max_kernel_size bootimage
2115 imagesdir=$1
2116 disksize=$2
2117 kernelpath=$3
2118 ramdisksize=$4
2119 do_boot_root_thingy=""
2120 local retval old_pwd
2121 retval=0
2122
2123 [ ! -e "$kernelpath" ] && Die "PBDI - cannot find $kernelpath kernel"
2124 echo -en "Making "$disksize"KB boot disk..."
2125 TurnTgzIntoRdz $MINDI_LIB/rootfs $MINDI_TMP/mindi.rdz $ramdisksize $disksize `du -sk $kernelpath | cut -f1` || Die "Could not turn rootfs into mindi.rdz; are you SURE your kernel supports loopfs?"
2126 [ "$disksize" != "2880" ] && [ "$disksize" != "$BOOT_SIZE" ] && Die "PDBI - disksize is $disksize - bad size"
2127 echo -en "..."
2128 imagefile=$imagesdir/mindi-bootroot.$disksize.img
2129 mountpoint=$MINDI_TMP/mountpoint.$$
2130 mkdir -p $mountpoint
2131 dd if=/dev/zero of=$imagefile bs=1k count=$disksize &> /dev/null || Die "Cannot dd blank file"
2132 echo "Creating vfat filesystem on $imagefile" >> $LOGFILE
2133 mkfs.vfat $imagefile >> $LOGFILE 2>> $LOGFILE
2134 syslinux $imagefile >> $LOGFILE 2>> $LOGFILE
2135
2136 mount -t vfat -o loop $imagefile $mountpoint || LogIt "Cannot mount (PBDI)"
2137
2138 # copy Mindi's skeleton fs & lilo/syslinux/whatever stuff into it
2139 old_pwd=`pwd`
2140 MakeSyslinuxMessageFile $mountpoint/message.txt
2141 cd $mountpoint
2142 [ -e "$sys_cfg_file" ] || Die "Obi Wan, word up?"
2143 cat $sys_cfg_file | HackSyslinuxFile $ramdisk_size $mountpoint > syslinux.cfg || Die "Cannot copy syslinux.cfg from mindi_home to tmp_root"
2144 if [ "$NFS_DEV" != "" ] ; then
2145 perl -pi -e 's/interactive/iso/' syslinux.cfg
2146 fi
2147 cd $old_pwd
2148 echo "Copying $MINDI_TMP/mindi.rdz to $mountpoint/initrd.img..." >> $LOGFILE
2149 cp -f $MINDI_TMP/mindi.rdz $mountpoint/initrd.img 2>> $LOGFILE
2150 if [ "$?" -ne "0" ] ; then
2151 LogIt "Failed to copy $MINDI_TMP/mindi.rdz to $mountpoint"
2152 cat $MINDI_TMP/mtpt.$$ >> $LOGFILE
2153 LogIt "Please unload some of your modules and try again."
2154 rm -f $MINDI_TMP/mtpt.$$
2155 LogIt "Cannot incorporate mindi.rdz in bootdisk (kernel / modules too big?)"
2156 retval=$(($retval+1))
2157 fi
2158
2159 mkdir -p $mountpoint/tmp
2160 cp -f $MINDI_TMP/mondo-restore.cfg $mountpoint/tmp &> /dev/null
2161
2162 # copy the kernel across
2163 [ "$mountpoint" != "" ] && rm -Rf $mountpoint/lost+found
2164 dd if=/dev/zero of=$mountpoint/zero bs=1k count=16 &> /dev/null
2165 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`
2166 cp -f $kernelpath $mountpoint/vmlinuz &> /dev/null
2167 if [ "$?" -ne "0" ] || [ "$FORCE_DUAL_FLOPPIES" = "yes" ] ; then
2168 echo "Files at mountpoint ($mountpoint) :-" >> $LOGFILE
2169 du -sk $mountpoint/* >> $LOGFILE
2170 echo "--- end of list of files ---" >> $LOGFILE
2171 echo -en "Kernel size = `du -sk $kernelpath | cut -f1` K\nRamdisk free = $free_space K\n\
2172Sorry, your kernel is too big for a boot/root floppy.\nI'll try the new boot/root two-disk thingy.\n" >> $LOGFILE
2173 rm -f $mountpoint/vmlinuz
2174 cd $old_pwd
2175 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
2176 rmdir $mountpoint || LogIt "Cannot rmdir (PBDI)"
2177
2178 res=0
2179 write_full_floppy_of_kernel $kernelpath $imagesdir/mindi-boot.1440.img 1440
2180 res=$(($res+$?))
2181 cp -f $MINDI_TMP/mindi.rdz $imagesdir/mindi-root.1440.img 2>> $LOGFILE
2182 res=$(($res+$?))
2183 rm -f $imagefile
2184 if [ "$res" -ne "0" ]; then
2185 LogIt "WARNING - failed to create 1.44MB boot/root floppies"
2186 rm -f $imagesdir/mindi-*.1440.img
2187 fi
2188 return $res
2189 fi
2190 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`
2191 max_kernel_size=$(($free_space+`du -sk $kernelpath | cut -f1`))
2192 echo "Free space left on floppy = $free_space KB" >> $LOGFILE
2193 echo "Max kernel size on $disksize KB floppy (est'd) = $max_kernel_size K" >> $LOGFILE
2194
2195 # make it bootable
2196 rm -f $mountpoint/zero
2197 mkdir -p $mountpoint/etc
2198 [ -e "$MINDI_LIB/memdisk" ] && cp -f $MINDI_LIB/memdisk $mountpoint 2>> $LOGFILE
2199 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
2200 echo -en "..."
2201 rmdir $mountpoint || LogIt "Cannot rmdir (PBDI)"
2202
2203 if [ "$retval" -eq "0" ] ; then
2204 echo -en "...$DONE\n"
2205 if [ "$KERN_DISK_MADE" ] ; then
2206 rm -f $imagefile
2207 LogIt "$disksize KB boot disks were created OK\n"
2208 fi
2209 else
2210 echo -en "...failed\n"
2211 LogIt $disksize"KB boot disk was NOT created\n"
2212 rm -f $imagefile
2213 fi
2214 [ "$retval" -ne "0" ] && LogIt "PrepareBootDiskImage() is returning nonzero"
2215 return $retval
2216}
2217
2218
2219PrepareDataDiskImages() {
2220 local needlist bigdir minidir_root tardir diskdir imagesdir res i j k old_pwd lines lfiles
2221
2222 imagesdir=$1
2223 rm -f $imagesdir/mindi-*.img $imagesdir/[0-9]*.tar.gz $imagesdir/mindi.iso
2224 needlist=$MINDI_TMP/what-we-need.txt
2225 bigdir=$MINDI_TMP/bigdir
2226 minidir_root=$MINDI_TMP/minidir
2227 mkdir -p $minidir_root
2228 mkdir -p $bigdir/usr/bin
2229 tardir=$MINDI_TMP/tardir
2230
2231 if [ -e "$DEPLIST_FILE" ]; then
2232 lfiles="$DEPLIST_FILE $DEPLIST_DIR/*"
2233 else
2234 lfiles="$DEPLIST_DIR/*"
2235 fi
2236 lines=`grep -vx " *#.*" $lfiles | grep -vx "" | wc -l`
2237 cat $lfiles | GenerateGiantDependencyList $needlist $lines
2238 res=$?
2239 if [ "$YOUR_KERNEL_SUCKS" ]; then
2240 pwd=`pwd`
2241 cd $MINDI_TMP
2242 for i in `ListKernelModulePaths | HackPathsToFailsafe` ; do
2243 cp --parents -pRdf ./$i $bigdir 2>> $LOGFILE || Die "PDDI can't cp $i->$bigdir"
2244 if [ "`du -sk $i | cut -f1`" -lt "$(($CHOPSIZE*2))" ] ; then
2245 cp --parents -pRdf $i $bigdir 2>> $LOGFILE
2246 else
2247 ChopUpAndCopyFile $i $bigdir $CHOPSIZE $BIGNO
2248 BIGNO=$(($BIGNO+1))
2249 fi
2250 done
2251 for i in $EXTRA_MODS ; do
2252 j=`find lib/modules/$FAILSAFE_KVER -name $i.*o 2> /dev/null`
2253 [ ! "$j" ] && echo "WARNING - cannot find failsafe module $i.o" >> $LOGFILE
2254 for k in $j ; do
2255 if [ "`du -sk $k | cut -f1`" -lt "$CHOPSIZE" ] ; then
2256 cp --parents -pRdf $k $bigdir 2>> $LOGFILE
2257 else
2258 ChopUpAndCopyFile $k $bigdir $CHOPSIZE $BIGNO
2259 BIGNO=$(($BIGNO+1))
2260 fi
2261 echo "Added failsafe module $k to ramdisk" >> $LOGFILE
2262 done
2263 done
2264 cd $pwd
2265 else
2266 ListKernelModulePaths >> $needlist
2267 fi
2268 if [ "$res" -ne "0" ] ; then
2269 Die "You have $res file`PluralOrNot $res` present in dependency list\nbut absent from filesystem."
2270 fi
2271 FindAndAddUserKeyboardMappingFile
2272 mkdir -p $bigdir/tmp
2273 if [ _"$MONDO_SHARE" != _"" ]; then
2274 cp -f $MONDORESTORECFG $bigdir/tmp &> /dev/null
2275 fi
2276 [ -d "/mnt/.boot.d" ] && echo "Oh Jebus" > $bigdir/tmp/DUMBASS-GENTOO
2277 DropOptimizedLibraries $needlist $bigdir
2278 echo -en "Assembling dependency files"
2279 CopyDependenciesToDirectory < $needlist $bigdir
2280
2281 # also copy io.sys and msdos.sys, if we can find them
2282 for i in `mount | cut -d' ' -f3` ; do
2283 for j in io.sys msdos.sys ; do
2284 [ -e "$i/$j" ] && cp -f $i/$j $bigdir 2>> $LOGFILE
2285 done
2286 done
2287
2288 # master boot record, too
2289 if [ _"$MONDORESTORECFG" != _"" ]; then
2290 i=`grep bootloader.device $MONDORESTORECFG | cut -d'=' -f2 2> /dev/null`
2291 if [ "$i" ] ; then
2292 LogIt "Backing up $i's MBR"
2293 dd if=$i of=$bigdir/BOOTLOADER.MBR bs=446 count=1 >> $LOGFILE 2>> $LOGFILE
2294 sleep 1
2295 sync
2296 j=$i
2297 [ -h "$j" ] && j=`readlink -f $j`
2298 LogIt "Creating /dev/boot_device ($j)"
2299 mkdir -p $bigdir/dev
2300 cp -pRdf $j $bigdir/dev/boot_device 2> /dev/null || Die "Unable to create /dev/boot_device on ramdisk"
2301 fi
2302 fi
2303
2304 old_pwd=`pwd`
2305 cd $bigdir
2306
2307 [ -e "$MINDI_LIB/aux-tools" ] || Die "aux-tools not found in Mindi's home dir. Do you have multiple copies of Mindi lying around? Please delete them. No, don't e-mail me and ask how. ;) Use 'rm'."
2308 cp -Rdf $MINDI_LIB/aux-tools/* . 2>> $LOGFILE || LogIt "WARNING - error occurred while unzipping aux-tools"
2309 if [ -e "$MINDI_LIB/x11-tools.tgz" ] ; then
2310 tar -zxf $MINDI_LIB/x11-tools.tgz 2>> $LOGFILE || LogIt "WARNING - error occurred while unzipping x11-tools.tgz"
2311 fi
2312 if [ -e "$MONDO_SHARE/restore-scripts" ]; then
2313 cp -Rdf $MONDO_SHARE/restore-scripts/* . 2>> $LOGFILE
2314 [ "$?" -ne "0" ] && [ _"$MONDO_SHARE" != _"" ] && Die "Cannot find/install $MONDO_SHARE/restore-scripts"
2315 fi
2316 [ -d "/lib/dev-state" ] && cp --parents -pRdf /lib/dev-state . 2>> $LOGFILE
2317 cd $old_pwd
2318 echo -e "$DONE"
2319 TOTAL_BIGDIR_SIZE=`du -sk $bigdir | cut -f1`
2320 SplitDirectoryIntoMinidirs $bigdir $minidir_root
2321 noof_disks=$?
2322 [ "$noof_disks" -eq "0" ] && Die "Too much stuff!"
2323 MakeMountlist $MINDI_TMP/mountlist.txt
2324 mkdir -p $minidir_root/$noof_disks/tmp
2325 cp -f $MINDI_TMP/mountlist.txt $minidir_root/$noof_disks/tmp/mountlist.txt 2> /dev/null || Die "Cannot copy mountlist.txt from $MINDI_TMP to data disk"
2326 if [ _"$MONDO_SHARE" != _"" ]; then
2327 cp -f $minidir_root/$noof_disks/tmp/mountlist.txt $MINDI_TMP/. 2>> $LOGFILE
2328 fi
2329 [ $LVM != "false" ] && $MINDI_LIB/analyze-my-lvm > $minidir_root/$noof_disks/tmp/i-want-my-lvm || LVM="false"
2330 cat $minidir_root/$noof_disks/tmp/mountlist.txt >> $LOGFILE
2331 ZipMinidirsIntoTarballs $minidir_root $tardir $noof_disks
2332 CreateDataDiskImagesFromTarballs $tardir $imagesdir $noof_disks
2333 FRIENDLY_OUTSTRING="Boot and data disk images were created."
2334 # One 1.72MB boot disk, one 2.88MB boot disk and $noof_disks data disk images
2335 rmdir $tardir $bigdir
2336 rm -f $needlist
2337 return $noof_disks
2338}
2339
2340
2341ProcessLDD() {
2342 local incoming f
2343 read incoming
2344 while [ "$incoming" != "" ] ; do
2345 # We take the full path name of the dyn. lib. we want
2346 incoming=`echo "$incoming" | awk '{if (match($1,/\//)) {print $1} else {if (match($3,/\//)) print $3} fi}'`
2347 for f in $incoming ; do
2348 echo "$f `ReadAllLink $f`"
2349 done
2350 read incoming
2351 done
2352}
2353
2354
2355Prompt() {
2356 echo -en "$1"
2357 read line
2358}
2359
2360
2361ReadLine() {
2362 local i incoming
2363 read incoming
2364 i=0
2365 while [ "$i" -le "32" ] && [ "$incoming" = "" ] ; do
2366 i=$(($i+1))
2367 read incoming
2368 done
2369 echo "$incoming"
2370}
2371
2372
2373RejigHyperlinks() {
2374 local minidir_root noof_disks fname path diskno old_pwd awk_loc gawk_loc dir i
2375 minidir_root=$1
2376 noof_disks=$2
2377
2378 old_pwd=`pwd`
2379 diskno=1
2380 while [ "$diskno" -le "$noof_disks" ] ; do
2381 mkdir -p $minidir_root/$diskno
2382 cd $minidir_root/$diskno
2383 for fname in `find -type d -o -print` ; do
2384 [ -h "$minidir_root/$diskno/$fname" ] && MoveHyperlinkSensibly $fname $minidir_root $diskno $noof_disks
2385 done
2386 diskno=$(($diskno+1))
2387 done
2388
2389 cd $old_pwd
2390 return
2391}
2392
2393
2394ReplaceIndividualLine() {
2395 local orig_file new_file lino newstring lines_total lines_remaining
2396
2397 orig_file=$1.orig
2398 mv -f $1 $orig_file || Die "Cannot move $1 to $orig_file"
2399 new_file=$1
2400 lino=$2
2401 newstring="$3"
2402 if [ "$lino" = "" ] || [ "$lino" -lt "1" ] ; then
2403 echo "Can't find string" >> $LOGFILE
2404 return 1
2405 fi
2406 lines_total=`wc -l $orig_file | $AWK '{print $1;}'`
2407 lines_remaining=$(($lines_total-$lino))
2408 head -n$(($lino-1)) $orig_file > $new_file
2409 echo "$newstring" >> $new_file
2410 echo "# The above line was added by Mindi, at the user's instruction" >> $new_file
2411 tail -n$lines_remaining $orig_file >> $new_file
2412 echo "Replace line $lino of $new_file with user-specified line, '$newstring'" >> $LOGFILE
2413 [ -x "$orig_file" ] && chmod +x $new_file
2414 rm -f $orig_file
2415 return 0
2416}
2417
2418
2419ScanCDandTape() {
2420 local i
2421
2422 for i in /dev/st0 /dev/ht0 /dev/cdrom /dev/cdrom0 /dev/cdrom 1 ; do
2423 dd if=$i of=/dev/null bs=64k count=1 &> /dev/null
2424 done
2425}
2426
2427
2428SizeOfPartition() {
2429 local devpath drive res stub
2430 device=$1
2431 if [ "`echo "$device" | grep -F "/dev/md"`" != "" ] ; then
2432 res=`SizeOfRaidPartition $device`
2433 [ "$res" = "" ] && Die "Cannot find $device's size - is your /etc/raidtab sane?"
2434 echo "$res"
2435 return 0
2436 fi
2437 # patch from Bill <bill@iwizard.biz> - 2003/08/25
2438 res=`$FDISK -s $device 2>> $LOGFILE`
2439 # end patch
2440 [ "$res" = "" ] && res=`df -k -P -x supermount | tr -s '\t' ' ' | grep -F "$device " | cut -d' ' -f2`
2441 [ "$res" = "" ] && res="-1"
2442 echo $res
2443 return 0
2444}
2445
2446
2447SizeOfRaidPartition() {
2448 local real_dev smallest_size silly tmp
2449
2450 silly=999999999
2451 smallest_size=$silly
2452
2453 for real_dev in `GetRaidDevMembers $1` ; do
2454 tmp=`SizeOfPartition $real_dev`
2455 [ "$tmp" -lt "$smallest_size" ] && smallest_size=$tmp
2456 done
2457
2458 if [ "$smallest_size" = "$silly" ] ; then
2459 echo "-1"
2460 return 1
2461 else
2462 echo "$smallest_size"
2463 return 0
2464 fi
2465}
2466
2467
2468StripComments()
2469{
2470 local tempfile
2471
2472 tempfile=$MINDI_TMP/$$.strip.txt
2473 cp -f $1 $tempfile 2>> $LOGFILE
2474 $AWK '{if (substr($0,0,1)!="#" || substr($0,0,3)=="#!/") {print $0;};}' $tempfile > $1
2475 rm -f $tempfile
2476 echo "Stripped comments from $2" >> $LOGFILE
2477}
2478
2479
2480SplitDirectoryIntoMinidirs() {
2481 local bigdir minidir_root i noof_disks old_pwd res
2482
2483 bigdir=$1
2484 minidir_root=$2
2485 [ "$minidir_root" != "" ] && rm -Rf $minidir_root/*
2486
2487 TryToFitDataIntoSeveralDirs $bigdir $minidir_root
2488 noof_disks=$?
2489 if [ "$noof_disks" -eq "0" ] ; then
2490 echo "Failed to fit data into several dirs."
2491 return 0
2492 fi
2493 RejigHyperlinks $minidir_root $noof_disks
2494 [ "$bigdir" != "" ] && rm -Rf $bigdir/*
2495 return $noof_disks
2496}
2497
2498
2499StripExecutable()
2500{
2501 local tmpfile
2502
2503 tmpfile=$MINDI_TMP/stripped.$$.dat
2504 [ -d "$1" ] || [ -h "$1" ] && return
2505 cp -f $1 $tmpfile 2>> $LOGFILE
2506 strip $tmpfile 2> /dev/null
2507 if [ "$?" -eq "0" ] ; then
2508 cp -f $tmpfile $1 2>> $LOGFILE
2509 echo "Stripped binary $2" >> $LOGFILE
2510 fi
2511 rm -f $tmpfile
2512}
2513
2514
2515TemporarilyCompressAllFiles() {
2516 local i orig_fname out_fname out_list
2517
2518 i=0
2519 out_list=$2/compressed/compressed.txt
2520 mkdir -p $2/compressed
2521 > $out_list
2522 for orig_fname in $1 ; do
2523 out_fname=$2/compressed/$orig_fname.gz
2524 mkdir -p $out_fname 2> /dev/null
2525 rmdir $out_fname 2> /dev/null
2526 gzip -c6 $orig_fname > $out_fname 2> /dev/null
2527 i=$(((($i+1))%15))
2528 [ "$i" -eq "0" ] && echo -en "."
2529 du -sk $out_fname >> $out_list
2530 done
2531}
2532
2533
2534TryToFindKernelPath() {
2535 local fname incoming res fkern_ver we_want_version possible_kernels noof_kernels kernelpath kdate duff_kernels
2536
2537 we_want_version=`uname -r`
2538 possible_kernels=""
2539 duff_kernels=""
2540
2541 if [ "$ARCH" = "ia64" ] ; then
2542 root="/boot/efi/efi"
2543 else
2544 root="/"
2545 fi
2546 for fname in `find $root -maxdepth 2 -type f | grep -F lin | grep -Ev '^/proc/|^/net/'` ; do
2547 [ ! -e "$fname" ] && continue
2548 [ "$fname" = "/boot/vmlinuz.shipped" ] && [ -f "/boot/vmlinuz" ] && continue; # ignore SuSE's extra kernel
2549 file $fname | grep -q gzip
2550 if [ "$?" -eq "0" ] ; then
2551 # Used by ia64
2552 fkern_ver=`gzip -cd $fname | strings 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
2553 else
2554 fkern_ver=`strings $fname 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
2555 fi
2556 [ "$fkern_ver" = "" ] && continue
2557 [ "`echo "$fkern_ver" |grep -F "$we_want_version "`" = "" ] && continue
2558 [ -f "$fname" ] || continue
2559 [ -h "$fname" ] && continue
2560 kdate=`uname -v | $AWK '{for(i=1;i<NF;i++){if(index($i,":")){print $i;};};}' | $AWK '{print $NF;}'`
2561 file $fname | grep -q gzip
2562 if [ "$?" -eq "0" ] ; then
2563 # Used by ia64
2564 if [ "`gzip -cd $fname | strings 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
2565 LogIt "Have you recompiled your kernel \"$fname\" w/o rebooting? Naughty but I'll allow it..."
2566 duff_kernels="$fname $duff_kernels"
2567 else
2568 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2569 possible_kernels="$fname $possible_kernels"
2570 fi
2571 else
2572 if [ "`strings $fname 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
2573 LogIt "Have you recompiled your kernel \"$fname\" w/o rebooting?\n Naughty but I'll allow it..."
2574 duff_kernels="$fname $duff_kernels"
2575 else
2576 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2577 possible_kernels="$fname $possible_kernels"
2578 fi
2579 fi
2580 done
2581 if [ ! "$possible_kernels" ] && uname -a | grep Knoppix > /dev/null ; then
2582 possible_kernels=`find /boot/vmlinuz-2.* | tail -n1`
2583 fi
2584 if [ ! "$possible_kernels" ] ; then
2585 LogIt "No kernel matches exactly. Are there any duff kernels?"
2586 possible_kernels="$duff_kernels"
2587 if [ ! "$possible_kernels" ] ; then
2588 LogIt "Sorry, no duff kernels either"
2589 else
2590 LogIt "I bet you're running Debian or Gentoo, aren't you?"
2591 LogIt "Your kernel doesn't have a sane builddate. Oh well..."
2592 fi
2593 fi
2594 possible_kernels=`echo "$possible_kernels" | tr -s ' ' '\n' | sort -u | tr '\n' ' '`
2595 noof_kernels=`CountItemsIn "$possible_kernels"`
2596 if [ "$noof_kernels" -eq "0" ] ; then
2597 LogIt "Could not find your kernel."
2598 if [ -e "/boot/vmlinuz" ] ; then
2599 LogIt "Using /boot/vmlinuz as a last resort."
2600 output=/boot/vmlinuz
2601 else
2602 output=""
2603 fi
2604 elif [ "$noof_kernels" -eq "1" ] ; then
2605 kernelpath=`echo "$possible_kernels" | sed s/' '//`
2606 echo "Your kernel is $kernelpath (v`uname -r`)" >> $LOGFILE
2607 output="$kernelpath"
2608 else
2609 for i in $possible_kernels ; do
2610 if echo $i | grep "`uname -r`" ; then
2611 LogIt "OK, I used my initiative and found that "
2612 LogIt "$i is probably your kernel. "
2613 output="$i"
2614 return
2615 fi
2616 done
2617 if echo " $possible_kernels " | grep -F "/boot/vmlinuz " &> /dev/null ; then
2618 output=/boot/vmlinuz
2619 echo "Schlomo, this one's for you." >> $LOGFILE
2620 else
2621 LogIt "Two or more possible kernels found. You may specify any one of them and the "
2622 LogIt "boot disks will still work, probably. If one does not work, try another."
2623 LogIt "$possible_kernels"
2624 echo ""
2625 fi
2626 fi
2627 echo "$output" | tr -s ' ' '\n' | sort -u | tr '\n' ' '
2628}
2629
2630
2631TryToFitDataIntoSeveralDirs() {
2632 local bigdir minidir_root noof_disks diskno list_of_files filename old_pwd progress
2633 local i retval noof_disks total_files list_of_devs
2634
2635 bigdir=$1
2636 minidir_root=$2
2637 BIG_CLUNKY_SIZE_COUNTER=0
2638 retval=0
2639 noof_disks=1
2640
2641 echo -en "\r \rDividing data into several groups..."
2642 old_pwd=`pwd`
2643 cd $bigdir
2644 list_of_files=`GetFileSizeList . | sort -nr | cut -f2 | grep -Fv "/dev/"`
2645 progress=0
2646 total_files=`CountItemsIn "$list_of_files"`
2647 if [ "`echo "$filename" | grep -x "/dev/.*"`" ] ; then
2648 filesize=1
2649 fi
2650 mkdir -p $minidir_root/$noof_disks
2651 if [ -e "dev" ] ; then
2652 echo "Copying dev/* to $minidir_root/$noof_disks" >> $LOGFILE
2653 cp --parents -pRdf dev $minidir_root/$noof_disks 2>> $LOGFILE
2654 fi
2655 TemporarilyCompressAllFiles "$list_of_files" $minidir_root
2656 for filename in $list_of_files ; do
2657 AddFileToDir $filename $minidir_root $noof_disks
2658 i=$?
2659 if [ "$i" -gt "$noof_disks" ] ; then
2660 noof_disks=$i
2661 echo -en "\r\t\t\t\t\t\t($noof_disks disks)"
2662 fi
2663 if [ "$i" -eq "0" ] ; then
2664 LogIt "Cannot add file $filename to minidir $minidir_root"
2665 retval=$(($retval+1))
2666 fi
2667 progress=$(($progress+1))
2668 echo -en "\r\t\t\t\t\t\t\t\t$(($progress*100/$total_files))% complete\r"
2669 done
2670 cd $old_pwd
2671 echo -en "\rThe files have been subdivided into $noof_disks directories. \r"
2672 [ "$minidir_root" != "" ] && rm -Rf $minidir_root/compressed
2673 if [ "$retval" -gt "0" ] ; then
2674 return 0
2675 else
2676 return $noof_disks
2677 fi
2678}
2679
2680
2681TurnTgzIntoRdz() {
2682 local tgz_dir_fname rdz_fname ramdisksize tempfile mountpoint old_pwd nodes disksize kernelsize maxsize res currsize not_copied j k floppy_modules s w
2683
2684 tgz_dir_fname=$1
2685 rdz_fname=$2
2686 ramdisksize=$3
2687 disksize=$4
2688 kernelsize=$5
2689 maxsize=$(($disksize-$kernelsize))
2690 maxsize=$(($maxsize*2)); # to allow for compression of 50%
2691 tempfile=$MINDI_TMP/temp.rd
2692 mountpoint=$MINDI_TMP/mnt1
2693 res=0
2694 echo -en "..."
2695 dd if=/dev/zero of=$tempfile bs=1k count=$ramdisk_size &> /dev/null || Die "Not enough room for temporary ramdisk (TurnTgzIntoRdz)"
2696 echo -en "..."
2697 echo "Creating ext2 filesystem on $tempfile" >> $LOGFILE
2698 mke2fs -b 1024 -m 1 -i 2048 -F $tempfile &> /dev/null || Die "Unable to create an ext2 file system on $tempfile"
2699 echo -en "..."
2700 mkdir -p $mountpoint
2701 mount -t ext2 -o loop $tempfile $mountpoint || Die "Cannot loopmount $tempfile to $mountpoint! The reason may be missing support for loopfs or ext2 (or both) in the running kernel."
2702 echo -en "..."
2703 old_pwd=`pwd`
2704 cd $mountpoint
2705 cp -Rdf $tgz_dir_fname/* . 2>&1 >> $LOGFILE
2706 tar -zxf symlinks.tgz || Die "Cannot untar symlinks.tgz"
2707 cd dev || Die "Can't cd to dev"
2708 tar -zxf dev-entries.tgz || Die "Cannot untar dev-entries.tgz"
2709 rm -f dev-entries.tgz
2710 cd ..
2711
2712 for w in insmod.static insmod.static.old ; do
2713 s=`which $w 2> /dev/null`
2714 if [ -e "$s" ] ; then
2715 cp --parents -af $s . 2>> $LOGFILE
2716 fi
2717 done
2718
2719 mkdir -p tmp
2720 [ -e "/dev/.devfsd" ] && echo "/dev/.devfsd found" > tmp/USE-DEVFS
2721 for w in cdrom floppy groovy-stuff ; do
2722 mkdir -p mnt/$w
2723 done
2724 #if [ "$RUN_AFTER_INITIAL_BOOT_PHASE" ] ; then
2725 #ReplaceIndividualLine sbin/init `grep -n "#WHOLIVESINAPINEAPPLEUNDERTHESEA#" sbin/init | cut -d':' -f1` "$RUN_AFTER_INITIAL_BOOT_PHASE"
2726 #fi
2727 if [ "$RUN_AFTER_BOOT_PHASE_COMPLETE" ] ; then
2728 ReplaceIndividualLine sbin/init `grep -n "#ABSORBENTANDYELLOWANDPOROUSISHE#" sbin/init | cut -d':' -f1` "$RUN_AFTER_BOOT_PHASE_COMPLETE"
2729 fi
2730
2731 cp --parents -Rdf /dev/fd0*[1,2][4,7,8]* . 2> /dev/null
2732 cd $old_pwd
2733 echo -en "..."
2734 MakeModuleLoadingScript $TMPMODPROBE_FLAG $mountpoint/sbin/insert-all-my-modules
2735 echo -en "..."
2736 old_pwd=`pwd`
2737 if [ "$YOUR_KERNEL_SUCKS" ] ; then
2738 cd $MINDI_TMP
2739 floppy_modules_path=lib/modules/$FAILSAFE_KVER
2740 else
2741 cd /
2742###
2743### Sq-Modification... Use kernel name in module path if specified.
2744###
2745 #floppy_modules_path=lib/modules/`uname -r`
2746 if [ "${kernelname}" != "" ]
2747 then
2748 floppy_modules_path=lib/modules/${kernelname}
2749 else
2750 floppy_modules_path=lib/modules/`uname -r`
2751 fi
2752###
2753### Sq-Modification end
2754###
2755 fi
2756 floppy_modules=""
2757 if [ "$disksize" -lt "2880" ] ; then
2758 list_of_groovy_mods="$FLOPPY_MODS $FORCE_MODS $IDE_MODS ide-scsi sr_mod cdrom isocd isofs `WhichOfTheseModulesAreLoaded "$SCSI_MODS"`"
2759 else
2760 list_of_groovy_mods="$CDROM_MODS $FORCE_MODS `WhichOfTheseModulesAreLoaded "$SCSI_MODS"`"
2761 fi
2762 if [ "$NFS_DEV" != "" ] ; then
2763 # For PXE boot
2764 list_of_groovy_mods="$list_of_groovy_mods $NET_MODS"
2765 fi
2766 [ -e "$floppy_modules_path" ] || LogIt "path $floppy_modules_path does not exist.\n If you're not using a modular kernel then you're NUTS."
2767 for i in $list_of_groovy_mods ; do
2768 floppy_modules="$floppy_modules `FindSpecificModuleInPath $floppy_modules_path $i`"
2769 done
2770 for i in $floppy_modules ; do
2771 [ -e "$i" ] && s=`du -sk $i | cut -f1` || s=""
2772 [ "$YOUR_KERNEL_SUCKS" ] && i=$MINDI_TMP/$i
2773 echo "Adding $i ($s KB) to the rootfs" >> $LOGFILE
2774 cp -df $i $mountpoint/ 2>/dev/null || LogIt "Unable to copy $i to $mountpoint"
2775 [ "`echo "$i" | grep -F ".gz"`" ] && gunzip -f $mountpoint/`basename $i`
2776 done
2777 if [ ! -e "/sbin/devfsd" ] || [ "$disksize" -lt "2880" ] || [ "$kernelpath" = "$MINDI_LIB/vmlinuz" ] ; then
2778 echo "Deleting devfsd daemon from ramdisk" >> $LOGFILE
2779 [ ! -e "/sbin/devfsd" ] && echo "...because /sbin/devfsd not found" >> $LOGFILE
2780 [ "$disksize" -lt "2880" ] && echo "...because disksize = $disksize" >> $LOGFILE
2781 [ "$kernelpath" = "$MINDI_LIB/vmlinuz" ] && echo "...because kernel is failsafe" >> $LOGFILE
2782 rm -f $mountpoint/sbin/devfsd
2783 fi
2784 cd $old_pwd
2785 [ "$PROMPT_MAKE_TAPE_IMAGE" = "yes" ] && echo -en "$TAPEDEV" > $mountpoint/tmp/TAPEDEV-LIVES-HERE
2786 dd if=/dev/zero of=$mountpoint/zero &> /dev/null
2787 rm -f $mountpoint/zero
2788 mkdir -p $mountpoint/tmp
2789 if [ _"$MONDO_SHARE" != _"" ]; then
2790 cp -f $MONDO_CACHE/mondo-restore.cfg $mountpoint/tmp &> /dev/null || Die "Cannot copy mondo-restore.cfg to ramdisk"
2791 cp -f $MINDI_TMP/mountlist.txt $mountpoint/tmp/ 2>/dev/null || Die "Cannot copy mountlist to ramdisk"
2792 fi
2793 mkdir -p $mountpoint/proc
2794 echo "$disksize" > $mountpoint/tmp/$disksize.siz
2795 find $mountpoint -name CVS -exec rm -rf '{}' \;
2796 # Determine what filesystem to use for initrd image
2797 echo "Call GetInitrdFilesystemToUse() with parameter ${kernelpath} to get filesystem to use for initrd." >> $LOGFILE
2798 gvFileSystem=`GetInitrdFilesystemToUse ${kernelpath}`
2799 [ -z gvFileSystem ] && Die "GetFilesystemToUse() failed. Terminating."
2800 case "$gvFileSystem" in
2801 "ext2fs")
2802 # say what will be used
2803 echo "Creating an ext2 initrd image..." >> $LOGFILE
2804 # kernel expects linuxrc in ext2 filesystem
2805 ( cd $mountpoint && ln -sf sbin/init linuxrc )
2806 # unmount loop filesystem and create image file using the standard approach
2807 umount $mountpoint || Die "Cannot unmount $tempfile"
2808 dd if=$tempfile bs=1k 2> /dev/null > ${rdz_fname}.tmp 2> /dev/null
2809 bs=`tune2fs -l ${rdz_fname}.tmp | grep -E '^Block size:' | cut -d: -f2`
2810 ADDITIONAL_BOOT_PARAMS="$ADDITIONAL_BOOT_PARAMS ramdisk_blocksize=$bs"
2811 gzip -v9 ${rdz_fname}.tmp > $rdz_fname 2> /dev/null
2812 rm -f ${rdz_fname}.tmp
2813 # log that we are done
2814 echo "...done." >> $LOGFILE
2815 ;;
2816 "initramfs")
2817 # say what will be used
2818 echo "Creating a gzip'ed cpio (AKA initramfs) initrd image..." >> $LOGFILE
2819 # make sure that cpio is there
2820 which cpio &> /dev/null; [ $? -eq 0 ] || Die "cpio not found. Please install package cpio and try again."
2821 # go into filesystem
2822 cd $mountpoint
2823 # kernel expects init in cpio filesystem
2824 ln -sf sbin/init init
2825 # create cpio image file and unmount loop filesystem
2826 find . -print | cpio -o -H newc | gzip -9 > $old_pwd/$rdz_fname 2> /dev/null
2827 cd $old_pwd
2828 umount $mountpoint || Die "Cannot unmount $tempfile"
2829 # log that we are done
2830 echo "...done." >> $LOGFILE
2831 ;;
2832 *)
2833 Die "Filesystem $gvFileSystem not supported for initrd image. Terminating."
2834 ;;
2835 esac
2836 if [ "$res" -eq "0" ] ; then
2837 echo -en "..."
2838 else
2839 echo -en "\rMade an rdz WITH ERRORS. \n"
2840 fi
2841 return 0
2842}
2843
2844
2845WhichOfTheseModulesAreLoaded() {
2846 local modname loaded_modules
2847 loaded_modules="$MODULES"
2848 for modname in $1 ; do
2849 [ "`echo "$loaded_modules" | grep -w "$modname"`" ] && echo "$modname"
2850 done
2851}
2852
2853
2854ZipMinidirsIntoTarballs() {
2855 local minidir_root tardir noof_disks diskno old_pwd i
2856 minidir_root=$1
2857 tardir=$2
2858 noof_disks=$3
2859
2860 echo -en "Tarring and zipping the group`PluralOrNot $noof_disks`..."
2861 mkdir -p $tardir
2862 mkdir -p $minidir_root/all
2863 old_pwd=`pwd`
2864 diskno=1
2865 while [ "$diskno" -le "$noof_disks" ] ; do
2866 cd $minidir_root/$diskno || LogIt "WARNING - cannot cd to $minidir_root/$diskno"
2867 tar -cf - . 2>> $LOGFILE | gzip -9 > $tardir/$diskno.tar.gz || Die "Can't tar/gzip disk#$diskno; please tell Dev Team -exactly- what the errors where."
2868 diskno=$(($diskno+1))
2869 echo -n "..."
2870 cp -pRdf * $minidir_root/all 2>> $LOGFILE
2871 done
2872 mkdir -p $minidir_root/all/tmp
2873 cd $minidir_root/all
2874 size_of_all_tools=`du -sk . | cut -f1`
2875 if [ _"$MONDO_SHARE" != _"" ]; then
2876 for q in filelist.full.gz biggielist.txt ; do
2877 [ ! -e "$MINDI_TMP/$q" ] && Die "Cannot find $MINDI_TMP/$q"
2878 cp -pRdf $MINDI_TMP/$q tmp/ 2>> $LOGFILE
2879 done
2880 mkdir -p $minidir_root/all/tmp
2881 fi
2882 tar -b 4096 -cf - * 2> /dev/null | gzip -9 > $tardir/all.tar.gz
2883 dd if=/dev/zero bs=1k count=64 >> $imagesdir/all.tar.gz 2> /dev/null
2884 [ "`du -sm $imagesdir/all.tar.gz | cut -f1`" -ge "30" ] && Die "You have too many tools in your shed"
2885 cd $old_pwd
2886 [ "$minidir_root" != "" ] && rm -Rf $minidir_root
2887 echo -e "$DONE"
2888}
2889
2890
2891##############################################################################
2892#----------------------------------- Main -----------------------------------#
2893##############################################################################
2894
2895# Now we can create what we nedd
2896mkdir -p $MINDI_TMP
2897
2898# Purge from potential old run
2899if [ _"$MINDI_CACHE" = _"" ]; then
2900 Die "MINDI_CACHE undefined"
2901fi
2902rm -rf $MINDI_CACHE/* 2> /dev/null
2903mkdir -p $MINDI_CACHE
2904
2905
2906if [ "$1" = "--printvar" ] ; then
2907 shift
2908 if [ _"$1" != _"" ] ; then
2909 set | egrep "^$1" | cut -d= -f2
2910 fi
2911 MindiExit 0
2912fi
2913
2914> $LOGFILE
2915echo "mindi v$MINDI_VERSION" >> $LOGFILE
2916echo "$ARCH architecture detected" >> $LOGFILE
2917echo "mindi called with the following arguments:" >> $LOGFILE
2918echo "$@" >> $LOGFILE
2919echo "Start date : `date`" >> $LOGFILE
2920echo "-----------------------------" >> $LOGFILE
2921
2922if [ -e "/etc/conf.modules" ] && [ ! -e "/etc/modules.conf" ] ; then
2923 LogIt "WARNING - Ancient distro detected." 1
2924 ln -sf /etc/conf.modules /etc/modules.conf
2925fi
2926[ -e "/sbin/mkdosfs" ] && [ ! -e "/sbin/mkfs.vfat" ] && ln -sf /sbin/mkdosfs /sbin/mkfs.vfat
2927
2928# Log some capital variables
2929[ "$MINDI_PREFIX" = "XXX" ] && Die "Mindi has not been installed correctly."
2930echo "MONDO_SHARE = $MONDO_SHARE" >> $LOGFILE
2931echo "MINDI_LIB = $MINDI_LIB" >> $LOGFILE
2932echo "MINDI_SBIN = $MINDI_SBIN" >> $LOGFILE
2933[ "$MINDI_CONF" = "YYY" ] && Die "Mindi has not been installed correctly."
2934echo "MINDI_CONF = $MINDI_CONF" >> $LOGFILE
2935if [ -f $MINDI_CONF ]; then
2936 echo "-----------------------------" >> $LOGFILE
2937 echo " Mindi configuration file " >> $LOGFILE
2938 echo "-----------------------------" >> $LOGFILE
2939 cat $MINDI_CONF >> $LOGFILE
2940 echo "-----------------------------" >> $LOGFILE
2941fi
2942
2943
2944trap AbortHere SIGTERM SIGHUP SIGQUIT SIGKILL SIGABRT SIGINT
2945
2946# Sanity checks
2947which which > /dev/null 2> /dev/null || Die "Please install 'which'."
2948which strings > /dev/null 2> /dev/null || Die "Please install binutils and libbinutils; you have no 'strings' executable."
2949which gawk > /dev/null 2> /dev/null || Die "Gawk is missing from your computer. Please install gawk. You may find the package on Debian's website. How did I know you're running Debian? Because only Debian would be stupid enough not to include gawk in your distribution."
2950which gawk > /dev/null 2> /dev/null && AWK=`which gawk 2>/dev/null` || AWK="`which awk 2>/dev/null`"
2951if which awk &> /dev/null ; then
2952 if ! which gawk &> /dev/null ; then
2953 LogIt "You have awk but not gawk.\nPlease note that mindi works fine with a _sane_ awk binary.\nIf your awk binary misbehaves then please contact your vendor\nor distribution's mailing list for technical support.\n"
2954 fi
2955fi
2956which mke2fs > /dev/null 2> /dev/null || Die "Please put mke2fs in system path"
2957[ ! -e "$FDISK" ] && Die "Cannot find (s)fdisk"
2958
2959[ "`uname -r | grep "2.4.[0-6]" | grep -v "2.4.[0-9][0-9]"`" != "" ] && echo "WARNING! Your kernel may have buggy loopfs code. Consider upgrading to 2.4.7"
2960# If we have a 2.6 kernel, the system uses module-init-tools which means that we
2961# may have the modprobe configuration spread out across multiple files in
2962# directory /etc/modprobe.d. If this is the case we concatenate these files into
2963# a temporary file for further processing. Otherwise we continue in the standard
2964# way. Note further that in case /etc/modprobe.d exists, we use it and ignore
2965# /etc/modprobe.conf which is exactly what module-init-tools does. The temporary
2966# modprobe.conf file is created in MakeModuleLoadingScript. AL041128.
2967if [ -d "/etc/modprobe.d" ] && [ "`uname -r | cut -c1-3`" = "2.6" ] ; then
2968 TMPMODPROBE_FLAG="Y"
2969else
2970 TMPMODPROBE_FLAG="N"
2971 [ -e "/etc/modprobe.conf" ] && [ ! -e "/etc/modules.conf" ] && ln -sf /etc/modprobe.conf /etc/modules.conf
2972 [ ! -e "/etc/modules.conf" ] && Die "/etc/modules.conf not found; you may have to create a softlink from /etc/conf.modules to /etc/modules.conf; of course, all good distros use modules.conf anyway..."
2973fi
2974
2975# Update the PATH variable if incomplete
2976if [ -e "/sbin/mkfs" ] && ! which mkfs &> /dev/null ; then
2977 PATH=$PATH:/sbin:/usr/sbin
2978 export PATH
2979 echo "Your PATH did not include /sbin or /usr/sbin. I have fixed that, temporarily." >> $LOGFILE
2980 echo "However, you may wish to ask your vendor to provide a permanent fix..." >> $LOGFILE
2981 echo " Or you might like to call 'su -' instead of 'su', for example." >> $LOGFILE
2982fi
2983
2984# If we have a distribution-specific script for finding a FAILSAFE kernel, use it.
2985if [ -f "$MINDI_LIB/FindDistroFailsafe" ] && [ ! "$1" = "--makemountlist" ] && [ "$kernelpath" = "FAILSAFE" ]; then
2986 source $MINDI_LIB/FindDistroFailsafe
2987 # Log kernel image
2988 LogIt "FAILSAFE kernel image to be used is: $FAILSAFE_KBIN ($FAILSAFE_KVER)"
2989else
2990 [ -f "$MINDI_LIB/vmlinuz" ] && FAILSAFE_KVER=`strings $MINDI_LIB/vmlinuz 2> /dev/null | grep -E "2\.[46]" | cut -d' ' -f1`
2991fi
2992
2993if ! which mkfs.vfat &> /dev/null ; then
2994 Die "mkfs.vfat missing from your filesystem - please install your dosfstools RPM or DEB package. Perhaps your PATH environmental variable is broken, too?"
2995fi
2996
2997### BERLIOS
2998### Fix as it's not mandatory on ia64
2999if [ "$ARCH" = "ia64" ] ; then
3000 if which elilo &> /dev/null ; then
3001 LILO_EXE=elilo
3002 else
3003 LILO_EXE=`which false`
3004 fi
3005else
3006 FindIsolinuxBinary
3007 FindLiloBinary
3008fi
3009trap "Aborted" SIGTERM
3010DONE="\r\t\t\t\t\t\t\t\tDone. "
3011CHOPSIZE=240
3012BIGNO=0
3013MAX_COMPRESSED_SIZE="$mindi_max_compressed_size"
3014
3015#
3016# Kernel management: Attempt to locate kernel specific module path
3017# if module path is found then use it other wise use uname -r to set it...
3018#
3019#
3020kernelpath="$mindi_kernel"
3021if [ "$kernelpath" = "NATIVE" ]; then
3022 kernelpath=""
3023fi
3024if [ "$kernelpath" = "" ]; then
3025 kernelpath=`TryToFindKernelPath`
3026fi
3027kernelname=`echo $kernelpath | cut -d'-' -f2-`
3028echo "kernelname = $kernelname" >> $LOGFILE
3029echo "kernelpath = $kernelpath" >> $LOGFILE
3030if [ ! -d "/lib/modules/$kernelname" ] && [ "$kernelpath" != "FAILSAFE" ]
3031then
3032 echo "Module path for ${kernelpath} not found..." >> $LOGFILE
3033 echo "using running kernel\'s modules." >> $LOGFILE
3034 kernelname=`uname -r`
3035else
3036 echo "Using modules for kernel: ${kernelname}" >> $LOGFILE
3037fi
3038
3039if [ -d "/proc/lvm" ]; then
3040 # LVM v1
3041 LVMCMD=""
3042 LVM="v1"
3043elif [ -d "/dev/mapper" ]; then
3044 # LVM v2
3045 LVMCMD="lvm"
3046 LVM="v2"
3047else
3048 LVM="false"
3049fi
3050echo "LVM set to $LVM" >> $LOGFILE
3051echo "----------" >> $LOGFILE
3052echo "df result:" >> $LOGFILE
3053echo "----------" >> $LOGFILE
3054df -T >> $LOGFILE
3055echo "-------------" >> $LOGFILE
3056echo "mount result:" >> $LOGFILE
3057echo "-------------" >> $LOGFILE
3058mount >> $LOGFILE
3059echo "-------------" >> $LOGFILE
3060if [ -e /etc/raidtab ]; then
3061 echo "-------------" >> $LOGFILE
3062 echo "/etc/raidtab content:" >> $LOGFILE
3063 echo "-------------" >> $LOGFILE
3064 cat /etc/raidtab >> $LOGFILE
3065fi
3066echo "-------------" >> $LOGFILE
3067echo "cat /proc/cmdline:" >> $LOGFILE
3068echo "-------------" >> $LOGFILE
3069cat /proc/cmdline >> $LOGFILE
3070echo "-------------" >> $LOGFILE
3071echo "lsmod result:" >> $LOGFILE
3072echo "-------------" >> $LOGFILE
3073lsmod >> $LOGFILE
3074MODULES="`cat /proc/modules | awk '{print $1}'`"
3075if [ -x /usr/sbin/esxcfg-module ]; then
3076 echo "VMWare ESX server detected - Enabling dedicated support" >> $LOGFILE
3077 echo "-------------" >> $LOGFILE
3078 echo "VMWare modules" >> $LOGFILE
3079 echo "-------------" >> $LOGFILE
3080 /usr/sbin/esxcfg-module -l >> $LOGFILE
3081 MODULES="$MODULES `esxcfg-module -l | awk '{print $1}'`"
3082fi
3083echo "-------------" >> $LOGFILE
3084echo "Liste of extra modules is:" >> $LOGFILE
3085echo "$EXTRA_MODS" >> $LOGFILE
3086echo "-------------" >> $LOGFILE
3087
3088
3089FLOPPY_WAS_MOUNTED=""
3090for mtpt in /media/floppy /mnt/floppy /floppy ; do
3091 if mount | grep -w $mtpt &> /dev/null ; then
3092 FLOPPY_WAS_MOUNTED="$FLOPPY_WAS_MOUNTED $mtpt"
3093 umount $mtpt
3094 fi
3095done
3096
3097#
3098# If we have a USB device we need to store info
3099# and remove it from the parameters line
3100#
3101if [ "$#" -ne "0" ] ; then
3102 if [ "$1" = "--usb" ] ; then
3103 shift
3104 USBDEVICE=$1
3105 if [ _"$USBDEVICE" = _"" ]; then
3106 Die "No USB device specified"
3107 fi
3108 shift
3109 fi
3110fi
3111
3112#
3113# Default value for parameters coming from mondo potentially
3114#
3115if [ "$ARCH" = "ia64" ] ; then
3116 USE_LILO=yes
3117else
3118 USE_LILO=no
3119fi
3120
3121#
3122# These variables are normaly only significant in a mondo environment
3123# Not enforced yet
3124#
3125CDRECOVERY="no"
3126NOT_BOOT="no"
3127EXCLUDE_DEVS=""
3128IMAGE_DEVS=""
3129NFS_DEV=""
3130
3131#
3132# Deal with parameters
3133#
3134if [ "$#" -ne "0" ] ; then
3135 if [ "$1" = "--findkernel" ] ; then
3136 res=`TryToFindKernelPath`
3137 # Avoids logfile content for mondo
3138 export MONDO_SHARE=""
3139 if [ "$res" = "" ] ; then
3140 MindiExit -1
3141 else
3142 echo "$res"
3143 MindiExit 0
3144 fi
3145 elif [ "$1" = "--makemountlist" ] ; then
3146 [ ! "$2" ] && Die "Please specify the output file"
3147 MakeMountlist $2
3148 # Avoids logfile content for mondo
3149 export MONDO_SHARE=""
3150 MindiExit $?
3151 elif [ "$1" = "-V" ] || [ "$1" = "-v" ] || [ "$1" = "--version" ] || [ "$1" = "-version" ] ; then
3152 echo "Mindi v$MINDI_VERSION"
3153 # Avoids logfile content for mondo
3154 export MONDO_SHARE=""
3155 MindiExit 0
3156 elif [ "$1" = "--custom" ] ; then
3157 if [ _"$MONDO_SHARE" = _"" ]; then
3158 Die "--custom is reserved for mondoarchive calls"
3159 fi
3160 MONDO_TMP=$2
3161 # Change MINDI_TMP for the one provided by mondo
3162 # So that it can get back the built files
3163 mv $MINDI_TMP/* $MINDI_TMP/.??* $MONDO_TMP 2> /dev/null
3164 rmdir $MINDI_TMP
3165 export MINDI_TMP=$MONDO_TMP
3166 mkdir -p $MINDI_TMP
3167 # This is the scratch dir in mondo
3168 MINDI_CACHE=$3
3169 if [ _"$MINDI_CACHE" != _"" ]; then
3170 mkdir -p $MINDI_CACHE
3171 fi
3172
3173 if [ ! -e "$MONDORESTORECFG" ]; then
3174 Die "MONDORESTORECFG undefined. Use an uptodate mondoarchive version"
3175 fi
3176
3177 if [ ! -e "$MONDO_CACHE" ]; then
3178 Die "MONDO_CACHE undefined. Use an uptodate mondoarchive version"
3179 else
3180 #
3181 # Get from mondo our additional configuration
3182 #
3183 echo "Using $MONDO_CACHE/mindi.conf as additional config file"
3184 if [ -f $MONDO_CACHE/mindi.conf ]; then
3185 . $MONDO_CACHE/mindi.conf
3186 echo "-----------------------------" >> $LOGFILE
3187 echo " Mondo configuration file " >> $LOGFILE
3188 echo "-----------------------------" >> $LOGFILE
3189 cat $MONDO_CACHE/mindi.conf >> $LOGFILE
3190 echo "-----------------------------" >> $LOGFILE
3191 else
3192 Die "No mindi.conf file created by mondo. Aborting"
3193 fi
3194 fi
3195
3196 echo "Here is your $MONDORESTORECFG file:" >> $LOGFILE
3197 echo "------------------------------------" >> $LOGFILE
3198 cat $MONDORESTORECFG >> $LOGFILE
3199 echo "-----------------------------------" >> $LOGFILE
3200
3201 CDRECOVERY=`grep use-cdrecovery $MONDORESTORECFG | cut -d'=' -f2`
3202 NOT_BOOT=`grep non-bootable $MONDORESTORECFG | cut -d'=' -f2`
3203 USE_LILO=`grep use-lilo $MONDORESTORECFG | cut -d'=' -f2`
3204 EXCLUDE_DEVS=`grep excluded-devs $MONDORESTORECFG | cut -d'=' -f2`
3205 NFS_DEV=`grep nfs-dev $MONDORESTORECFG | cut -d'=' -f2`
3206 VALUE=`grep image-devs $MONDORESTORECFG | cut -d'=' -f2`
3207 if [ "$VALUE" = "(null)" ] || [ "$VALUE" = "" ] ; then
3208 IMAGE_DEVS=""
3209 else
3210 IMAGE_DEVS="`echo "$VALUE" | tr '|' ' '`"
3211 fi
3212 [ "$CDRECOVERY" = "yes" ] && [ "$PROMPT_MAKE_TAPE_IMAGE" = "yes" ] && Die "Sorry, you can't use --cd-recovery and --write-tapes at the same time"
3213 MONDO_ROOT=`echo $MINDI_CACHE | sed 's/\(.*\)\/.*/\1/'`
3214 if [ _"$MONDO_ROOT" != _"" ]; then
3215 mkdir -p $MONDO_ROOT
3216 else
3217 Die "MONDO_ROOT is undefined"
3218 fi
3219 else
3220 echo "Syntax: mindi (--custom ....)" >> /dev/stderr
3221 MindiExit -1
3222 fi
3223fi
3224#ScanCDandTape
3225[ "$CDRECOVERY" = "yes" ] || CDRECOVERY=no
3226if [ "$CDRECOVERY" = "yes" ] ; then
3227 iso_cfg_file=$MINDI_LIB/isolinux-H.cfg
3228 sys_cfg_file=$MINDI_LIB/syslinux-H.cfg
3229else
3230 iso_cfg_file=$MINDI_LIB/isolinux.cfg
3231 sys_cfg_file=$MINDI_LIB/syslinux.cfg
3232fi
3233
3234[ -e "$iso_cfg_file" ] || Die "Cannot find $iso_cfg_file"
3235if [ _"$MONDO_SHARE" = _"" ]; then
3236 LogIt "Mindi Linux mini-distro generator v$MINDI_VERSION"
3237 LogIt "Latest Mindi is available from http://www.mondorescue.org"
3238 LogIt "BusyBox sources are available from http://www.busybox.net"
3239else
3240 echo "You are using Mindi-Linux v$MINDI_VERSION to make boot+data disks" >> $LOGFILE
3241fi
3242if [ -f $MINDI_LIB/rootfs/bin/busybox ]; then
3243 LogIt "Mindi-`$MINDI_LIB/rootfs/bin/busybox 2>&1 | head -1`"
3244else
3245 LogIt "Unable to find mindi-busybox, please install it"
3246 MindiExit -1
3247fi
3248
3249# for Mandrake 9.2, which comes with two aes.o.gz modules :-/
3250insmod /lib/modules/`uname -r`/*/*/misc/aes.*o.gz >> $LOGFILE 2>> $LOGFILE
3251for i in loop cdrom ide-cd isofs linear raid0 raid1 raid5 ; do
3252 insmod $i >> $LOGFILE 2>> $LOGFILE
3253done
3254
3255KERN_DISK_MADE=""
3256
3257if [ "$NOT_BOOT" = "yes" ]; then
3258 LogIt "Just creating a small all.tar.gz for Mondo. Nothing else."
3259 mkdir -p $MINDI_TMP/small-all/tmp
3260 MakeMountlist $MINDI_TMP/small-all/tmp/mountlist.txt
3261 cp -f $MINDI_TMP/{filelist.full.gz,biggielist.txt} $MONDO_CACHE/mondo-restore.cfg $MINDI_CACHE/small-all/tmp 2>/dev/null || Die "Cannot copy small all.tar.gz"
3262 cd $MINDI_TMP/small-all
3263 tar -cv tmp | gzip -9 > $MINDI_CACHE/all.tar.gz || Die "Cannot make small all.tar.gz"
3264 sync
3265 LogIt "Done. Exiting."
3266 MindiExit 0
3267fi
3268
3269if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ]; then
3270 LogIt "Including the generation of a Bootable USB device on $USBDEVICE"
3271fi
3272if [ "$kernelpath" = "" ] ; then
3273 if [ _"$MONDO_SHARE" != _"" ]; then
3274 Die "Please use -k <path> to specify kernel."
3275 fi
3276 if [ "$INTERACTIVE" = "yes" ]; then
3277 echo -en "Do you want to use your own kernel to build the boot disk ([y]/n) ?"
3278 read ch
3279 if [ "$ch" != "n" ] && [ "$ch" != "N" ] ; then
3280 USE_OWN_KERNEL="yes"
3281 fi
3282 fi
3283 if [ "$USE_OWN_KERNEL" = "yes" ]; then
3284 YOUR_KERNEL_SUCKS=""
3285 kernelpath=`TryToFindKernelPath`
3286 if [ "$kernelpath" = "" ] ; then
3287 echo -n "Please enter kernel path : "
3288 read kernelpath
3289 fi
3290 else
3291 YOUR_KERNEL_SUCKS="That's why you're using mine, dude. :-)"
3292 fi
3293fi
3294if [ _"$MONDO_SHARE" = _"" ] && [ "$INTERACTIVE" = "yes" ] && [ "$ARCH" != "ia64" ] ; then
3295 echo -en "Would you like to use LILO (instead of syslinux)\nfor your boot CD/floppies (y/[n]) ?"
3296 read ch
3297 if [ "$ch" = "y" ] || [ "$ch" = "Y" ] ; then
3298 USE_LILO=yes
3299 fi
3300fi
3301if [ "$YOUR_KERNEL_SUCKS" != "" ] || [ "$kernelpath" = "" ] || [ "$kernelpath" = "SUCKS" ] || [ "$kernelpath" = "FAILSAFE" ] ; then
3302 # If we have a distribution-specific script for finding a FAILSAFE kernel, use it.
3303 if [ -f "$MINDI_LIB/FindDistroFailsafe" ] && [ ! "$1" = "--makemountlist" ]; then
3304 source $MINDI_LIB/FindDistroFailsafe
3305 # Log kernel image
3306 LogIt "FAILSAFE kernel image to be used is: $FAILSAFE_KBIN ($FAILSAFE_KVER)"
3307 kernelpath="$FAILSAFE_KBIN"
3308 LogIt "I shall include a failsafe kernel, not your kernel, in the boot disks.\n"
3309 LogIt "The failsafe kernel is $kernelpath.\n"
3310 LogIt "However, you are still running your kernel. If Mindi fails to create your\n"
3311 LogIt "disks then it may still be a result of a problem with your kernel.\n"
3312 pwd=`pwd`
3313 cd $MINDI_TMP
3314 mkdir -p lib/modules
3315 cp -a "/lib/modules/$FAILSAFE_KVER" "lib/modules/$FAILSAFE_KVER" || Die "Cannot copy kernel modules."
3316 cd $pwd
3317 else
3318 kernelpath=$MINDI_LIB/vmlinuz
3319 LogIt "I shall include Mindi's failsafe kernel, not your kernel, in the boot disks."
3320 LogIt "However, you are still running your kernel. If Mindi fails to create your"
3321 LogIt "disks then it may still be a result of a problem with your kernel."
3322 pwd=`pwd`
3323 cd $MINDI_TMP
3324 bzip2 -dc $MINDI_LIB/lib.tar.bz2 | tar -x || Die "Cannot unzip lib.tar.bz2"
3325 cd $pwd
3326 fi
3327 YOUR_KERNEL_SUCKS="Your kernel sucks"
3328fi
3329echo -e "Mindi's temp dir = $MINDI_TMP \nMindi's output dir=$MINDI_CACHE" >> $LOGFILE
3330[ "$(($RANDOM%64))" -eq "0" ] && LogIt "Dude, I've looked inside your computer and it's really dusty..."
3331
3332[ "$YOUR_KERNEL_SUCKS" ] && [ ! "$FAILSAFE_KVER" ] && Die "Please install mindi-kernel package. You need it.\nGo to http://www.mondorescue.org and download it, then install it."
3333
3334PrepareDataDiskImages $MINDI_CACHE
3335noof_disks=$?
3336ramdisk_size=$(($size_of_all_tools+$EXTRA_SPACE))
3337rds=$(($ramdisk_size-$((ramdisk_size%4096))))
3338ramdisk_size=$rds
3339
3340echo "Ramdisk will be $ramdisk_size KB" >> $LOGFILE
3341if [ "$USE_LILO" = "yes" ] ; then
3342 if [ "$ARCH" = "ia64" ] ; then
3343 PrepareBootDiskImage_LILO $MINDI_CACHE $BOOT_SIZE $kernelpath $ramdisk_size || Die "Failed to create ia64 floppy disk image."
3344 else
3345 if ! PrepareBootDiskImage_LILO $MINDI_CACHE 2880 $kernelpath $ramdisk_size ; then
3346 LogIt "WARNING - failed to create 2.88MB floppy disk image."
3347 LogIt "Please reduce your kernel's size if you want to make a 2.88MB floppy disk."
3348 PrepareBootDiskImage_LILO $MINDI_CACHE $BOOT_SIZE $kernelpath $ramdisk_size || Die "Failed to create 2.88MB floppy disk image."
3349 fi
3350 fi
3351else
3352 if ! PrepareBootDiskImage_SYSLINUX $MINDI_CACHE 2880 $kernelpath $ramdisk_size ; then
3353 LogIt "WARNING - failed to create 2.88MB floppy disk image."
3354 LogIt "Please reduce your kernel's size if you want to make a 2.88MB floppy disk."
3355 PrepareBootDiskImage_SYSLINUX $MINDI_CACHE $BOOT_SIZE $kernelpath $ramdisk_size || Die "Failed to create 5.76MB floppy disk image."
3356 fi
3357fi
3358
3359[ -e "$MINDI_LIB/memtest.img" ] && BOOT_MEDIA_MESSAGE="$BOOT_MEDIA_MESSAGE\n\
3360...Or type 'memtest' to test your PC's RAM thoroughly.\n"
3361
3362if [ _"$MONDO_SHARE" = _"" ]; then
3363 ListImagesForUser $MINDI_CACHE
3364 if [ "$PROMPT_WRITE_BOOT_FLOPPIES" = "yes" ]; then
3365 OfferToCopyImagesToDisks $MINDI_CACHE $boot_dev $FDDEVICE
3366 fi
3367 OfferToMakeBootableISO $MINDI_CACHE
3368 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ]; then
3369 OfferToMakeBootableUSB $MINDI_CACHE
3370 fi
3371 LogIt "Finished."
3372elif [ "$PROMPT_MAKE_TAPE_IMAGE" = "yes" ] ; then
3373 rm -f $MINDI_CACHE/{*img,*gz,*iso}
3374 OfferToMakeBootableISO $MINDI_CACHE
3375 if [ -e "$MINDI_CACHE/all.tar.gz" ] ; then
3376 cp -f $MINDI_CACHE/all.tar.gz $MINDI_TMP/ 2>> $LOGFILE
3377 else
3378 Die "Cannot find all.tar.gz, to be written to tape"
3379 fi
3380elif [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ]; then
3381 OfferToMakeBootableUSB $MINDI_CACHE
3382else
3383 OfferToMakeBootableISO $MINDI_CACHE
3384fi
3385# cleanup
3386LogIt "$FRIENDLY_OUTSTRING"
3387for mtpt in $FLOPPY_WAS_MOUNTED ; do
3388 mount $mtpt
3389done
3390MindiExit 0
Note: See TracBrowser for help on using the repository browser.