source: MondoRescue/trunk/mindi/mindi@ 808

Last change on this file since 808 was 808, checked in by Bruno Cornec, 18 years ago

merge -r793:807 $SVN_M/branches/stable
src => common for the moment it's easier to manage merges

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