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

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

Bad declaration for MindiExit

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