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

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

Fix #33 for mindi

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