Changeset 746 in MondoRescue for branches/stable/mindi
- Timestamp:
- Aug 5, 2006, 12:00:51 PM (19 years ago)
- Location:
- branches/stable/mindi
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi/mindi
r745 r746 1 #!/bin/bash2 3 # $Id$4 #5 #-----------------------------------------------------------------------------6 # mindi - mini-Linux distro based on the user's filesystem & distribution7 #8 # Mindi can create a multi-floppy boot/root kit. The first floppy is the boot9 # 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)16 export ARCH=`/bin/arch`17 18 ADDITIONAL_BOOT_PARAMS="acpi=off apm=off devfs=nomount noresume selinux=0 barrier=off"19 20 RUN_AFTER_INITIAL_BOOT_PHASE="echo \"Who lives in a pineapple under the sea?\" > /tmp/spongebob.squarepants.txt"21 # after booting from floppy/CD image but before22 # accessing auxiliary data disks (or the rest of23 # the CD), the initscript will run the above command.24 25 RUN_AFTER_BOOT_PHASE_COMPLETE="ide-opt"26 # after the emergency boot process is complete but27 # before the init script runs mondorestore, it will28 # run this command.29 30 MINDI_REV=RRR31 MINDI_VER=VVV32 33 MINDI_VERSION=${MINDI_VER}-r$MINDI_REV34 MINDI_PREFIX=XXX35 MINDI_CONF=YYY36 MINDI_SBIN=${MINDI_PREFIX}/sbin37 38 39 if [ "$ARCH" = "x86_64" ] ; then40 MINDI_LIB=${MINDI_PREFIX}/lib64/mindi41 else42 MINDI_LIB=${MINDI_PREFIX}/lib/mindi43 fi44 45 EXTRA_SPACE=24576 ; # increase if you run out of ramdisk space46 IA64_BOOT_SIZE=8192 ; # size of the ia64 boot disk47 TMP_ROOT=/tmp48 WRITE_BOOT_FLOPPIES="yes" ; # do you want to be propted to write floppy images49 PROMPT_WRITE_BOOT_FLOPPIES="yes"50 # do you want to be prompted to write51 # floppy images out to floppy disks?52 # if 'no', images will not be written to floppies53 54 PROMPT_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 automatically57 58 USE_OWN_KERNEL="no"59 # If set to "no", you will be prompted for whether or not60 # you want to use your own kernel, or the supplied default.61 # If "yes" mindi will automatically use your own kernel.62 MINDI_CONFIG="$MINDI_CONF/mindi.conf"63 if [ -f $MINDI_CONFIG ]; then64 . $MINDI_CONFIG65 fi66 MY_FSTAB=/etc/fstab67 FLOPPY_MODS="ide-floppy floppy"68 TAPE_MODS="ht st osst ide-tape ide_tape"69 SCSI_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-mod72 IDE_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"73 PCMCIA_MODS="pcmcia_core ds yenta_socket"74 USB_MODS="usb-storage usb-ohci usb-uhci usbcore usb_storage hid uhci_hcd ehci_hcd uhci-hcd ehci-hcd usbkbd"75 CDROM_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"76 NET_MODS="sunrpc nfs nfs_acl lockd loop mii 3c59x e100 bcm5700 e1000 eepro100 ne2k-pci tg3 pcnet32 8139cp 8139too 8390 vmxnet"77 EXTRA_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"78 LOGFILE=/var/log/mindi.log79 FDDEVICE=/dev/fd0 ; # 1.44MB floppy #080 CACHE_LOC=/var/cache/mondo-archive81 FORCE_DUAL_FLOPPIES=no82 83 BOOT_MEDIA_MESSAGE="\84 To format and restore all files automatically, type 'nuke' <enter>.\n\85 To restore some/all files interactively, type 'interactive' <enter>.\n\86 To compare the archives with your filesystem, type 'compare' <enter>.\n\87 To boot to a command-line prompt (expert mode), type 'expert' <enter>.\n\88 You 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\95 e.g. Type 'nuke donteject textonly' if you have an unstable Newt library and \n\96 a PC whose CD-ROM drive tray would be damaged if it unexpectedly ejected.\n\97 "98 99 # ----------------------------------------------------------------------------100 101 102 103 104 105 AbortHere() {106 [ "$mountpoint" ] && umount $mountpoint 2>> $LOGFILE107 Die "Program is terminating in response to signal received from OS/user"108 }109 110 111 112 HackSyslinuxFile() {113 local incoming114 incoming=`ReadLine`115 while [ "$incoming" ] ; do116 echo -en "$incoming" | sed s/24000/$1/117 if [ "`echo "$incoming" | grep append`" ] ; then118 echo -en " $ADDITIONAL_BOOT_PARAMS"119 fi120 echo -en "\n"121 incoming=`ReadLine`122 done123 if [ -e "$MINDI_LIB/memtest.img" ] ; then124 # 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/MULTIFUNC127 fi128 }129 130 131 132 AbortIfYourDistroIsAPieceOfStercus() {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 ; then138 if ! which gawk &> /dev/null ; then139 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 fi141 fi142 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.net145 FDISK=$MINDI_SBIN/parted2fdisk146 FDISKLOG=/tmp/parted2fdisk.log147 touch $FDISKLOG148 [ ! -e "$FDISK" ] && Die "Cannot find (s)fdisk"149 }150 151 152 153 AbortIfMkfsVfatMissing() {154 #if grep -F "vfat" /etc/fstab &> /dev/null ; then155 if ! which mkfs.vfat &> /dev/null ; then156 Die "mkfs.vfat missing from your filesystem - please install your dosfstools RPM or DEB package. Perhaps your PATH environmental variable is broken, too?"157 fi158 #fi159 }160 161 162 163 164 165 Aborted() {166 trap SIGHUP SIGTERM SIGTRAP SIGINT167 [ "$imagesdir" != "" ] && rm -f $imagesdir/mindi*img $imagesdir/*gz $imagesdir/mindi.iso168 [ "$minidir_root" != "" ] && rm -Rf $minidir_root/*169 Die "User abort."170 }171 172 173 AddFileToCfgIfExists() {174 [ -e "$1" ] && echo -en "$2 `cat $1`\n" >> $3175 }176 177 178 179 AddFileToDir() {180 local filename minidir_root noof_disks diskno res filesize disksize would_occupy zipsize complevel cutoff compressed_fname siz181 filename=$1182 minidir_root=$2183 noof_disks=$3184 185 # diskno=1186 diskno=$noof_disks187 mkdir -p $minidir_root/$diskno188 [ "$LAST_COMPRESSED_SIZE" = "" ] && LAST_COMPRESSED_SIZE=0189 if [ ! -e "$filename" ] ; then190 if [ -h "$filename" ] ; then191 cp --parents -pRdf $filename $minidir_root/$diskno192 return $noof_disks193 else194 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 fi196 fi197 # move to the disk that has room on it (or end up using the last, if all full)198 while [ "$diskno" -lt "40" ] ; do199 mkdir -p $minidir_root/$diskno200 filesize=`du -sk $filename | cut -f1`201 cp --parents -Rdf $filename $minidir_root/$diskno202 if [ "$filesize" -le "4" ] ; then203 siz=$filesize204 elif [ ! -f "$filename" ] ; then205 siz=0206 else207 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 up210 fi211 [ ! "$siz" ] && siz=4212 [ "$siz" -lt "0" ] && siz=0213 LAST_COMPRESSED_SIZE=$(($LAST_COMPRESSED_SIZE+$siz))214 [ "$LAST_COMPRESSED_SIZE" -le "$MAX_COMPRESSED_SIZE" ] &&return $diskno215 echo "disk=$diskno siz=$LAST_COMPRESSED_SIZE" >> $LOGFILE216 LAST_COMPRESSED_SIZE=0217 rm -f $minidir_root/$diskno/$filename218 diskno=$(($diskno+1))219 done220 return 0 ; # failed221 }222 223 224 225 226 AddKeyboardMappingFile() {227 local mappath r included_list included_item i res ii sss228 mappath=$1229 KBDEPTH=$(($KBDEPTH+1))230 [ "$KBDEPTH" -gt "128" ] && Die "Edit $MINDI_SBIN/mindi and disable FindAndAddUserKeyboardMappingFile (line 2160, approx.)"231 if [ -e "$bigdir/$mappath" ] ; then232 echo "$mappath already added" >> $LOGFILE233 return234 elif [ -d "$bigdir/$mappath" ] ; then235 echo "Cannot add $mappath: it's a directory. Sorry."236 return237 fi238 echo "Added kbd map $mappath" >> $LOGFILE239 if [ ! -e "$mappath" ] ; then240 mappath=`find $KEYDIR/keymaps | grep "i[3-8]86" | grep "$locale[^r][^/]" | grep -vx " *#.*"`241 if [ ! -e "$mappath" ] ; then242 LogIt "Cannot add $mappath: kbd map file not found\n"243 return244 fi245 else246 echo -en "`basename $mappath | tr '.' '#' | sed s/#kmap#gz// | sed s/#inc#gz//` " | tr '#' '.'247 fi248 249 mkdir -p $bigdir/etc250 cp --parents -pRdf $mappath $bigdir || LogIt "AKMF -- Could not copy $mappath to $bigdir\n"251 if [ "`echo $mappath | grep -F ".gz"`" ] ; then252 included_list=`gzip -dc $mappath | grep -Fi include | sed s/'"'// | sed s/'"'// | cut -d' ' -f2`253 else254 included_list=`grep -Fi include $mappath | sed s/'"'// | sed s/'"'// | cut -d' ' -f2`255 fi256 for included_item in $included_list ; do257 if [ ! -e "$included_item" ] ; then258 sss=`find $KEYDIR/keymaps | grep -F "${included_item}.inc"`259 [ "$sss" = "" ] && sss=`find $KEYDIR/keymaps | grep -F "$included_item"`260 for ii in $sss ; do261 [ -e "$ii" ] && AddKeyboardMappingFile $ii262 done263 else264 AddKeyboardMappingFile $included_item265 fi266 done267 }268 269 270 271 272 273 274 275 ChopUpAndCopyFile() {276 local filename slicesize outdir res biggienumber filesize sliceno noof_slices testfile scratchfile277 filename=$1278 outdir=$2279 slicesize=$3280 biggienumber=$4281 282 [ -d "$filename" ] && Die "Cannot chop up $filename: it's a directory. Please amend deplist.txt accordingly."283 mkdir -p $outdir284 285 sliceno=0286 scratchfile=$TMP_ROOT/blah.$$.dat287 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"`" != "" ] ; then291 mv $scratchfile $scratchfile.gz292 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 fi295 filesize=`du -sk $scratchfile | cut -f1`296 noof_slices=$(($filesize/$slicesize))297 echo "$filename" > $outdir/slice-$biggienumber.name298 echo "$filesize" > $outdir/slice-$biggienumber.size299 [ -x "$scratchfile" ] && StripExecutable $scratchfile "-$filename-"300 while [ "$sliceno" -le "$noof_slices" ] ; do301 dd if=$scratchfile skip=$(($sliceno*$slicesize)) of=$outdir/slice-$biggienumber.`printf "%03d" $sliceno` bs=1k count=$slicesize 2> /dev/null302 sliceno=$(($sliceno+1))303 done304 rm -f $scratchfile305 }306 307 308 CopyBootBFile() {309 local copy_to copy_from possible_locations liloc310 copy_to=$1311 copy_from=/boot/boot.b312 liloc=`which lilo.real 2>/dev/null`313 [ $liloc ] || liloc=`which lilo 2>/dev/null`314 if [ $liloc ]; then315 if ! [ `strings $liloc | grep "boot\.b"` ]; then316 LogIt "boot.b files built into lilo; I'll create a dummy.\n"317 > $copy_to318 return 0319 fi320 fi321 if [ ! -f "$copy_from" ] ; then322 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" ] ; then325 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 fi329 fi330 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 336 CopyDependenciesToDirectory() {337 local outdir incoming fname filesize counter338 outdir=$1339 mkdir -p $outdir340 incoming=`ReadLine`341 counter=0342 while [ "$incoming" != "" ] ; do343 if [ -d "$incoming" ] ; then344 find $incoming/* -maxdepth 0 2> /dev/null | CopyDependenciesToDirectory $outdir345 elif [ -e "$incoming" ] ; then346 filesize=`du -sk $incoming | cut -f1`347 if [ "$filesize" -gt "$(($CHOPSIZE*2))" ] && [ ! -h "$incoming" ] ; then348 ChopUpAndCopyFile $incoming $outdir $CHOPSIZE $BIGNO349 BIGNO=$(($BIGNO+1))350 else351 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"`" != "" ] ; then353 gunzip -f $outdir/$incoming || LogIt "Cannot gunzip $outdir/$incoming\n"354 fi355 [ -x "$outdir" ] && StripExecutable $outdir "-$filename-"356 fi357 counter=$(($counter+1))358 if [ "$counter" -ge "5" ] ; then359 counter=0360 echo -en "."361 fi362 fi363 incoming=`ReadLine`364 done365 }366 367 368 369 CopyImageToDisk() {370 local image dev procno res comment371 image=$1372 dev=$2373 comment=$3374 [ ! -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 ; then378 fdformat -n $dev > /dev/null 2> /dev/null || Die "Cannot format $dev - is your Linux distro broken?"379 elif which superformat > /dev/null ; then380 superformat $dev > /dev/null 2> /dev/null || Die "Cannot format $dev - is your Linux distro broken?"381 else382 Die "Please install either fdformat or superformat."383 fi384 echo -en "\rWriting $comment"385 if echo $image | grep "mindi-[r|b]oot\.1440" &> /dev/null ; then386 cat $image > $dev &387 else388 dd if=$image of=$dev &> /dev/null &389 fi390 procno=$!391 ps $procno > /dev/null 2> /dev/null392 while [ "$?" -eq "0" ] ; do393 sleep 3394 echo -en "."395 ps $procno > /dev/null 2> /dev/null396 done397 echo -e "$DONE"398 LogIt "$comment has been written.\n"399 }400 401 402 403 404 405 CountItemsIn() {406 local r407 r=0408 for q in $1 ; do409 r=$(($r+1))410 done411 echo $r412 }413 414 415 416 417 418 419 CreateDataDiskImagesFromTarballs() {420 local tardir outdir diskno noof_disks kp421 tardir=$1422 outdir=$2423 noof_disks=$3424 425 mkdir -p $outdir426 diskno=1427 echo -en "Creating data disk "428 while [ "$diskno" -le "$noof_disks" ] ; do429 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_disks432 diskno=$(($diskno+1))433 done434 mv -f $tardir/all.tar.gz $outdir435 du -sk $outdir/*gz >> $LOGFILE436 echo -e "$DONE"437 }438 439 440 441 CreateOneDataDiskImage() {442 local tarball imagefile dev diskno noof_disks mountpoint443 tarball=$1444 imagefile=$2445 diskno=$3446 noof_disks=$4447 448 mountpoint=$TMP_ROOT/mountpoint.$$449 mkdir -p $mountpoint450 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" ] ; then457 umount $mountpoint458 Die "Tarball $tarball is too big for disk! (CODI)\nTell Dev Team to adjust MAX_COMPRESSED_SIZE"459 fi460 [ "$diskno" -eq "$noof_disks" ] && echo "This is the last disk ($diskno=$noof_disks)" >> $mountpoint/LAST-DISK461 umount $mountpoint || LogIt "Cannot umount (CODI)\n"462 rmdir $mountpoint || LogIt "Cannot rmdir (CODI)\n"463 }464 465 466 467 DidMondoCallMe() {468 local res469 470 res=0471 [ "`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 479 Die() {480 local my_partitions i481 echo "MINDI_VERSION is $MINDI_VERSION" >> $LOGFILE482 if [ "$1" = "" ] ; then483 LogIt "Fatal error\n"484 else485 LogIt "Fatal error. $1\n"486 fi487 sync488 cd /489 490 my_partitions=`mount | grep -F $$ | cut -f1 -d' '`491 [ "$my_partitions" != "" ] && umount $my_partitions492 [ "$TMP_ROOT" != "/tmp" ] && rm -Rf $TMP_ROOT493 cd /tmp494 mkdir -p mindi.err495 for i in /etc/fstab /etc/lilo.conf /etc/raidtab $LOGFILE /var/log/mondo-archive.log /tmp/mountlist.txt.$$ $FDISKLOG ; do496 [ -e "$i" ] && cp -f $i mindi.err/497 done498 rm -f mindi.err.*.tgz499 tar -cf - mindi.err | gzip -9 > mindi.err.$$.tgz500 rm -Rf mindi.err /tmp/mountlist.txt.$$ mindilinux $FDISKLOG501 LogIt "Please e-mail a copy of /tmp/mindi.err.$$.tgz to the mailing list.\n"502 LogIt "See http://www.mondorescue.org for more information.\n"503 LogIt "WE CANNOT HELP unless you enclose that file.\n"504 exit 1505 }506 507 508 509 510 DropOptimizedLibraries() {511 local outdir filelist list_of_optimized_libraries optimized_lib_name vanilla_lib_name reason msg resolved res512 filelist=$1513 outdir=$2514 515 list_of_optimized_libraries=`grep "lib/i[5-7]86/" $filelist`516 if [ "$list_of_optimized_libraries" = "" ] ; then517 return 0518 fi519 echo -en "Dropping i686-optimized libraries if appropriate"520 for optimized_lib_name in $list_of_optimized_libraries ; do521 echo -en "."522 reason=""523 vanilla_lib_name=`echo "$optimized_lib_name" | sed s/i[5-7]86// | tr -s '/' '/'`524 echo "$vanilla_lib_name" >> $filelist525 resolved=$vanilla_lib_name526 echo "Adding $resolved to filelist" >> $LOGFILE527 while [ -h "$resolved" ] ; do528 resolved=`ls $resolved -l|tr -s ' ' '\t'|$AWK '{printf $NF;}'`529 LocateFile $resolved >> $filelist530 echo "Adding $resolved to filelist" >> $LOGFILE531 done532 mkdir -p $outdir$optimized_lib_name > /dev/null 2> /dev/null533 rmdir $outdir$optimized_lib_name > /dev/null 2> /dev/null534 ln -sf $vanilla_lib_name $outdir$optimized_lib_name535 echo "Excluding $optimized_lib_name" >> $LOGFILE536 grep -Fvx "$optimized_lib_name $filelist" > $filelist.tmp537 echo "Replacing it with $vanilla_lib_name" >> $LOGFILE538 echo "$vanilla_lib_name" >> $filelist.tmp539 mv -f $filelist.tmp $filelist540 done541 sort $filelist | $AWK '{ print $1; }' | uniq > $filelist.tmp542 mv -f $filelist.tmp $filelist543 echo -e "$DONE"544 }545 546 547 548 549 FindAndAddUserKeyboardMappingFile() {550 local r res mapfile mappath included_item included_list keyfile mp locale551 LogIt "Analyzing your keyboard's configuration.\n"552 KEYDIR=/lib/kbd553 [ ! -e "$KEYDIR" ] && KEYDIR=/usr/share/kbd # Slackware554 [ ! -e "$KEYDIR" ] && KEYDIR=/usr/lib/kbd555 [ ! -e "$KEYDIR" ] && KEYDIR=/usr/share556 if [ ! -e "$KEYDIR" ] ; then557 LogIt "Keyboard mapping directory not found. I shall use default map at boot-time.\n"558 return 0559 fi560 if [ -e "/etc/sysconfig/keyboard" ] ; then561 echo "Red Hat-style config detected." >> $LOGFILE562 keyfile=/etc/sysconfig/keyboard563 elif [ -e "/etc/rc.d/rc.keymap" ] ; then564 echo "Slackware-style config detected." >> $LOGFILE565 keyfile=/etc/rc.d/rc.keymap566 elif [ -e "/etc/rc.config" ] ; then567 echo "Debian-style config detected." >> $LOGFILE568 keyfile=/etc/rc.config569 elif [ -e "/etc/console/boottime.kmap.gz" ] ; then570 echo "Debian-style config detected." >> $LOGFILE571 echo -en "Adding the following keyboard mapping tables: "572 mkdir -p $bigdir/tmp573 echo "/etc/console/boottime.kmap.gz" > $bigdir/tmp/KEYMAP-LIVES-HERE574 KBDEPTH=0575 mkdir -p $bigdir/etc/console576 cp /etc/console/boottime.kmap.gz $bigdir/etc/console577 echo -e "$DONE"578 return 0579 else580 echo -en "Searching for rc.config ..."581 keyfile=`find /etc -name rc.config | head -n1`582 if [ "$keyfile" = "" ] || [ ! -e "$keyfile" ] ; then583 LogIt "Unknown config detected. Default keyboard map will be used.\n"584 return585 else586 echo "Found $keyfile" >> $LOGFILE587 fi588 fi589 if [ ! -e "$KEYDIR/keymaps" ] ; then590 LogIt "Keyboard mapping directory not found. Default keyboard map will be used.\n"591 return592 fi593 echo "keyfile=$keyfile" >> $LOGFILE594 locale=`grep -F KEYTABLE "$keyfile" | tr -d '"' |cut -d'=' -f2`595 [ ! "$locale" ] && locale=`grep '.map$' "$keyfile" | sed 's/^.* //'` # Slackware596 echo "locale=$locale" >> $LOGFILE597 mp=`find $KEYDIR/keymaps | grep "i[3-8]86" | grep -F "/${locale}." | grep -vx " *#.*"`598 [ ! "$mp" ] && mp=`find $KEYDIR/keymaps | grep "i[3-8]86" | grep "$locale[^r][^/]" | grep -vx " *#.*"`599 # If we have multiple keymaps then log it !!600 echo "$mp" | grep -q " "601 if [ $? -eq 0 ]; then602 echo "WARNING: Multiple keymaps found: $mp" | tee -a $LOGFILE603 echo "The following one will be used" >> $LOGFILE604 fi605 for i in $mp ; do606 mappath=$i607 [ -e "$i" ] && [ ! -d "$i" ] && break608 done609 if [ ! -e "$mappath" ] || [ -d "$mappath" ] ; then610 mappath=$(locate */kbd/keymaps/*/$locale)611 fi612 echo "mappath = $mappath" >> $LOGFILE613 if [ ! -e "$mappath" ] || [ -d "$mappath" ] ; then614 LogIt "Keyboard mapping file not found. Default keyboard map will be used.\n"615 return616 fi617 echo -en "Adding the following keyboard mapping tables: "618 mkdir -p $bigdir/tmp619 echo "$mappath" > $bigdir/tmp/KEYMAP-LIVES-HERE620 KBDEPTH=0621 AddKeyboardMappingFile $mappath622 echo -e "$DONE"623 return 0624 }625 626 627 628 629 630 FindHomeOfMindiAndMondo() {631 [ "$MINDI_PREFIX" = "XXX" ] && Die "Mindi has not been installed correctly."632 echo "MINDI_LIB = $MINDI_LIB" >> $LOGFILE633 echo "MINDI_SBIN = $MINDI_SBIN" >> $LOGFILE634 [ "$MINDI_CONF" = "YYY" ] && Die "Mindi has not been installed correctly."635 echo "MINDI_CONF = $MINDI_CONF" >> $LOGFILE636 echo "MONDO_SHARE = $MONDO_SHARE" >> $LOGFILE637 mkdir -p $CACHE_LOC638 }639 640 641 642 643 644 FindIsolinuxBinary() {645 ISOLINUX=/usr/lib/isolinux.bin646 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/lib/syslinux/isolinux.bin647 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/share/syslinux/isolinux.bin648 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/share/lib/syslinux/isolinux.bin649 [ ! -e "$ISOLINUX" ] && ISOLINUX=`locate isolinux.bin | grep -x "/.*/isolinux.bin"`650 [ ! -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'"651 echo "Found isolinux.bin at $ISOLINUX" >> $LOGFILE652 }653 654 655 656 FindLiloBinary() {657 if which lilo &> /dev/null ; then658 if which lilo.real > /dev/null 2> /dev/null ; then659 LILO_EXE=lilo.real660 LogIt "lilo.real found; will be used instead of lilo (*grumble* *mutter*)\n"661 else662 LILO_EXE=lilo663 fi664 $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. :)"665 else666 LILO_EXE=`which false`667 fi668 }669 670 FindELiloBinary() {671 if which elilo &> /dev/null ; then672 LILO_EXE=elilo673 else674 LILO_EXE=`which false`675 fi676 }677 678 679 FixPathIfBroken() {680 if [ -e "/sbin/mkfs" ] && ! which mkfs &> /dev/null ; then681 PATH=$PATH:/sbin:/usr/sbin682 export PATH683 echo "Your PATH did not include /sbin or /usr/sbin. I have fixed that, temporarily." >> $LOGFILE684 echo "However, you may wish to ask your vendor to provide a permanent fix..." >> $LOGFILE685 echo "You might like to call 'su -' instead of 'su', for example." >> $LOGFILE686 fi687 }688 689 690 691 FindSensibleBootBFile() {692 local i out last693 out=""694 last=""695 for i in `find /boot -type f | grep -v chain | grep -v os2 | sort -u` ; do696 if [ "`strings $i 2> /dev/null | head -n1`" = "LILO" ] ; then697 out="$out $i"698 last="$i"699 fi700 done701 echo "$last"702 }703 704 705 706 FindSpecificModuleInPath() {707 local modpaths pwd line708 pwd=`pwd`709 if [ "$YOUR_KERNEL_SUCKS" ] ; then710 cd $TMP_ROOT711 else712 cd /713 fi714 if [ ! -e "$1" ] ; then715 LogIt "Warning - cannot search specific path '$1'\n"716 return 1717 fi718 modpaths=`find $1 -name $2.*o -type f`719 [ "$?" -ne "0" ] && Die "find $1 -name $2.o -type f --- failed"720 [ "$modpaths" = "" ] && modpaths=`find $1 -name $2.o.gz -type f`721 [ "$modpaths" = "" ] && modpaths=`find $1 -name $2.ko.gz -type f`722 [ "$modpaths" = "" ] && modpaths=`find $1 -name $2 -type f`723 echo "$modpaths"724 cd $pwd725 }726 727 728 729 GenerateGiantDependencyList() {730 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 lvmresolved731 732 echo -en "Analyzing dependency requirements"733 outfile=$1734 tempfile=$TMP_ROOT/$$.txt735 incoming=`ReadLine`736 737 > $tempfile738 progress=0739 res=0740 noof_lines=$2741 while [ "$incoming" != "" ] ; do742 if echo "$incoming" | grep -x " *#.*" &> /dev/null ; then743 # echo "Skipping '$incoming'"744 incoming=`ReadLine`745 continue746 fi747 if [ "$incoming" = "LVMFILES:" ] ; then748 break749 fi750 # echo "Processing '$incoming'."751 # sleep 1752 filelist=`GenerateListForFile "$incoming"`753 r=$?754 [ "$r" -ne "0" ] && LogIt "$incoming not found\n"755 res=$(($res+$r))756 # echo "'$incoming' generates filelist '$filelist'" >> $LOGFILE757 for fname in $filelist ; do758 [ "$fname" != "" ] && echo "$fname" >> $tempfile759 done760 progress=$(($progress+1))761 echo -en "\r\t\t\t\t\t\t\t\t"762 i=$(($progress*100))763 i=$(($i/$noof_lines))764 echo -en "$i"765 echo -en "%"766 modres=$(($progress%4))767 [ "$modres" -eq "0" ] && echo -en "\t/"768 [ "$modres" -eq "1" ] && echo -en "\t-"769 [ "$modres" -eq "2" ] && echo -en "\t\\"770 [ "$modres" -eq "3" ] && echo -en "\t|"771 incoming=`ReadLine`772 done773 if [ "$incoming" = "LVMFILES:" ] ; then774 incoming=`ReadLine`775 lvmversion=""776 while [ "$incoming" != "" ] ; do777 if echo "$incoming" | grep -x " *#.*" &> /dev/null ; then778 incoming=`ReadLine`779 continue780 fi781 filelist=`GenerateListForFile "$incoming"`782 for tool in $filelist ; do783 lvmresolved=`ResolveSoftlink $tool`784 if [ "$tool" == "$lvmresolved" ]; then785 echo "$tool" >> $tempfile786 elif echo "$lvmresolved" | grep "lvmiopversion" &> /dev/null ; then787 if [ "$lvmversion" = "" ] ; then788 lvmversion=`$lvmresolved`789 echo "$lvmresolved" >> $tempfile790 fi791 toolstripped=`echo $tool | $AWK -F / '{print $NF;}'`792 if [ "$lvmversion" == "200" ]; then793 # pvdata and lvmcreate_initrd don't exist in LVM2794 case "$toolstripped" in795 "pvdata")796 continue797 ;;798 "lvmcreate_initrd")799 continue800 ;;801 esac802 fi803 toolpath="/sbin/lvm-"$lvmversion"/"$toolstripped804 if [ -e "$toolpath" ] ; then805 echo "$toolpath" >> $tempfile806 echo "$tool" >> $tempfile807 else808 toolpath="/lib/lvm-"$lvmversion"/"$toolstripped809 fi810 if [ -e "$toolpath" ] ; then811 echo "$toolpath" >> $tempfile812 echo "$tool" >> $tempfile813 else814 echo "Where are your LVM-Tools? Couldn't find $tool"815 fi816 else817 echo "$tool" >> $tempfile818 fi819 done820 progress=$(($progress+1))821 echo -en "\r\t\t\t\t\t\t\t\t"822 i=$(($progress*100))823 i=$(($i/$noof_lines))824 echo -en "$i"825 echo -en "%"826 modres=$(($progress%4))827 [ "$modres" -eq "0" ] && echo -en "\t/"828 [ "$modres" -eq "1" ] && echo -en "\t-"829 [ "$modres" -eq "2" ] && echo -en "\t\\"830 [ "$modres" -eq "3" ] && echo -en "\t|"831 incoming=`ReadLine`832 done833 fi834 echo -en "$DONE\nMaking complete dependency list"835 836 tr -s '/' '/' < $tempfile | sort -u > $tempfile.new837 mv -f $tempfile.new $tempfile838 > $outfile.pre839 progress=0840 noof_lines=`cat $tempfile | wc -l`841 for fname in `cat $tempfile` ; do842 tempdepfile=`mktemp /tmp/mindilinux/tempdepfile.XXXXXX`843 LocateDeps $fname > $tempdepfile844 echo "$fname" >> $outfile.pre845 cat $tempdepfile >> $outfile.pre846 # echo "$fname ----> dependencies:-" >> $LOGFILE847 # cat $tempdepfile | tr -s '/' '/' | sort -u >> $LOGFILE848 # echo -en "(end of deplist of $fname)\n\n" >> $LOGFILE849 rm -f $tempdepfile850 progress=$(($progress+1))851 echo -en "\r\t\t\t\t\t\t\t\t"852 i=$(($progress*100))853 i=$(($i/$noof_lines))854 echo -en "$i"855 echo -en "%"856 modres=$(($progress%4))857 [ "$modres" -eq "0" ] && echo -en "\t/"858 [ "$modres" -eq "1" ] && echo -en "\t-"859 [ "$modres" -eq "2" ] && echo -en "\t\\"860 [ "$modres" -eq "3" ] && echo -en "\t|"861 done862 if [ "`DidMondoCallMe`" ] ; then863 mkdir -p $bigdir/tmp864 mkdir -p $bigdir/sbin865 mkdir -p $bigdir/bin866 if [ -e "$MONDO_TMP/post-nuke.tgz" ] ; then867 LogIt "\nIncorporating post-nuke tarball\n"868 old_pwd=`pwd`869 cd $bigdir870 tar -zxf $MONDO_TMP/post-nuke.tgz || LogIt "Error occurred when untarring post-nuke tarball\n"871 cd $old_pwd872 fi873 if cp -f $MONDO_TMP/mondo*restore $bigdir/usr/bin ; then874 LocateDeps $bigdir/usr/bin/mondo*restore >> $outfile.pre875 else876 LogIt "Cannot find mondo*restore in mondo's tempdir, $MONDO_TMP\n"877 LogIt "I bet you've got a spare copy of Mondo or Mindi floating around on your system.\n"878 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."879 Die "Odd."880 fi881 cp -f $MONDO_TMP/BOOTLOADER.* $bigdir 2> /dev/null || LogIt "\nMondo v1.2x defaults to LILO as the bootloader, BTW.\n"882 if [ -e "$MONDO_TMP/NFS-DEV" ] ; then883 LogIt "Incorporating NFS-related settings\n"884 for r in NFS-* ISO-PREFIX ; do885 cp -f $MONDO_TMP/$r $bigdir/tmp || Die "Cannot copy $r - did you run out of disk space?"886 echo "Copying $r to ramdisk" >> $LOGFILE887 done888 fi889 fi890 tr ' ' '\n' < $outfile.pre | tr -s '/' '/' | grep -Fvx "" | sort -u | grep -Ev "/libX11|/libXext|/libXi|/libgtk|/libgdk" > $outfile891 rm -f $tempfile $outfile.pre892 [ "$res" -eq "0" ] && echo -e "\r\t\t\t\t\t\t\t\t$DONE" || echo "\nFailed."893 return $res894 }895 896 897 898 899 900 GenerateListForFile() {901 local files_found loc fname incoming i res902 incoming="$1"903 files_found=""904 res=0905 906 for fname in $incoming ; do907 files_found="$files_found `LocateFile $fname`"908 done909 910 echo "$files_found" | tr ' ' '\n' | sort -u | tr '\n' ' '911 }912 913 914 915 # Returns all disk devices which are part of a raid array916 917 GetAllRaidMembers() {918 $AWK "/^[[:space:]]*#/ {next} /^[[:space:]]*device/ if(\$2) {print \$2}" < /etc/raidtab919 }920 921 922 GetFileSizeList() {923 local i924 for i in `find $1 -type d -o -print` ; do925 du -sk $i926 done927 }928 929 930 931 GetHomeDir() {932 local res loc933 loc=`which $1 2>/dev/null`934 res=`file $loc | $AWK '{print $NF;}'`935 dirname $res936 }937 938 939 940 941 942 # Searches parent raid device of given disk device943 # $1: disk device (i.e. /dev/hda1)944 945 GetParentRaidDev() {946 $AWK "/^[[:space:]]*#/ {next} /^[[:space:]]*raiddev/ {dev=\$2} /^[[:space:]]*device/ {if(\$2==\"$1\") {print dev; exit}}" < /etc/raidtab947 }948 949 950 951 # Searches members of raid device952 # $1: raid device (/dev/md...)953 954 GetRaidDevMembers() {955 $AWK "/^[[:space:]]*#/ {next} /^[[:space:]]*raiddev/ {if(dev) exit; if(\$2 == \"$1\") dev=\$2} /^[[:space:]]*device/ {if(dev) {print \$2}}" < /etc/raidtab956 }957 958 959 HackAwk() {960 local pathname filename dir old_pwd new_fname961 pathname=$1962 filename=$2963 dir=`echo "$pathname" | sed s/$filename//`964 old_pwd=`pwd`965 cd $dir966 [ -f "$filename" ] || Die "Can't find $filename at $dir"967 new_fname="an.icky.icky.spider.ewww"968 [ "$filename" = "gawk" ] && new_fname="awk"969 [ "$filename" = "awk" ] && new_fname="gawk"970 ln -s $filename $new_fname971 cd $old_pwd972 }973 974 975 976 977 HackMountlist() {978 local scratchdir outfile partlist pst partstr \979 res partition swapsize980 scratchdir=$TMP_ROOT981 outfile=$1982 983 mkdir -p $outfile984 rm -Rf $outfile985 > $outfile986 partlist=$(mount | cut -d' ' -f1,3,5 \987 | grep -Ev "((none|/tmp|/ISOs|/proc|/dev/root) )|/mnt/" \988 | tr ' ' '|')989 990 echo -n "Modifying mountlist..."991 992 if [ ! -f "/mountlist.hacked" ] ; then993 Die "Can't find modified mountlist.hacked!"994 else995 cp /mountlist.hacked "$outfile"996 LogIt "Done. (Created by auto-archive, I assume?)\n"997 fi998 }999 1000 1001 1002 1003 HackPathsToFailsafe() {1004 local incoming newpath kver stub i pwd1005 kver=`uname -r`1006 incoming=`ReadLine`1007 pwd=`pwd`1008 cd $TMP_ROOT1009 while [ "$incoming" != "" ] ; do1010 stub=`basename $incoming`1011 newpath=`FindSpecificModuleInPath lib/modules/$FAILSAFE_KVER $stub`1012 for i in $newpath ; do1013 echo "$i"1014 done1015 read incoming1016 done1017 cd $pwd1018 }1019 1020 1021 1022 ListAllPartitions() {1023 local res currline partition all_partitions ap_orig remaining i j1024 1025 grep -vx " *#.*" $MY_FSTAB | grep -vx " *none.*" | $AWK '/^\/dev\/[imhs]d||LABEL\=\// && !/fdd|cdr|zip|floppy/ {print $1}'1026 # for partition in `$FDISK -l | tr -s ' ' '\n' | grep /dev` ; do1027 # [ -e "$i" ] && all_partitions=echo "$i"1028 # done1029 [ -e "/etc/raidtab" ] && $AWK '/^ *device/ {print $2}' /etc/raidtab1030 return1031 }1032 1033 1034 1035 1036 1037 ListImagesForUser() {1038 local path fname1039 path=$11040 echo -en "In the directory '$path' you will find the images:-\n"1041 for fname in `ls $path | grep -F mindi-` ; do1042 printf "%19s " $fname1043 done1044 echo " "1045 }1046 1047 1048 1049 ListKernelModulePaths() {1050 local module_list module fname oss r kern1051 oss="/root/oss/modules"1052 module_list="`lsmod | sed -n '2,$s/ .*//p'`"1053 ###1054 ### Sq-Modification ... Use kernelname for module search path if specified1055 ###1056 # kern="`uname -r`"1057 if [ "${kernelname}" != "" -a "${kernelname}" != "FAILSAFE" ]1058 then1059 kern=${kernelname}1060 else1061 kern="`uname -r`"1062 fi1063 ###1064 ### Sq-Mod End1065 ###1066 for module in $module_list $EXTRA_MODS ; do1067 r=`find /lib/modules/$kern -type f | grep "/${module}\..*o" | tail -n1`1068 echo "module $module --> $r" >> $LOGFILE1069 [ "$r" ] && echo "$r"1070 [ -f "$oss" ] && find $oss | grep -F $module1071 done1072 find /lib/modules/$kern/modules.* -type f 2> /dev/null1073 [ -f "$oss" ] && find $oss.* 2> /dev/null1074 }1075 1076 1077 #ListKernelModules() {1078 #local output q1079 #output=""1080 #for q in `lsmod | sed -n '2,$s/ .*//p'` ; do1081 #output="$q $output"1082 #done1083 #echo "`lsmod | sed -n '2,$s/ .*//p'`"1084 #}1085 1086 1087 1088 LocateDeps() {1089 local incoming fname deps1090 incoming="$1"1091 for fname in $incoming ; do1092 if [ ! -e "$fname" ] ; then1093 echo "Warning - $fname does not exist; cannot be LDD'd." >> $LOGFILE1094 if echo $fname | grep lvm &> /dev/null ; then1095 echo "This warning only affects you if you are using LVM." >> $LOGFILE1096 if lsmod | grep lvm &> /dev/null ; then1097 echo "I think you are, so please take heed!" >> $LOGFILE1098 # LogIt "Where is liblvm? You need it."1099 else1100 echo "I don't think you are, so don't worry about it." >> $LOGFILE1101 fi1102 fi1103 elif [ -h "$fname" ] && [ -x "$fname" ] ; then1104 echo "$fname is softlink" >> $LOGFILE1105 # echo "$fname will not be LDD'd. It is a softlink to `WhatSoftlinkPointsTo $fname`, which should already be in queue to be analyzed." >> $LOGFILE1106 # echo "$fname"1107 else1108 ldd $fname 2> /dev/null | ProcessLDD $fname1109 fi1110 done1111 }1112 1113 1114 1115 LocateFile() {1116 local i path fname_to_find location output resolved tmp stub cache_id loclist1117 fname_to_find="$1"1118 if [ "$FILE_CACHE" ] ; then1119 touch $FILE_CACHE1120 output=""; cache_id=`echo $fname_to_find | md5sum`1121 output=`sed -n -e "s/^$cache_id //p" $FILE_CACHE`1122 if [ ! "$output" = "" ] ; then1123 echo "$output"1124 return 01125 fi1126 fi1127 if echo "$fname_to_find" | grep -x "/.*" ; then1128 output="$fname_to_find"1129 location="$fname_to_find"1130 while [ -h "$location" ] ; do1131 resolved=`WhatSoftlinkPointsTo $location`1132 location=$resolved1133 output="$location $output"1134 done1135 echo "$output"1136 return 01137 fi1138 output=""1139 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/* ; do1140 [ ! -d "$path" ] && continue1141 location=`echo "$path/$fname_to_find" | tr -s '/' '/'`1142 if echo "$location" | grep "lib/lib" 2> /dev/null ; then1143 loclist=`find $path -maxdepth 1 | grep -F "$fname_to_find"`1144 else1145 loclist=$location1146 fi1147 for location in $loclist ; do1148 [ ! -e "$location" ] && continue1149 output="$location $output"1150 copies_found=$(($copies_found+1))1151 while [ -h "$location" ] ; do1152 resolved=`WhatSoftlinkPointsTo $location`1153 location=$resolved1154 output="$location $output"1155 done1156 # resolved=`file $location | $AWK '{print $NF;}'`1157 # if [ "`echo "$resolved" | grep -F "/"`" = "" ] ; then1158 # stub=`dirname $location`1159 # output="/$stub/$resolved $output"1160 # fi1161 # fi1162 done1163 done1164 if [ "$output" = "" ] ; then1165 # echo "$fname_to_find not found" >> /dev/stderr1166 return 11167 fi1168 echo "$output"1169 [ "$FILE_CACHE" ] && echo -ne "$cache_id $output\n" >> $FILE_CACHE1170 return 01171 }1172 1173 1174 1175 LogIt() {1176 if [ -e /dev/stderr ] ; then1177 echo -e "$1" >> /dev/stderr1178 elif [ -e /usr/bin/logger ] ; then1179 /usr/bin/logger -s $11180 fi1181 echo -en "$1" >> $LOGFILE1182 }1183 1184 1185 1186 1187 1188 1189 1190 # Called by TurnTgzIntoRdz, to make /tmp/mondo-restore.cfg1191 1192 MakeMondoConfigFile() {1193 local outfile use_lzo use_comp use_star1194 outfile=$11195 > $outfile1196 [ "$TAPESIZE" ] && echo "media-size $TAPESIZE" >> $outfile1197 [ "$TAPEDEV" ] && echo "media-dev $TAPEDEV" >> $outfile1198 [ "$FILES_IN_FILELIST" ] && echo "files-in-filelist $FILES_IN_FILELIST" >> $outfile1199 [ "$LAST_FILELIST_NUMBER" ] && echo "last-filelist-number $LAST_FILELIST_NUMBER" >> $outfile1200 [ "$INTERNAL_TAPE_BLOCK_SIZE" ] && echo "internal-tape-block-size $INTERNAL_TAPE_BLOCK_SIZE" >> $outfile1201 use_lzo=$USE_LZO; [ "$use_lzo" = "" ] && use_lzo="no"1202 use_comp=$USE_COMP; [ "$use_comp" = "" ] && use_comp="yes"1203 use_star=$USE_STAR; [ "$use_star" = "" ] && use_star="no"1204 echo "use-lzo $use_lzo" >> $outfile1205 echo "use-star $use_star" >> $outfile1206 echo "use-comp $use_comp" >> $outfile1207 echo "datestamp `date`" >> $outfile1208 [ "$ESTIMATED_TOTAL_NOOF_SLICES" ] && echo "total-slices $ESTIMATED_TOTAL_NOOF_SLICES" >> $outfile1209 AddFileToCfgIfExists $MONDO_TMP/NFS-CLIENT-IPADDR nfs-client-ipaddr $outfile1210 AddFileToCfgIfExists $MONDO_TMP/NFS-CLIENT-NETMASK nfs-client-netmask $outfile1211 AddFileToCfgIfExists $MONDO_TMP/NFS-CLIENT-BROADCAST nfs-client-broadcast $outfile1212 AddFileToCfgIfExists $MONDO_TMP/NFS-CLIENT-DEFGW nfs-client-defgw $outfile1213 AddFileToCfgIfExists $MONDO_TMP/NFS-SERVER-MOUNT nfs-server-mount $outfile1214 AddFileToCfgIfExists $MONDO_TMP/NFS-SERVER-PATH nfs-server-path $outfile1215 AddFileToCfgIfExists $MONDO_TMP/NFS-DEV nfs-dev $outfile1216 AddFileToCfgIfExists $MONDO_TMP/NFS-SERVER-IPADDR nfs-server-ipaddr $outfile1217 AddFileToCfgIfExists $MONDO_TMP/ISO-DEV iso-dev $outfile1218 AddFileToCfgIfExists $MONDO_TMP/ISO-MNT iso-mnt $outfile1219 AddFileToCfgIfExists $MONDO_TMP/ISO-PREFIX iso-prefix $outfile1220 AddFileToCfgIfExists $MONDO_TMP/ISODIR isodir $outfile1221 AddFileToCfgIfExists $MONDO_TMP/BOOTLOADER.DEVICE bootloader.device $outfile1222 AddFileToCfgIfExists $MONDO_TMP/BOOTLOADER.NAME bootloader.name $outfile1223 AddFileToCfgIfExists $MONDO_TMP/KEYMAP-LIVES-HERE keymap-lives-here $outfile1224 AddFileToCfgIfExists $MONDO_TMP/TAPEDEV-HAS-DATA-DISKS tapedev-has-data-disks $outfile1225 AddFileToCfgIfExists $MONDO_TMP/BACKUP-MEDIA-TYPE backup-media-type $outfile1226 AddFileToCfgIfExists $MONDO_TMP/DIFFERENTIAL differential $outfile1227 }1228 1229 1230 1231 1232 MakeModuleLoadingScript() {1233 local module fname params modpath kver outerloop i modpaths kver searchpath list_to_echo j1234 tmpmodprobe_flag=$11235 outfile=$21236 > $outfile || Die "Cannot create empty $outfile"1237 echo -en "#\041/bin/sh\n\n" >> $outfile1238 echo "echo -en \"Loading your modules...\"" >> $outfile1239 if [ "$YOUR_KERNEL_SUCKS" ] ; then1240 kver=$FAILSAFE_KVER1241 cd $TMP_ROOT1242 searchpath=lib/modules/$kver1243 else1244 ###1245 ### Sq-Modification ... Use kernelname for module search path if specified1246 ###1247 #kver=`uname -r`1248 if [ "${kernelname}" != "" ]1249 then1250 kver=${kernelname}1251 else1252 kver=`uname -r`1253 fi1254 ###1255 ### Sq-Modification end1256 ###1257 searchpath=/lib/modules/$kver1258 fi1259 1260 echo -en "for outerloop in 1 2 3 4 5 ; do\necho -en \".\"\n" >> $outfile1261 list_to_echo="`lsmod | sed -n '2,$s/ .*//p'`"1262 # LTE=`echo "$list_to_echo" | tr ' ' '\n' | grep -n "" | cut -d':' -f2,3,4 | tr '\n' ' '`1263 # lte_old="$LTE"1264 # LTE=""1265 # for q in $lte_old ; do1266 # LTE="$q $LTE"1267 # done1268 #echo "LTE = '$LTE'" >> $LOGFILE1269 # Make temporary modprobe.conf file if we are told so1270 if [ $tmpmodprobe_flag == "Y" ] ; then1271 infile="/tmp/modprobe.conf.mindi.$$"1272 find /etc/modprobe.d -maxdepth 1 -name "*" -xtype f -print0 | xargs -0 cat > $infile1273 else1274 infile="/etc/modules.conf"1275 fi1276 for module in $list_to_echo $EXTRA_MODS ; do1277 params=`sed -n "s/^options \\+$module \\+//p" $infile`1278 modpaths=`FindSpecificModuleInPath $searchpath $module`1279 for i in $modpaths ; do1280 echo "MyInsmod $i $params > /dev/null 2> /dev/null" \1281 | tr '.' '#' \1282 | sed s/#o#gz/#o/ \1283 | sed s/#o#gz/#o/ \1284 | sed s/#ko#gz/#ko/ \1285 | sed s/#ko#gz/#ko/ \1286 | tr '#' '.' >> $outfile1287 echo -en "$i added to module list.\n" >> $LOGFILE1288 done1289 done1290 echo -en "done\n" >> $outfile1291 echo "echo \"Done.\"" >> $outfile1292 chmod +x $outfile1293 # cp $outfile /tmp/out.txt1294 cd /1295 # Remove temporary modprobe.conf file if we have created one1296 if [ $tmpmodprobe_flag == "Y" ] ; then1297 rm -f $infile1298 fi1299 }1300 1301 1302 1303 1304 1305 MakeMountlist() {1306 local scratchdir mountlist all_partitions current_partition \1307 partition_size partition_format outstring partition_number \1308 partition_mountpt c_p lwm_info psz lvm_dev unofficial_outstring \1309 absolute_partition old_partition_fmt current_lvolume1310 1311 echo "Your raw fstab file looks like this:-" >> $LOGFILE1312 cat $MY_FSTAB >> $LOGFILE1313 echo "Your mountlist will look like this:-"1314 1315 # scratchdir, mountlist(OUT)1316 scratchdir=$TMP_ROOT1317 mountlist=$11318 1319 # NB: partition = device1320 # NB: mountpt = where the device is mounted1321 1322 [ -e "$MY_FSTAB" ] || Die "Cannot find your fstab file ($MY_FSTAB)"1323 1324 rm -f $mountlist1325 mkdir -p $mountlist1326 rm -Rf $mountlist1327 > $mountlist1328 echo -en "\rHang on...\r"1329 all_partitions=""1330 1331 if [ $LVM != "false" ]; then1332 echo -en "\rAnalyzing LVM...\r"1333 all_partitions=`$MINDI_LIB/analyze-my-lvm | grep -F ">>>" | cut -d' ' -f2-32`1334 fi1335 all_partitions="$all_partitions `ListAllPartitions 2> /dev/null`"1336 # echo "all partitions = $all_partitions" > /dev/stderr1337 for i in $IMAGE_DEVS ; do1338 mount | grep -F "$i " > /dev/null 2> /dev/null && Die "Sorry, $i is already mounted! CANNOT DO IMAGEDEV on it if it's mounted."1339 done1340 [ "$IMAGE_DEVS" != "" ] && all_partitions="`echo "$all_partitions $IMAGE_DEVS" | tr ' ' '\n' | sort -u | tr '\n ' ' '`"1341 printf " %-15s %-15s %-15s %-15s %-15s\n" DEVICE MOUNTPOINT FORMAT "SIZE (MB)" LABEL1342 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"1343 for c_p in $all_partitions ; do1344 # echo "c_p = $c_p" > /dev/stderr1345 [ "`echo "$useless_dev" | grep -F "$c_p"`" != "" ] || [ "`echo "$c_p" | grep ":"`" != "" ] && continue1346 [ "`echo "$c_p" | grep -x "/dev/cdroms.*"`" ] && continue1347 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"`" = "" ] ; then1348 current_partition=`ResolveSoftlink $c_p`1349 [ "`echo "$current_partition" | grep -F "/dev/mapper"`" != "" ] && current_partition="$c_p"1350 [ "`echo "$useless_dev" | grep -F "$current_partition"`" ] && continue1351 else1352 current_partition="$c_p"1353 fi1354 [ "$c_p" = "none" ] && continue1355 redhat_label=""1356 absolute_partition=`ResolveSoftlink $c_p`1357 partition_mountpt=`tr -s '\t' ' ' < $MY_FSTAB | /bin/grep -w "$current_partition" | /bin/grep -vx " *#.*" | $AWK '{print $2}' | head -n1`1358 1359 # Detects noauto partitions not mounted and exclude them1360 partition_option=`tr -s '\t' ' ' < $MY_FSTAB | /bin/grep -w "$current_partition" | /bin/grep -vx " *#.*" | $AWK '{print $4}' | head -n1`1361 if [ "`echo "$partition_option" | grep -i noauto`" != "" ] && [ "`mount | grep -w "$partition_mountpt"`" = "" ] ; then1362 continue1363 fi1364 1365 # This part tries to retrieve the correct device from a LABEL line in /etc/fstab1366 # current_partition contains only first column of /etc/fstab1367 if [ "`echo "$current_partition" | /bin/grep -i "LABEL="`" != "" ]; then1368 str_to_find_fmt_with=$current_partition1369 redhat_label=`echo "$current_partition" | /bin/cut -d'=' -f2`1370 actual_dev=""1371 1372 # 1st try : blkid, the good way1373 if [ -x "/sbin/blkid" ]; then1374 actual_dev=`/sbin/blkid | /bin/grep "$current_partition" | /bin/cut -d':' -f1`1375 fi1376 1377 # 2nd try, which works on a standard partition (ext2/3), but not on swap1378 if [ "x$actual_dev" = "x" ]; then1379 actual_dev=`/bin/mount -l | /bin/grep "\[$redhat_label\]" | /bin/cut -d' ' -f1`1380 fi1381 1382 # 3rd try, with vol_id (which works with swap)1383 if [ "x$actual_dev" = "x" -a -x "/sbin/vol_id" ]; then1384 list_swaps=`cat /proc/swaps | /bin/grep "/dev/" | /bin/awk '{ print $1 }' `1385 for dev_swap in $list_swaps ; do1386 dev_exists=`/sbin/vol_id $dev_swap | /bin/grep "$redhat_label"`1387 if [ "x$dev_exists" != "x" ]; then1388 actual_dev=$dev_swap1389 break;1390 fi1391 done1392 fi1393 1394 # 4th try : pre-formated LABEL. Format is : LABEL=SWAP-mydevice. e.g. : LABEL=SWAP-hda51395 if [ "x$actual_dev" = "x" -a _"`echo $current_partition | /bin/grep -i 'LABEL=SWAP'`" != _"" ]; then1396 try_dev="`echo "$redhat_label" | /bin/cut -d '-' -f2`"1397 present_dev="`/bin/cat /proc/swaps | /bin/grep -w /dev/$try_dev`"1398 if [ "x$present_dev" != "x" ] ; then1399 actual_dev="/dev/$try_dev"1400 fi1401 fi1402 1403 # Check if one of all those tries has known success1404 if [ "x$actual_dev" != "x" ]; then1405 current_partition=$actual_dev1406 else1407 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"1408 fi1409 else1410 str_to_find_fmt_with=$current_partition1411 fi1412 1413 partition_format=`$AWK '$1 == "'"$str_to_find_fmt_with"'" {print $3}' $MY_FSTAB`1414 # Some distributions such as Debian do not put /dev/<VG>/<LV> in fstab1415 # for LVM partitions but use /dev/mapper/<VG>-<LV> instead. Fortunately,1416 # the former is then a link to the latter, so we test whether1417 # $current_partition is actually such a link or not and set1418 # $current_lvolume accordingly. Note that $current_lvolume may well be an1419 # ordinary device. It is just to make sure that we feed the right value1420 # into any of the LVM tools if possible.1421 1422 current_lvolume="$current_partition"1423 if [ $LVM = "v2" ] && [ "`$LVMCMD lvdisplay $current_partition 2> /dev/null`" ]; then1424 partition_stub="`echo "$current_partition" | sed "s|^/dev/mapper/|/dev/|" | cut -d"-" -f1`"1425 current_lvolume="`find /dev -lname "$current_partition" | grep "^$partition_stub"`"1426 fi1427 # End of LVM device style variation code (other than $current_lvolume).1428 1429 1 if [ $LVM != "false" ] && [ "`$LVMCMD lvdisplay $current_lvolume 2> /dev/null`" ]; then 1430 2 # Size computed via LVM not directly 1431 partition_size="lvm"1432 else1433 partition_size=`SizeOfPartition $current_partition`1434 [ "`echo "$current_partition" | grep "[0-9]"`" = "" ] && continue1435 [ "`echo "$current_partition" | grep -c "^/"`" -ne "1" ] && continue1436 if [ "$partition_format" = "swap" ] || [ "$partition_mountpt" = "swap" ] ; then1437 partition_size=`grep -Fv "Priority" /proc/swaps | tr -s '\t' ' ' | grep -F "$current_partition" | $AWK '{print $3}'`1438 [ "$partition_mountpt" != "swap" ] && partition_mountpt="swap"1439 [ "$partition_format" != "swap" ] && partition_format="swap"1440 if [ "$partition_size" = "" ] ; then1441 totalsize=01442 items=01443 for i in `tr -s ' ' '\t' < /proc/swaps | grep -Fv "Filename" | cut -f3` ; do1444 totalsize=$(($totalsize+$i))1445 items=$(($items+1))1446 done1447 [ "$items" -gt "0" ] && partition_size=$(($totalsize/$items)) || partition_size=01448 [ "$partition_size" -lt "125000" ] && partition_size=1250001449 echo "I'm guessing $c_p is $(($partition_size/1024))MB" >> $LOGFILE1450 fi1451 fi1452 fi1453 [ "$partition_mountpt" = "swap" ] && partition_format="swap"1454 [ "$partition_format" = "swap" ] && partition_mountpt="swap"1455 if [ "$partition_mountpt" = "" ] ; then1456 if [ "`$LVMCMD pvdisplay $current_lvolume 2> /dev/null`" != "" ] ; then1457 if [ "`grep -F device /etc/raidtab 2> /dev/null | grep -w $current_partition`" ] ; then1458 partition_mountpt="raid"1459 partition_format="raid"1460 else1461 partition_mountpt="lvm"1462 partition_format="lvm"1463 fi1464 fi1465 fi1466 psz=$partition_size1467 echo "Examining $current_partition (mount=$partition_mountpt fmt=$partition_format psz=$psz)" >> $LOGFILE1468 [ "$psz" != "lvm" ] && psz=$(($psz/1024))1469 if [ "`echo " $IMAGE_DEVS " | grep -F " $current_partition "`" != "" ] ; then1470 partition_mountpt="image"1471 old_partition_fmt=$partition_format1472 # partition_format="`$FDISK -l 2>> $LOGFILE | tr -s '\t' ' ' | grep -w "$absolute_partition" | $AWK 'x=$(NF-1}'`"1473 partition_format="`$FDISK -l 2>> $LOGFILE | tr '*' ' ' | tr '+' ' ' | tr -s ' ' '\t' | grep -w "$absolute_partition" | cut -f5`"1474 echo "------- $FDISK -l log ------------" >> $LOGFILE1475 cat $FDISKLOG >> $LOGFILE1476 echo "------- $FDISK log end ------------" >> $LOGFILE1477 partition_size=$(($partition_size+1)); # just in case1478 if [ "$partition_format" = "Linux" ] ; then1479 echo "Are you imaging a mounted swap partition? Silly..." >> $LOGFILE1480 echo "Reverting format from $old_partition_fmt to $partition_format" >> $LOGFILE1481 partition_format=$old_partition_fmt1482 fi1483 fi1484 if [ "$EXCLUDE_DEVS" ] && [ "`echo " $EXCLUDE_DEVS " | grep -F " $current_partition "`" ] || [ "`echo " $EXCLUDE_DEVS " | grep " $current_partition "`" ] ; then1485 echo "Excluding $current_partition from mountlist" >> $LOGFILE1486 continue1487 fi1488 if [ ! "$partition_mountpt" ] ; then1489 for qq in "" `find /dev/ida/c*d* ! -name '*p*'` ; do1490 partition_format=`$FDISK -l $qq 2>> $LOGFILE | grep -w "$c_p" | sed 's/12/|/' | tr -s '\t' ' ' | cut -d'|' -f2 | cut -d' ' -f2-9`1491 echo "------- $FDISK -l $qq log ------------" >> $LOGFILE1492 cat $FDISKLOG >> $LOGFILE1493 echo "------- $FDISK log end ------------" >> $LOGFILE1494 [ "$partition_format" ] && break1495 done1496 if [ "$partition_format" = "Compaq diagnostics" ] ; then1497 partition_format="compaq"1498 elif [ ! "`grep -F device /etc/raidtab 2> /dev/null | grep -w $current_partition`" ] ; then1499 LogIt "Unable to find mountpoint of $current_partition - ignoring\n"1500 continue1501 fi1502 fi1503 partition_format="`echo "$partition_format" | cut -d',' -f1`"; # in case user has ext3,ext2 or something dumb like that1504 [ "$partition_format" = "auto" ] && partition_format="`mount | grep -w $current_partition | awk '{print$5;}'`"; # in case user uses 'auto' (dumb!)1505 unofficial_outstring=`printf "\t%-15s %-15s %-15s %7s\n" $current_partition $partition_mountpt $partition_format $psz`1506 if [ "$current_partition" = "" ] ; then1507 echo "Unknown partition (outstring = $unofficial_outstring)" >> $LOGFILE1508 elif [ "$partition_mountpt" = "" ] && [ -f "/etc/raidtab" ] ; then1509 if [ "`grep -F device /etc/raidtab 2>/dev/null | grep -F $current_partition`" ] ; then1510 partition_mountpt=raid1511 partition_format=raid1512 printf "\t%-15s %-15s %-15s %7s %-15s\n" $current_partition $partition_mountpt $partition_format $psz "$redhat_label"1513 printf "%s %s %s %s %s\n" $current_partition $partition_mountpt $partition_format $partition_size "$redhat_label" >> $mountlist1514 else1515 echo "Unknown mountpoint (outstring = $unofficial_outstring)" >> $LOGFILE1516 fi1517 elif [ "$partition_format" = "" ] ; then1518 echo "Unknown format (outstring = $unofficial_outstring)" >> $LOGFILE1519 elif [ "$partition_size" = "" ] ; then1520 echo "Unknown partition size (outstring = $unofficial_outstring)" >> $LOGFILE1521 elif [ "$partition_mountpt" = "/proc" ] || [ "$partition_mountpt" = "/dev/pts" ] ; then1522 continue1523 else1524 if [ "$partition_format" = "dos" ] || [ "$partition_format" = "msdos" ] ; then1525 echo "Stupid bastard..." >> $LOGFILE1526 partition_format="vfat"1527 fi1528 printf "\t%-15s %-15s %-15s %7s %-15s\n" $current_partition $partition_mountpt $partition_format $psz "$redhat_label"1529 printf "%s %s %s %s %s\n" $current_partition $partition_mountpt $partition_format $partition_size "$redhat_label" >> $mountlist1530 fi1531 done1532 }1533 1534 1535 1536 1537 1538 1539 MakeSureNumberIsInteger() {1540 res=`echo "$1" | tr -s '\-[0-9]' ' '`1541 if [ "$res" != " " ] && [ "$res" != "" ] ; then1542 echo "result = '$res'"1543 Die "$1 should be an integer"1544 fi1545 }1546 1547 1548 1549 1550 1551 MakeSyslinuxMessageFile() {1552 mkdir -p $11553 rmdir $11554 echo -en " " > $11555 if [ "`grep -Fi "debian" /etc/issue.net 2> /dev/null`" ] ; then1556 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.tmp1557 else1558 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.tmp1559 fi1560 sed s/%r/"`uname -r`"/ $1.tmp | sed s/%t/"`hostname`"/ > $11561 rm -f $1.tmp1562 if [ "$CDRECOVERY" != "yes" ] ; then1563 if [ -e "$MONDO_TMP/NFS-DEV" ] ; then1564 echo -en "Press <enter> to continue.\n" >> $11565 elif [ ! "$MONDO_TMP" ] ; then1566 echo -en "FYI, this is _not_ a Mondo Rescue CD.\n" >> $11567 if [ -e "$MINDI_LIB/memtest.img" ] ; then1568 echo -en "Type 'memtest' <Enter> to test your PC's memory intensively.\nJust press <Enter> to go to the main test menu.\n" >> $11569 fi1570 else1571 echo -en "$BOOT_MEDIA_MESSAGE" >> $11572 fi1573 else1574 echo -en " \1575 To restore your disk to factory defaults, type 'RESTORE' <enter>.\n\1576 CAUTION: THIS WILL ERASE YOUR WHOLE DISK !!!\n" >> $11577 fi1578 }1579 1580 1581 1582 1583 MoveHyperlinkSensibly() {1584 local filename minidir_root resides_on_diskno noof_disks old_diskno d old_pwd1585 filename=$11586 minidir_root=$21587 resides_on_diskno=$31588 noof_disks=$41589 1590 [ -h "$minidir_root/$resides_on_diskno/$filename" ] || Die "$filename isn't a softlink (or doesn't exist): how can I move it sensibly?"1591 1592 old_diskno=$resides_on_diskno1593 d=11594 while [ "$d" -le "$noof_disks" ] ; do1595 if [ "$d" -ne "$old_diskno" ] ; then1596 old_pwd=`pwd`1597 cd $minidir_root/$old_diskno1598 cp --parents -Rdf $filename $minidir_root/$d/ || Die "Can't move $filename (sensibly) from $old_diskno to $d"1599 rm -f $filename1600 cd $old_pwd1601 fi1602 # when the softlink is resolvable, our work here is done1603 [ -e "$minidir_root/$d/$filename" ] && return 01604 old_diskno=$d1605 d=$(($d+1))1606 done1607 return 11608 }1609 1610 1611 1612 OfferToCopyImagesToDisks() {1613 local imagesdir i imagename dev count boot_dev data_dev1614 imagesdir=$11615 boot_dev=$21616 data_dev=$31617 echo -en "Would you like to create boot+data floppy disks now (y/n) ?"1618 read i1619 [ "$i" != "y" ] && [ "$i" != "Y" ] && return1620 mount | grep -F /dev/fd > /dev/null && Die "Please unmount your floppies first."1621 echo "WARNING! THIS WILL ERASE YOUR FLOPPY DISKS."1622 [ ! -e "$boot_dev" ] && Die "Cannot find $boot_dev - is your Linux distro broken?"1623 [ ! -e "$data_dev" ] && Die "Cannot find $data_dev - is your Linux distro broken?"1624 i=`find $imagesdir -type f | grep -F "/mindi-root.1" 2> /dev/null`1625 j=`find $imagesdir -type f | grep -F "/mindi-boot" | grep -Ev '2880|5760'`1626 # echo "i=$i"1627 # echo "j=$j"1628 if [ "$i" ] ; then1629 CopyImageToDisk $j $data_dev "boot disk"1630 CopyImageToDisk $i $data_dev "root disk"1631 else1632 CopyImageToDisk $j $boot_dev "boot/root disk"1633 fi1634 count=11635 for i in `find $imagesdir | grep -F mindi-data` ; do1636 CopyImageToDisk $i $data_dev "data disk #$count"1637 count=$(($count+1))1638 done1639 }1640 1641 1642 1643 OfferToMakeBootableISO() {1644 local i old_pwd1645 if [ "$PROMPT_MAKE_CD_IMAGE" = "yes" ] && [ ! "`DidMondoCallMe`" ] ; then1646 echo -en "Shall I make a bootable CD image? (y/n) "1647 read i1648 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 01649 fi1650 if [ ! "$MONDO_TMP" ] ; then1651 LogIt "NB: Mindi's bootable CD always uses isolinux.\n"1652 LogIt "For a bootable CD w/LILO, please use Mondo.\n"1653 fi1654 rm -Rf $TMP_ROOT/iso1655 mkdir -p $TMP_ROOT/iso/{images,archives,isolinux}1656 cp -f $1/*.img $1/*.gz $TMP_ROOT/iso/images || LogIt "OfferToMakeBootableISO: Cannot copy $i to $TMP_ROOT/iso/images\n"1657 old_pwd=`pwd`1658 cd $TMP_ROOT/iso1659 mkdir -p $MONDO_ROOT/iso/isolinux1660 echo "mindi_lib = $MINDI_LIB" >> $LOGFILE1661 cp $MINDI_LIB/mem{test,disk}* $MONDO_ROOT 2>> $LOGFILE1662 for i in memdisk memtest.bin memtest.img ; do1663 j=$MINDI_LIB/$i1664 k=$TMP_ROOT/iso/isolinux1665 if [ -e "$j" ] ; then1666 LogIt "Copying $j to $k\n"1667 cp -f $j $k || Die "Failed to copy $j to $k"1668 cp -f $j $TMP_ROOT || Die "Failed to copy $j to $k"1669 fi1670 done1671 MakeSyslinuxMessageFile $TMP_ROOT/iso/isolinux/message.txt1672 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?"1673 cp $TMP_ROOT/mindi.rdz $TMP_ROOT/iso/isolinux/initrd.img1674 cp $TMP_ROOT/mindi.rdz $imagesdir/initrd.img1675 [ -e "$iso_cfg_file" ] || Die "FIXME - unable to find $iso_cfg_file - this should never occur"1676 cd $TMP_ROOT/iso/isolinux1677 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?"1678 if [ -e "$MONDO_TMP/NFS-DEV" ] ; then1679 mv isolinux.cfg isolinux.cfg.old1680 sed s/interactive/iso/ isolinux.cfg.old > isolinux.cfg1681 fi1682 if [ "$ARCH" != "ia64" ] ; then1683 cp $ISOLINUX isolinux.bin || Die "Cannot copy isolinux.bin ($ISOLINUX) to tmp_root - did you run out of disk space?"1684 cp $ISOLINUX ../1685 fi1686 cd $TMP_ROOT/iso1687 if [ "$ARCH" != "ia64" ] ; then1688 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?"1689 fi1690 [ "$MONDO_SHARE" ] && cp -f $MONDO_SHARE/autorun .1691 if [ -d "/home/MondoCD" ] ; then1692 cp -pRdu /home/MondoCD/* .1693 fi1694 if [ "$ARCH" != "ia64" ] ; then1695 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/$$.mk1696 else1697 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/$$.mk1698 fi1699 if [ "$?" -ne "0" ] ; then1700 echo "----------- mkisofs's errors --------------" >> $LOGFILE1701 cat /tmp/$$.mk >> $LOGFILE1702 echo "mkisofs returned the following errors:-"1703 cat /tmp/$$.mk1704 LogIt "Failed to create ISO image.\n"1705 else1706 echo "Created bootable ISO image at $imagesdir/mindi.iso" >> $LOGFILE1707 fi1708 rm -f /tmp/$$.mk1709 cd $old_pwd1710 }1711 1712 1713 1714 PluralOrNot() {1715 [ "$1" -gt "1" ] && echo -en "s"1716 }1717 1718 1719 1720 1721 MakeMessageFile() {1722 local disksize1723 disksize=$11724 if [ "`grep -Fi "debian" /etc/issue.net 2> /dev/null`" ] ; then1725 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`"/1726 else1727 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`/1728 fi1729 if [ "$disksize" -gt "2880" ] ; then1730 if [ "`DidMondoCallMe`" ] ; then1731 if [ "$CDRECOVERY" != "yes" ] ; then1732 if [ -e "$MONDO_TMP/NFS-DEV" ] ; then1733 echo -en "Press <enter> to continue.\n"1734 elif [ ! "$MONDO_TMP" ] ; then1735 echo -en "FYI, this is _not_ a Mondo Rescue CD.\n"1736 else1737 echo -en "$BOOT_MEDIA_MESSAGE"1738 fi1739 fi1740 fi1741 fi1742 if [ "$CDRECOVERY" = "yes" ] ; then1743 echo -en "\1744 To restore your disk to factory defaults, type 'RESTORE' <enter>.\n\1745 CAUTION: THIS WILL ERASE YOUR WHOLE DISK !!!\n"1746 fi1747 echo -en "\n\n\n"1748 }1749 1750 1751 1752 1753 write_full_floppy_of_kernel() {1754 local mtpt image old_pwd res disksize1755 1756 res=01757 old_pwd=`pwd`1758 KERN_DISK_MADE=11759 disksize=$31760 rand1=$RANDOM1761 rand2=$RANDOM1762 image=/tmp/$rand1.$rand2.img1763 mtpt=/tmp/$rand1.$rand2.mtpt1764 dd if=/dev/zero of=$image bs=1k count=$disksize1765 mke2fs -N 26 -F $image > /dev/null1766 mkdir -p $mtpt1767 mount -o loop $image $mtpt1768 cd $mtpt1769 mkdir -p {dev,tmp,boot}1770 cp -f $1 vmlinuz1771 if [ "$?" -ne "0" ] ; then1772 LogIt "Failed to copy $1 to ramdisk\n"1773 cd $old_pwd1774 umount $mtpt1775 rmdir $mtpt1776 rm $image1777 return 11778 fi1779 1780 rdev vmlinuz 2,01781 rdev -R vmlinuz 01782 rdev -r vmlinuz 491521783 1784 tar -zxf $MINDI_LIB/dev.tgz || LogIt "Cannot untar dev.tgz\n"1785 losetup /dev/loop0 > /dev/null 2> /dev/null1786 [ "$?" -eq "0" ] || losetup /dev/loop0 -d || Die "Please free up /dev/loop0 by typing 'losetup /dev/loop0 -d'.\nReboot if necessary.\n"1787 CopyBootBFile $mtpt/boot.b1788 1789 # echo "root=/dev/loop0" > bdlilo.conf1790 MakeLiloConfFile $disksize >> bdlilo.conf1791 1792 # cat bdlilo.conf > /tmp/bdlilo.conf1793 1794 # cat /home/mondostuff/bdlc > bdlilo.conf1795 1796 chmod 644 bdlilo.conf1797 MakeMessageFile $disksize > message1798 lilo -v -C bdlilo.conf -r $mtpt1799 res=$?1800 1801 #echo "lilo -v -C bdlilo.conf -r $mtpt"1802 #echo -en "Press enter"; read line1803 1804 cd $old_pwd1805 umount $mtpt1806 mv -f $image $21807 rmdir $mtpt1808 1809 return $res1810 1811 # --- the kernel-only method NO LONGER WORKS. Not since Apr 2002.1812 # It should work, according to the Boot Disk HOWTO, but it doesn't.1813 # It works for my failsafe kernel & for RH7.2 but not RH7.3, 8.0, etc.1814 # -Hugo, Apr 19th 20041815 # dd if=$1 of=$2 bs=1k &> /dev/null || Die "Cannot dd blank file"1816 # dd if=/dev/zero bs=1k count=$3 >> $2 2> /dev/null || Die "Cannot dd blank file"1817 # mv -f $2 $2.old1818 # dd if=$2.old bs=1k count=$3 of=$2 &> /dev/null || Die "Cannot dd blank file"1819 # rm -f $2.old1820 # if [ "$3" = "1440" ] ; then1821 # rdev $2 "/dev/fd0H"$31822 # else1823 # rdev $2 "/dev/fd0u"$31824 # fi1825 # rdev -R $2 01826 # rdev -r $2 491521827 }1828 1829 1830 1831 1832 1833 1834 MakeLiloConfFile() {1835 local disksize options i ooo1836 disksize=$11837 options=""1838 if [ "$ARCH" != "ia64" ] ; then1839 echo -en "boot=/dev/loop0\ndisk=/dev/loop0\n"1840 fi1841 if [ "$disksize" -eq "2880" ] ; then1842 echo -en "bios=0x00\nsectors=36\nheads=2\ncylinders=80\n"1843 elif [ "$disksize" -eq "1722" ] ; then1844 echo -en "bios=0x00\nsectors=21\nheads=2\ncylinders=82\n"1845 elif [ "$disksize" -gt "2880" ] ; then1846 /bin/true1847 else1848 echo -en "bios=0x00\nsectors=18\nheads=2\ncylinders=80\n"1849 fi1850 if [ "$ARCH" != "ia64" ] ; then1851 echo -en "install=/boot.b\nmap=/boot.map\n"1852 fi1853 if [ "$CDRECOVERY" = "yes" ] ; then1854 echo -en "default=RESTORE\n"1855 elif [ "$disksize" -gt "2880" ] && [ "`DidMondoCallMe`" ] ; then1856 if [ -e "$MONDO_TMP/NFS-DEV" ] ; then1857 echo -en "default=iso\n"1858 else1859 echo -en "default=interactive\n"1860 fi1861 else1862 echo -en "default=expert\n"1863 fi1864 1865 echo -en "prompt\n"1866 if [ "$ARCH" != "ia64" ] ; then1867 echo -en "vga=normal\nbackup=/dev/null\nmessage=/message\n"1868 fi1869 if [ "$CDRECOVERY" != "yes" ] ; then1870 echo -en "timeout=300\n"1871 fi1872 echo -en "\n"1873 if [ "$CDRECOVERY" = "yes" ] ; then1874 options="RESTORE expert"1875 elif [ "$disksize" -gt "2880" ] ; then1876 if [ "`DidMondoCallMe`" ] ; then1877 if [ -e "$MONDO_TMP/NFS-DEV" ] ; then1878 options="iso"1879 else1880 options="interactive expert compare iso nuke isonuke"1881 # hda hdb hdc hdd"1882 fi1883 else1884 options="expert"1885 fi1886 else1887 options="expert"1888 fi1889 for i in $options ; do1890 ooo=$i1891 [ "$ooo" = "RESTORE" ] && ooo="nuke"1892 if [ "$ARCH" = "ia64" ] ; then1893 rootpart="root=/dev/ram0\n\t"1894 else1895 rootpart=""1896 fi1897 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"1898 1899 outstr=$outstr" $ooo_mode"1900 outstr=$outstr"\"\n"1901 if [ "$disksize" = "1440" ] ; then1902 echo -en "$outstr" | sed s/initrd=.*// | grep -v root=1903 else1904 echo -en "$outstr"1905 fi1906 done1907 }1908 1909 1910 1911 1912 PrepareBootDiskImage_LILO() {1913 local disksize imagesdir dev imagefile mountpoint fname i kernelpath ramdisksize cfg_file testpath options retval outstr old_pwd ooo max_kernel_size liloconf1914 imagesdir=$11915 disksize=$21916 kernelpath=$31917 ramdisksize=$41918 1919 retval=01920 [ ! -e "$kernelpath" ] && Die "PBDI - cannot find $kernelpath kernel"1921 echo -en "Making "$disksize"KB boot disk..."1922 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?"1923 if [ "$ARCH" != "ia64" ] ; then1924 [ "$disksize" != "1722" ] && [ "$disksize" != "2880" ] && [ "$disksize" != "5760" ] && Die "PDBI - disksize is $disksize - bad size"1925 fi1926 echo -en "..."1927 imagefile=$imagesdir/mindi-bootroot.$disksize.img1928 mountpoint=$TMP_ROOT/mountpoint.$$1929 mkdir -p $mountpoint1930 dd if=/dev/zero of=$imagefile bs=1k count=$disksize &> /dev/null || Die "Cannot dd blank file"1931 if [ "$ARCH" = "ia64" ] ; then1932 mkdosfs $imagefile > /tmp/mke2fs.$$ 2>> /tmp/mke2fs.$$1933 t=vfat1934 else1935 mke2fs -N 26 -m 0 -F $imagefile > /tmp/mke2fs.$$ 2>> /tmp/mke2fs.$$1936 t=ext21937 fi1938 [ "$?" -ne "0" ] && cat /tmp/mke2fs.$$1939 rm -f /tmp/mke2fs.$$1940 mount -t $t -o loop $imagefile $mountpoint || LogIt "Cannot mount (PBDI)\n\n"1941 # copy Mindi's skeleton fs & lilo/syslinux/whatever stuff into it1942 mkdir -p $mountpoint/etc1943 if [ "$ARCH" != "ia64" ] ; then1944 liloconf=$mountpoint/etc/lilo.conf1945 else1946 liloconf=$mountpoint/elilo.conf1947 fi1948 old_pwd=`pwd`1949 cd $mountpoint1950 if [ "$ARCH" != "ia64" ] ; then1951 tar -zxf $MINDI_LIB/dev.tgz || LogIt "Cannot untar dev.tgz\n"1952 fi1953 cd $old_pwd1954 losetup /dev/loop0 > /dev/null 2> /dev/null1955 [ "$?" -eq "0" ] || losetup /dev/loop0 -d || Die "Please free up /dev/loop0 by typing 'losetup /dev/loop0 -d'.\nReboot if necessary.\n"1956 CopyBootBFile $mountpoint/boot.b1957 1958 MakeLiloConfFile $disksize > $liloconf1959 1960 echo "Copying $TMP_ROOT/mindi.rdz to $mountpoint..." >> $LOGFILE1961 cp -f $TMP_ROOT/mindi.rdz $mountpoint 2>> $LOGFILE1962 if [ "$?" -ne "0" ] ; then1963 LogIt "Failed to copy $TMP_ROOT/mindi.rdz to $mountpoint\n"1964 cat $TMP_ROOT/mtpt.$$ >> $LOGFILE1965 LogIt "Please unload some of your modules and try again.\n"1966 rm -f $TMP_ROOT/mtpt.$$1967 LogIt "Cannot incorporate mindi.rdz in bootdisk (kernel / modules too big?)\n"1968 retval=$(($retval+1))1969 fi1970 MakeMessageFile $disksize > $mountpoint/message1971 1972 mkdir -p $mountpoint/tmp1973 cp -f $TMP_ROOT/mondo-restore.cfg $mountpoint/tmp &> /dev/null1974 if [ -e "$MINDI_LIB/memtest.img" ] ; then1975 echo -en "image=/memtest.bin\nlabel=memtest\nn" >> $liloconf1976 echo -en "image=/memdisk\nlabel=memtest\nappend=\"initrd=memtest.img\"\n" >> $liloconf1977 # echo "Yep, this is a multi-function CD" > $mountpoint/MULTIFUNC1978 fi1979 if [ -d "/home/MondoCD" ] ; then1980 cp -pRdu /home/MondoCD/* . || Die "Cannot do kung pow"1981 fi1982 1983 # copy the kernel across1984 rm -Rf $mountpoint/lost+found1985 dd if=/dev/zero of=$mountpoint/zero bs=1k count=16 &> /dev/null1986 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`1987 cp -f $kernelpath $mountpoint/vmlinuz > /dev/null 2> /dev/null1988 if [ "$?" -ne "0" ] || [ "$FORCE_DUAL_FLOPPIES" = "yes" ] ; then1989 echo "Files at mountpoint ($mountpoint) :-" >> $LOGFILE1990 du -sk $mountpoint/* >> $LOGFILE1991 echo "--- end of list of files ---" >> $LOGFILE1992 echo -en "Kernel size = `du -sk $kernelpath | cut -f1` K\nRamdisk free = $free_space K\n\1993 Sorry, your kernel is too big for a boot/root floppy.\nI'll try the new boot/root two-disk thingy.\n" >> $LOGFILE1994 rm -f $mountpoint/vmlinuz1995 cd $old_pwd1996 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"1997 rmdir $mountpoint || LogIt "Cannot rmdir (PBDI)\n"1998 # losetup /dev/loop0 -d1999 res=02000 write_full_floppy_of_kernel $kernelpath $imagesdir/mindi-boot.1440.img 14402001 res=$(($res+$?))2002 cp -f $TMP_ROOT/mindi.rdz $imagesdir/mindi-root.1440.img2003 res=$(($res+$?))2004 rm -f $imagefile2005 if [ "$res" -ne "0" ]; then2006 LogIt "Warning - failed to create 1.44MB boot/root floppies\n"2007 rm -f $imagesdir/mindi-*.1440.img2008 fi2009 return $res2010 fi2011 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`2012 max_kernel_size=$(($free_space+`du -sk $kernelpath | cut -f1`))2013 echo "Free space left on floppy = $free_space KB" >> $LOGFILE2014 echo "Max kernel size on $disksize KB floppy (est'd) = $max_kernel_size K" >> $LOGFILE2015 # make it bootable2016 rm -f $mountpoint/zero2017 [ -e "$MINDI_LIB/memdisk" ] && cp -f $MINDI_LIB/memdisk $mountpoint2018 if [ "$disksize" -gt "2880" ] && [ ! "$KERN_DISK_MADE" ] ; then2019 if [ "$ARCH" != "ia64" ] ; then2020 $LILO_EXE $LILO_OPTIONS -r $mountpoint >> $LOGFILE 2>> $LOGFILE2021 else2022 /bin/true2023 fi2024 elif [ ! "$KERN_DISK_MADE" ] ; then2025 # 12/28/2001 - if 1.72MB floppy then don't use LILO's optimizations at all2026 $LILO_EXE -r $mountpoint >> $LOGFILE 2>> $LOGFILE2027 else2028 echo "Not running LILO. It's not that kind of disk." >> $LOGFILE2029 fi2030 if [ $? -ne "0" ] ; then2031 if [ "`grep -F "/tmp/dev.0" $LOGFILE`" ] ; then2032 LogIt "The '/tmp/dev.0' error is NOT Mindi's fault. It is LILO's.\n"2033 LogIt "Please reboot your PC as a workaround.\n"2034 Die "LILO sneezed and Mindi caught a cold. Please read the README / FAQ.\n"2035 fi2036 echo "$LILO_EXE -r $mountpoint ...failed."2037 echo -en "Press ENTER to continue."; read line2038 LogIt "Cannot run lilo on $mountpoint\nPlease upgrade/downgrade your version of LILO. It has a bug.\n"2039 retval=$(($retval+1))2040 fi2041 cp -f $liloconf /tmp/lilo.conf2042 if [ "$ARCH" = "ia64" ] ; then2043 cp `dirname $kernelpath`/*.efi $mountpoint2044 fi2045 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"2046 echo -en "..."2047 rmdir $mountpoint || LogIt "Cannot rmdir (PBDI)\n"2048 if [ "$retval" -eq "0" ] ; then2049 echo -en "...$DONE\r"2050 if [ "$KERN_DISK_MADE" ] ; then2051 LogIt "... $disksize KB boot disks were created OK\r"2052 fi2053 else2054 echo -en "...failed\r"2055 LogIt $disksize"KB boot disk was NOT created\r"2056 rm -f $imagefile2057 fi2058 [ "$retval" -ne "0" ] && LogIt "PrepareBootDiskImage() is returning nonzero\n"2059 return $retval2060 }2061 2062 2063 2064 2065 PrepareBootDiskImage_SYSLINUX() {2066 local disksize imagesdir dev imagefile mountpoint fname i kernelpath ramdisksize cfg_file testpath options retval outstr old_pwd ooo max_kernel_size bootimage2067 imagesdir=$12068 disksize=$22069 kernelpath=$32070 ramdisksize=$42071 do_boot_root_thingy=""2072 local retval old_pwd2073 retval=02074 [ ! -e "$kernelpath" ] && Die "PBDI - cannot find $kernelpath kernel"2075 echo -en "Making "$disksize"KB boot disk..."2076 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?"2077 [ "$disksize" != "1722" ] && [ "$disksize" != "2880" ] && [ "$disksize" != "5760" ] && Die "PDBI - disksize is $disksize - bad size"2078 echo -en "..."2079 imagefile=$imagesdir/mindi-bootroot.$disksize.img2080 mountpoint=$TMP_ROOT/mountpoint.$$2081 mkdir -p $mountpoint2082 # If I format a 1722KB data file & run syslinux on it, the resultant image2083 # won't boot. So, I have formatted a floppy, called syslinux on/to it, and2084 # used 'dd' to copy it to sys-disk.raw (zipped to sys-disk.raw.gz).2085 # If I extract it, mount it, copy my files to it, etc. then the resultant2086 # image _is_ bootable. I don't know why syslinux and/or mkfs.vfat won't2087 # play nicely and I don't care. :) I have worked around the problem. -Hugo, 06/27/20022088 if [ "$disksize" = "1722" ] ; then2089 gzip -dc $MINDI_LIB/sys-disk.raw.gz > $imagefile || Die "Cannot dd blank file"2090 else2091 dd if=/dev/zero of=$imagefile bs=1k count=$disksize &> /dev/null || Die "Cannot dd blank file"2092 mkfs.vfat $imagefile2093 syslinux $imagefile2094 fi2095 mount -t vfat -o loop $imagefile $mountpoint || LogIt "Cannot mount (PBDI)\n\n"2096 # copy Mindi's skeleton fs & lilo/syslinux/whatever stuff into it2097 old_pwd=`pwd`2098 MakeSyslinuxMessageFile $mountpoint/message.txt2099 cd $mountpoint2100 [ -e "$sys_cfg_file" ] || Die "Obi Wan, word up?"2101 # tar -zxf $MINDI_LIB/dev.tgz || LogIt "Cannot untar dev.tgz\n" <--- present for LILO; is it nec. for SYSLINUX too?2102 cat $sys_cfg_file | HackSyslinuxFile $ramdisk_size $mountpoint > syslinux.cfg || Die "Cannot copy syslinux.cfg from mindi_home to tmp_root"2103 if [ -e "$MONDO_TMP/NFS-DEV" ] ; then2104 mv syslinux.cfg syslinux.cfg.orig2105 sed s/interactive/iso/ syslinux.cfg.orig > syslinux.cfg2106 fi2107 cd $old_pwd2108 echo "Copying $TMP_ROOT/mindi.rdz to $mountpoint/initrd.img..." >> $LOGFILE2109 cp -f $TMP_ROOT/mindi.rdz $mountpoint/initrd.img 2>> $LOGFILE2110 if [ "$?" -ne "0" ] ; then2111 LogIt "Failed to copy $TMP_ROOT/mindi.rdz to $mountpoint\n"2112 cat $TMP_ROOT/mtpt.$$ >> $LOGFILE2113 LogIt "Please unload some of your modules and try again.\n"2114 rm -f $TMP_ROOT/mtpt.$$2115 LogIt "Cannot incorporate mindi.rdz in bootdisk (kernel / modules too big?)\n"2116 retval=$(($retval+1))2117 fi2118 2119 mkdir -p $mountpoint/tmp2120 cp -f $TMP_ROOT/mondo-restore.cfg $mountpoint/tmp &> /dev/null2121 2122 # copy the kernel across2123 rm -Rf $mountpoint/lost+found2124 dd if=/dev/zero of=$mountpoint/zero bs=1k count=16 &> /dev/null2125 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`2126 cp -f $kernelpath $mountpoint/vmlinuz &> /dev/null2127 if [ "$?" -ne "0" ] || [ "$FORCE_DUAL_FLOPPIES" = "yes" ] ; then2128 echo "Files at mountpoint ($mountpoint) :-" >> $LOGFILE2129 du -sk $mountpoint/* >> $LOGFILE2130 echo "--- end of list of files ---" >> $LOGFILE2131 echo -en "Kernel size = `du -sk $kernelpath | cut -f1` K\nRamdisk free = $free_space K\n\2132 Sorry, your kernel is too big for a boot/root floppy.\nI'll try the new boot/root two-disk thingy.\n" >> $LOGFILE2133 rm -f $mountpoint/vmlinuz2134 cd $old_pwd2135 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"2136 rmdir $mountpoint || LogIt "Cannot rmdir (PBDI)\n"2137 # losetup /dev/loop0 -d2138 2139 res=02140 write_full_floppy_of_kernel $kernelpath $imagesdir/mindi-boot.1440.img 14402141 res=$(($res+$?))2142 cp -f $TMP_ROOT/mindi.rdz $imagesdir/mindi-root.1440.img2143 res=$(($res+$?))2144 rm -f $imagefile2145 if [ "$res" -ne "0" ]; then2146 LogIt "Warning - failed to create 1.44MB boot/root floppies\n"2147 rm -f $imagesdir/mindi-*.1440.img2148 fi2149 return $res2150 fi2151 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`2152 max_kernel_size=$(($free_space+`du -sk $kernelpath | cut -f1`))2153 echo "Free space left on floppy = $free_space KB" >> $LOGFILE2154 echo "Max kernel size on $disksize KB floppy (est'd) = $max_kernel_size K" >> $LOGFILE2155 # make it bootable2156 rm -f $mountpoint/zero2157 mkdir -p $mountpoint/etc2158 [ -e "$MINDI_LIB/memdisk" ] && cp -f $MINDI_LIB/memdisk $mountpoint2159 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"2160 echo -en "..."2161 rmdir $mountpoint || LogIt "Cannot rmdir (PBDI)\n"2162 2163 if [ "$retval" -eq "0" ] ; then2164 echo -en "...$DONE\r"2165 if [ "$KERN_DISK_MADE" ] ; then2166 rm -f $imagefile2167 LogIt "... $disksize KB boot disks were created OK\r"2168 fi2169 else2170 echo -en "...failed\r"2171 LogIt $disksize"KB boot disk was NOT created\r"2172 rm -f $imagefile2173 fi2174 [ "$retval" -ne "0" ] && LogIt "PrepareBootDiskImage() is returning nonzero\n"2175 return $retval2176 }2177 2178 2179 2180 2181 PrepareDataDiskImages() {2182 local needlist bigdir minidir_root tardir diskdir imagesdir res i j k old_pwd lines2183 2184 imagesdir=$12185 rm -f $imagesdir/mindi-*.img $imagesdir/[0-9]*.tar.gz $imagesdir/mindi.iso2186 needlist=$TMP_ROOT/what-we-need.txt2187 bigdir=$TMP_ROOT/bigdir2188 minidir_root=$TMP_ROOT/minidir2189 mkdir -p $minidir_root2190 mkdir -p $bigdir/usr/bin2191 tardir=$TMP_ROOT/tardir2192 2193 lines=`grep -vx " *#.*" $MINDI_CONF/deplist.txt | grep -vx "" | wc -l`2194 cat $MINDI_CONF/deplist.txt | GenerateGiantDependencyList $needlist $lines2195 res=$?2196 if [ "$YOUR_KERNEL_SUCKS" ]; then2197 pwd=`pwd`2198 cd $TMP_ROOT2199 for i in `ListKernelModulePaths | HackPathsToFailsafe` ; do2200 cp --parents -pRdf ./$i $bigdir || Die "PDDI can't cp $i->$bigdir"2201 if [ "`du -sk $i | cut -f1`" -lt "$(($CHOPSIZE*2))" ] ; then2202 cp --parents -pRdf $i $bigdir2203 else2204 ChopUpAndCopyFile $i $bigdir $CHOPSIZE $BIGNO2205 BIGNO=$(($BIGNO+1))2206 fi2207 done2208 for i in $EXTRA_MODS ; do2209 j=`find lib/modules/$FAILSAFE_KVER -name $i.*o 2> /dev/null`2210 [ ! "$j" ] && echo "Warning - cannot find failsafe module $i.o" >> $LOGFILE2211 for k in $j ; do2212 if [ "`du -sk $k | cut -f1`" -lt "$CHOPSIZE" ] ; then2213 cp --parents -pRdf $k $bigdir2214 else2215 ChopUpAndCopyFile $k $bigdir $CHOPSIZE $BIGNO2216 BIGNO=$(($BIGNO+1))2217 fi2218 echo "Added failsafe module $k to ramdisk" >> $LOGFILE2219 done2220 done2221 cd $pwd2222 else2223 ListKernelModulePaths >> $needlist2224 fi2225 if [ "$res" -ne "0" ] ; then2226 Die "You have $res file`PluralOrNot $res` present in dependency list\nbut absent from filesystem."2227 fi2228 FindAndAddUserKeyboardMappingFile2229 mkdir -p $bigdir/tmp2230 if [ "`DidMondoCallMe`" ] ; then2231 MakeMondoConfigFile $TMP_ROOT/mondo-restore.cfg2232 cp -f $TMP_ROOT/mondo-restore.cfg $bigdir/tmp &> /dev/null2233 cp -f $TMP_ROOT/mondo-restore.cfg $CACHE_LOC &> /dev/null2234 fi2235 [ -d "/mnt/.boot.d" ] && echo "Oh Jebus" > $bigdir/tmp/DUMBASS-GENTOO2236 DropOptimizedLibraries $needlist $bigdir2237 echo -en "Assembling dependency files"2238 CopyDependenciesToDirectory < $needlist $bigdir2239 2240 # also copy io.sys and msdos.sys, if we can find them2241 for i in `mount | cut -d' ' -f3` ; do2242 for j in io.sys msdos.sys ; do2243 [ -e "$i/$j" ] && cp -f $i/$j $bigdir2244 done2245 done2246 2247 # master boot record, too2248 i=`cat $MONDO_TMP/BOOTLOADER.DEVICE 2> /dev/null`2249 if [ "$i" ] ; then2250 LogIt "Backing up $i's MBR\n"2251 dd if=$i of=$bigdir/BOOTLOADER.MBR bs=446 count=1 >> $LOGFILE 2>> $LOGFILE2252 # < < E O F2253 sleep 12254 sync2255 # [ "$?" -ne "0" ] && echo "Failed to save $i's MBR to bigdir" >> $LOGFILE2256 j=$i2257 [ -h "$j" ] && j=`ResolveSoftlink $j`2258 LogIt "Creating /dev/boot_device ($j)\n"2259 mkdir -p $bigdir/dev2260 cp -pRdf $j $bigdir/dev/boot_device || Die "Unable to create /dev/boot_device on ramdisk"2261 fi2262 2263 # more stuff2264 # cp -f $MINDI_LIB/embleer* $bigdir2265 old_pwd=`pwd`2266 cd $bigdir2267 2268 [ -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'."2269 cp -Rdf $MINDI_LIB/aux-tools/* . 2>> $LOGFILE || LogIt "Warning - error occurred while unzipping aux-tools\n"2270 if [ -e "$MINDI_LIB/x11-tools.tgz" ] ; then2271 tar -zxf $MINDI_LIB/x11-tools.tgz 2>> $LOGFILE || LogIt "Warning - error occurred while unzipping x11-tools.tgz\n"2272 fi2273 if [ -e "$MONDO_SHARE/restore-scripts" ] ; then2274 cp -Rdf $MONDO_SHARE/restore-scripts/* . 2>> $LOGFILE2275 [ "$?" -ne "0" ] && [ "`DidMondoCallMe`" ] && Die "Cannot find/install $MONDO_SHARE/restore-scripts"2276 fi2277 [ -d "/lib/dev-state" ] && cp --parents -pRdf /lib/dev-state .2278 cd $old_pwd2279 echo -e "$DONE"2280 TOTAL_BIGDIR_SIZE=`du -sk $bigdir | cut -f1`2281 SplitDirectoryIntoMinidirs $bigdir $minidir_root2282 noof_disks=$?2283 [ "$noof_disks" -eq "0" ] && Die "Too much stuff!"2284 # if [ "$noof_disks" -ge "8" ] ; then2285 # LogIt "You are putting a ludicrously large amount of data on these disks."2286 # LogIt "I shall therefore double EXTRA_SPACE, just in case your ramdisk is too small."2287 # EXTRA_SPACE=$(($EXTRA_SPACE*2))2288 # fi2289 MakeMountlist $TMP_ROOT/mountlist.txt2290 mkdir -p $minidir_root/$noof_disks/tmp2291 cp -f $TMP_ROOT/mountlist.txt $minidir_root/$noof_disks/tmp/mountlist.txt || Die "Cannot copy mountlist.txt from $TMP_ROOT to data disk"2292 cp -f $TMP_ROOT/mountlist.txt $CACHE_LOC2293 [ "`DidMondoCallMe`" ] && cp -f $minidir_root/$noof_disks/tmp/mountlist.txt $MONDO_TMP/.2294 [ $LVM != "false" ] && $MINDI_LIB/analyze-my-lvm > $minidir_root/$noof_disks/tmp/i-want-my-lvm2295 cat $minidir_root/$noof_disks/tmp/mountlist.txt >> $LOGFILE2296 ZipMinidirsIntoTarballs $minidir_root $tardir $noof_disks2297 CreateDataDiskImagesFromTarballs $tardir $imagesdir $noof_disks2298 FRIENDLY_OUTSTRING="Boot and data disk images were created."2299 # One 1.72MB boot disk, one 2.88MB boot disk and $noof_disks data disk images2300 rmdir $tardir $bigdir2301 rm -f $needlist2302 return $noof_disks2303 }2304 2305 2306 ProcessLDD() {2307 local main_fname incoming j i fname f newf2308 main_fname=$12309 read incoming2310 while [ "$incoming" != "" ] ; do2311 incoming=`echo "$incoming" | sed '/[[:blank:]]*.*[[:blank:]]*=>[[:blank:]]*(.*/d ; s/[[:blank:]]*\(.*\)[[:blank:]]*=>[[:blank:]]*\/.*/\1/ ; s/[[:blank:]]*\(\/.*\)[[:blank:]]*(.*/\1/'`2312 for fname in `echo "$incoming"` ; do2313 fname=`LocateFile $fname`2314 for f in $fname ; do2315 [ -e "$f" ] && echo $f2316 done2317 done2318 read incoming2319 done2320 }2321 2322 2323 2324 Prompt() {2325 echo -en "$1"2326 read line2327 }2328 2329 2330 2331 ReadLine() {2332 local i incoming2333 read incoming2334 i=02335 while [ "$i" -le "32" ] && [ "$incoming" = "" ] ; do2336 i=$(($i+1))2337 read incoming2338 done2339 echo "$incoming"2340 }2341 2342 2343 2344 RejigHyperlinks() {2345 local minidir_root noof_disks fname path diskno old_pwd awk_loc gawk_loc dir i2346 minidir_root=$12347 noof_disks=$22348 2349 old_pwd=`pwd`2350 diskno=12351 while [ "$diskno" -le "$noof_disks" ] ; do2352 mkdir -p $minidir_root/$diskno2353 cd $minidir_root/$diskno2354 for fname in `find -type d -o -print` ; do2355 [ -h "$minidir_root/$diskno/$fname" ] && MoveHyperlinkSensibly $fname $minidir_root $diskno $noof_disks2356 done2357 diskno=$(($diskno+1))2358 done2359 2360 2361 cd $old_pwd2362 return2363 2364 2365 2366 # do some awk/gawk stuff2367 cd $minidir_root2368 awk_loc=`find -name awk`2369 gawk_loc=`find -name gawk`2370 if [ "$awk_loc" = "" ] && [ "$gawk_loc" != "" ] ; then2371 for i in $gawk_loc ; do HackAwk $i gawk ; done2372 elif [ "$gawk_loc" = "" ] && [ "$awk_loc" != "" ] ; then2373 for i in $awk_loc ; do HackAwk $i awk ; done2374 elif [ "$gawk_loc" != "" ] && [ "$awk_loc" != "" ] ; then2375 echo -en "Gawk/awk found. Good.\r"2376 else2377 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? :-)"2378 fi2379 cd $old_pwd2380 }2381 2382 2383 2384 EliminateRelatives() {2385 # eliminate /../../..... from path string2386 local orig i old_i newo2387 newo=$12388 while [ "`echo "$newo" | grep "\.\."`" ] ; do2389 orig="`echo "$newo" | tr -s '/' '/'`"2390 # echo "orig=$orig"2391 newo="/"2392 old_i=""2393 for i in `echo "$orig" | tr '/' ' '` ; do2394 if [ ! "$old_i" ] ; then2395 old_i=$i2396 continue2397 fi2398 if [ "$old_i" ] && [ "$i" = ".." ] ; then2399 if [ "$old_i" = ".." ] ; then2400 newo="$newo"$old_i/2401 # echo "two --- $old_i $i"2402 old_i="$i"2403 continue2404 # else2405 # echo "swallowing ($old_i $i)"2406 fi2407 elif [ "$old_i" != ".." ] ; then2408 newo="$newo"$old_i/2409 fi2410 old_i=$i2411 done2412 newo="$newo"$i2413 done2414 echo "$newo"2415 }2416 2417 2418 WhatSoftlinkPointsTo() {2419 local orig new resolved2420 orig=$12421 new=`ls -l $orig | tr -s ' ' '\t' | $AWK '{printf $NF;}'`2422 if [ "`echo "$new" | cut -d'/' -f1`" ] ; then2423 resolved=`dirname $orig`/$new2424 else2425 resolved=$new2426 fi2427 EliminateRelatives $resolved2428 }2429 2430 2431 2432 2433 2434 ReplaceIndividualLine() {2435 local orig_file new_file lino newstring lines_total lines_remaining2436 orig_file=$1.orig2437 mv -f $1 $orig_file || Die "Cannot move $1 to $orig_file"2438 new_file=$12439 lino=$22440 newstring="$3"2441 if [ "$lino" = "" ] || [ "$lino" -lt "1" ] ; then2442 echo "Can't find string" >> $LOGFILE2443 return 12444 fi2445 lines_total=`wc -l $orig_file | gawk '{print $1;}'`2446 lines_remaining=$(($lines_total-$lino))2447 head -n$(($lino-1)) $orig_file > $new_file2448 echo "$newstring" >> $new_file2449 echo "# The above line was added by Mindi, at the user's instruction" >> $new_file2450 tail -n$lines_remaining $orig_file >> $new_file2451 echo "Replace line $lino of $new_file with user-specified line, '$newstring'" >> $LOGFILE2452 # cp -f $new_file /tmp/init.new2453 [ -x "$orig_file" ] && chmod +x $new_file2454 rm -f $orig_file2455 return 02456 }2457 2458 2459 2460 2461 ResolveSoftlink() {2462 local resolved new2463 resolved=$12464 while [ -h "$resolved" ] ; do2465 resolved=`WhatSoftlinkPointsTo $resolved`2466 done2467 echo "$resolved"2468 }2469 2470 2471 2472 2473 ScanCDandTape() {2474 local i2475 2476 for i in /dev/st0 /dev/ht0 /dev/cdrom /dev/cdrom0 /dev/cdrom 1 ; do2477 dd if=$i of=/dev/null bs=64k count=1 &> /dev/null2478 done2479 }2480 2481 2482 2483 SizeOfPartition() {2484 local devpath drive res stub2485 device=$12486 if [ "`echo "$device" | grep -F "/dev/md"`" != "" ] ; then2487 res=`SizeOfRaidPartition $device`2488 [ "$res" = "" ] && Die "Cannot find $device's size - is your /etc/raidtab sane?"2489 echo "$res"2490 return 02491 fi2492 # 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/-//`2493 # patch from Bill <bill@iwizard.biz> - 2003/08/252494 res=`$FDISK -s $device`2495 echo "------- $FDISK -l $device log ------------" >> $LOGFILE2496 cat $FDISKLOG >> $LOGFILE2497 echo "------- $FDISK log end ------------" >> $LOGFILE2498 # end patch2499 [ "$res" = "" ] && res=`df -k -P -x supermount | tr -s '\t' ' ' | grep -F "$device " | cut -d' ' -f2`2500 [ "$res" = "" ] && res="-1"2501 echo $res2502 return 02503 }2504 2505 2506 SizeOfRaidPartition() {2507 local real_dev smallest_size silly tmp2508 2509 silly=9999999992510 smallest_size=$silly2511 2512 for real_dev in `GetRaidDevMembers $1` ; do2513 tmp=`SizeOfPartition $real_dev`2514 [ "$tmp" -lt "$smallest_size" ] && smallest_size=$tmp2515 done2516 2517 if [ "$smallest_size" = "$silly" ] ; then2518 echo "-1"2519 return 12520 else2521 echo "$smallest_size"2522 return 02523 fi2524 }2525 2526 2527 2528 2529 2530 2531 StripComments()2532 {2533 local tempfile2534 tempfile=$TMP_ROOT/$$.strip.txt2535 cp -f $1 $tempfile2536 $AWK '{if (substr($0,0,1)!="#" || substr($0,0,3)=="#!/") {print $0;};}' $tempfile > $12537 rm -f $tempfile2538 echo "Stripped comments from $2" >> $LOGFILE2539 }2540 2541 2542 2543 2544 2545 2546 SplitDirectoryIntoMinidirs() {2547 local bigdir minidir_root i noof_disks old_pwd res2548 bigdir=$12549 minidir_root=$22550 rm -Rf $minidir_root/*2551 2552 TryToFitDataIntoSeveralDirs $bigdir $minidir_root2553 noof_disks=$?2554 if [ "$noof_disks" -eq "0" ] ; then2555 echo "Failed to fit data into several dirs."2556 return 02557 fi2558 RejigHyperlinks $minidir_root $noof_disks2559 rm -Rf $bigdir/*2560 return $noof_disks2561 }2562 2563 2564 2565 StripExecutable()2566 {2567 local tmpfile2568 tmpfile=$TMP_ROOT/stripped.$$.dat2569 [ -d "$1" ] || [ -h "$1" ] && return2570 cp -f $1 $tmpfile2571 strip $tmpfile 2> /dev/null2572 if [ "$?" -eq "0" ] ; then2573 cp -f $tmpfile $12574 echo "Stripped binary $2" >> $LOGFILE2575 fi2576 rm -f $tmpfile2577 }2578 2579 2580 TemporarilyCompressAllFiles() {2581 local i orig_fname out_fname out_list2582 2583 i=02584 out_list=$2/compressed/compressed.txt2585 mkdir -p $2/compressed2586 > $out_list2587 for orig_fname in $1 ; do2588 out_fname=$2/compressed/$orig_fname.gz2589 mkdir -p $out_fname 2> /dev/null2590 rmdir $out_fname 2> /dev/null2591 gzip -c6 $orig_fname > $out_fname 2> /dev/null2592 i=$(((($i+1))%15))2593 [ "$i" -eq "0" ] && echo -en "."2594 du -sk $out_fname >> $out_list2595 done2596 }2597 2598 2599 2600 TryToFindKernelPath() {2601 local fname incoming res fkern_ver we_want_version possible_kernels noof_kernels kernelpath kdate duff_kernels2602 we_want_version=`uname -r`2603 possible_kernels=""2604 duff_kernels=""2605 2606 if [ "$ARCH" = "ia64" ] ; then2607 root="/boot/efi/efi"2608 else2609 root="/"2610 fi2611 for fname in `find $root -maxdepth 2 -type f | grep -F lin | grep -Ev '^/proc/|^/net/'` ; do2612 [ ! -e "$fname" ] && continue2613 [ "$fname" = "/boot/vmlinuz.shipped" ] && [ -f "/boot/vmlinuz" ] && continue; # ignore SuSE's extra kernel2614 file $fname | grep -q gzip2615 if [ "$?" -eq "0" ] ; then2616 # Used by ia642617 fkern_ver=`gzip -cd $fname | strings 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`2618 else2619 fkern_ver=`strings $fname 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`2620 fi2621 [ "$fkern_ver" = "" ] && continue2622 # echo "$fname --> $fkern_ver (but we want $we_want_version)" >> /dev/stderr2623 [ "`echo "$fkern_ver" |grep -F "$we_want_version "`" = "" ] && continue2624 [ -f "$fname" ] || continue2625 [ -h "$fname" ] && continue2626 kdate=`uname -v | $AWK '{for(i=1;i<NF;i++){if(index($i,":")){print $i;};};}' | $AWK '{print $NF;}'`2627 file $fname | grep -q gzip2628 if [ "$?" -eq "0" ] ; then2629 # Used by ia642630 if [ "`gzip -cd $fname | strings 2> /dev/null | grep -F "$kdate"`" = "" ] ; then2631 LogIt "Have you recompiled your kernel \"$fname\" w/o rebooting? Naughty but I'll allow it...\n"2632 duff_kernels="$fname $duff_kernels"2633 else2634 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue2635 possible_kernels="$fname $possible_kernels"2636 fi2637 else2638 if [ "`strings $fname 2> /dev/null | grep -F "$kdate"`" = "" ] ; then2639 LogIt "Have you recompiled your kernel \"$fname\" w/o rebooting?\n Naughty but I'll allow it...\n"2640 duff_kernels="$fname $duff_kernels"2641 else2642 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue2643 possible_kernels="$fname $possible_kernels"2644 fi2645 fi2646 done2647 if [ ! "$possible_kernels" ] && uname -a | grep Knoppix > /dev/null ; then2648 possible_kernels=`find /boot/vmlinuz-2.* | tail -n1`2649 fi2650 if [ ! "$possible_kernels" ] ; then2651 LogIt "No kernel matches exactly. Are there any duff kernels?\n"2652 possible_kernels="$duff_kernels"2653 if [ ! "$possible_kernels" ] ; then2654 LogIt "Sorry, no duff kernels either\n"2655 else2656 LogIt "I bet you're running Debian or Gentoo, aren't you?\n"2657 LogIt "Your kernel doesn't have a sane builddate. Oh well...\n"2658 fi2659 fi2660 possible_kernels=`echo "$possible_kernels" | tr -s ' ' '\n' | sort -u | tr '\n' ' '`2661 noof_kernels=`CountItemsIn "$possible_kernels"`2662 if [ "$noof_kernels" -eq "0" ] ; then2663 LogIt "Could not find your kernel.\n"2664 if [ -e "/boot/vmlinuz" ] ; then2665 LogIt "Using /boot/vmlinuz as a last resort.\n"2666 output=/boot/vmlinuz2667 else2668 output=""2669 fi2670 elif [ "$noof_kernels" -eq "1" ] ; then2671 kernelpath=`echo "$possible_kernels" | sed s/' '//`2672 echo "Your kernel is $kernelpath (v`uname -r`)" >> $LOGFILE2673 output="$kernelpath"2674 else2675 for i in $possible_kernels ; do2676 if echo $i | grep "`uname -r`" ; then2677 LogIt "OK, I used my initiative and found that "2678 LogIt "$i is probably your kernel.\n "2679 output="$i"2680 return2681 fi2682 done2683 if echo " $possible_kernels " | grep -F "/boot/vmlinuz " &> /dev/null ; then2684 output=/boot/vmlinuz2685 echo "Schlomo, this one's for you." >> $LOGFILE2686 else2687 LogIt "Two or more possible kernels found. You may specify any one of them and the \n"2688 LogIt "boot disks will still work, probably. If one does not work, try another.\n"2689 LogIt "$possible_kernels\n"2690 echo ""2691 fi2692 fi2693 echo "$output" | tr -s ' ' '\n' | sort -u | tr '\n' ' '2694 }2695 2696 2697 2698 2699 2700 TryToFitDataIntoSeveralDirs() {2701 local bigdir minidir_root noof_disks diskno list_of_files filename old_pwd progress2702 local i retval noof_disks total_files list_of_devs2703 bigdir=$12704 minidir_root=$22705 BIG_CLUNKY_SIZE_COUNTER=02706 retval=02707 noof_disks=12708 2709 echo -en "\r \rDividing data into several groups..."2710 old_pwd=`pwd`2711 cd $bigdir2712 list_of_files=`GetFileSizeList . | sort -nr | cut -f2 | grep -Fv "/dev/"`2713 progress=02714 total_files=`CountItemsIn "$list_of_files"`2715 if [ "`echo "$filename" | grep -x "/dev/.*"`" ] ; then2716 filesize=12717 fi2718 mkdir -p $minidir_root/$noof_disks2719 if [ -e "dev" ] ; then2720 echo "Copying dev/* to $minidir_root/$noof_disks" >> $LOGFILE2721 cp --parents -pRdf dev $minidir_root/$noof_disks2722 fi2723 TemporarilyCompressAllFiles "$list_of_files" $minidir_root2724 for filename in $list_of_files ; do2725 AddFileToDir $filename $minidir_root $noof_disks2726 i=$?2727 if [ "$i" -gt "$noof_disks" ] ; then2728 noof_disks=$i2729 echo -en "\r\t\t\t\t\t\t($noof_disks disks)"2730 fi2731 if [ "$i" -eq "0" ] ; then2732 LogIt "Cannot add file $filename to minidir $minidir_root\n"2733 retval=$(($retval+1))2734 fi2735 progress=$(($progress+1))2736 echo -en "\r\t\t\t\t\t\t\t\t$(($progress*100/$total_files))% complete\r"2737 done2738 cd $old_pwd2739 echo -en "\rThe files have been subdivided into $noof_disks directories. \r"2740 rm -Rf $minidir_root/compressed2741 if [ "$retval" -gt "0" ] ; then2742 return 02743 else2744 return $noof_disks2745 fi2746 }2747 2748 2749 2750 TurnTgzIntoRdz() {2751 local tgz_dir_fname rdz_fname ramdisksize tempfile mountpoint old_pwd nodes disksize kernelsize maxsize res currsize not_copied j k floppy_modules s w2752 tgz_dir_fname=$12753 rdz_fname=$22754 ramdisksize=$32755 disksize=$42756 kernelsize=$52757 maxsize=$(($disksize-$kernelsize))2758 maxsize=$(($maxsize*2)); # to allow for compression of 50%2759 tempfile=$TMP_ROOT/temp.rd2760 mountpoint=$TMP_ROOT/mnt12761 res=02762 echo -en "..."2763 dd if=/dev/zero of=$tempfile bs=1k count=$ramdisk_size &> /dev/null || Die "Not enough room for temporary ramdisk (TurnTgzIntoRdz)"2764 echo -en "..."2765 mke2fs -b 1024 -m 1 -i 2048 -F $tempfile >> $LOGFILE 2>> $LOGFILE2766 2767 [ "$?" -ne "0" ] && cat /tmp/mke2fs.$$2768 rm -f /tmp/mke2fs.$$2769 echo -en "..."2770 mkdir -p $mountpoint2771 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."2772 echo -en "..."2773 old_pwd=`pwd`2774 cd $mountpoint2775 # [ -e "$MINDI_LIB/memtest.img" ] && echo "Yep, this is a multi-function CD" > MULTIFUNC2776 cp -Rdf $tgz_dir_fname/* . 2>> $LOGFILE >> $LOGFILE2777 tar -zxf symlinks.tgz || Die "Cannot untar symlinks.tgz"2778 cd dev || Die "Can't cd to dev"2779 tar -zxf dev-entries.tgz || Die "Cannot untar dev-entries.tgz"2780 rm -f dev-entries.tgz2781 cd ..2782 2783 # add insmod.static and insmod.static.old if (a) they exist and (b) this is a 64-bit distro2784 # if [ "`uname -a | grep x86`" ] || [ "`uname -a | grep amd64`" ] ; then2785 2786 for w in insmod.static insmod.static.old ; do2787 s=`which $w 2> /dev/null`2788 if [ -e "$s" ] ; then2789 cp --parents -af $s .2790 # LogIt "Copying $s to initrd"2791 fi2792 done2793 2794 # fi2795 2796 mkdir -p tmp2797 [ -e "/dev/.devfsd" ] && echo "/dev/.devfsd found" > tmp/USE-DEVFS2798 for w in cdrom floppy groovy-stuff ; do2799 mkdir -p mnt/$w2800 done2801 if [ "$RUN_AFTER_INITIAL_BOOT_PHASE" ] ; then2802 ReplaceIndividualLine sbin/init `grep -n "#WHOLIVESINAPINEAPPLEUNDERTHESEA#" sbin/init | cut -d':' -f1` "$RUN_AFTER_INITIAL_BOOT_PHASE"2803 fi2804 if [ "$RUN_AFTER_BOOT_PHASE_COMPLETE" ] ; then2805 ReplaceIndividualLine sbin/init `grep -n "#ABSORBENTANDYELLOWANDPOROUSISHE#" sbin/init | cut -d':' -f1` "$RUN_AFTER_BOOT_PHASE_COMPLETE"2806 fi2807 2808 lsmod > tmp/original-lsmod.txt2809 2810 cp --parents -Rdf /dev/fd0*[1,2][4,7,8]* . 2> /dev/null2811 cd $old_pwd2812 echo -en "..."2813 MakeModuleLoadingScript $TMPMODPROBE_FLAG $mountpoint/sbin/insert-all-my-modules2814 echo -en "..."2815 old_pwd=`pwd`2816 if [ "$YOUR_KERNEL_SUCKS" ] ; then2817 cd $TMP_ROOT2818 floppy_modules_path=lib/modules/$FAILSAFE_KVER2819 else2820 cd /2821 ###2822 ### Sq-Modification... Use kernel name in module path if specified.2823 ###2824 #floppy_modules_path=lib/modules/`uname -r`2825 if [ "${kernelname}" != "" ]2826 then2827 floppy_modules_path=lib/modules/${kernelname}2828 else2829 floppy_modules_path=lib/modules/`uname -r`2830 fi2831 ###2832 ### Sq-Modification end2833 ###2834 fi2835 floppy_modules=""2836 if [ "$disksize" -lt "2880" ] ; then2837 list_of_groovy_mods="$FLOPPY_MODS $IDE_MODS ide-scsi sr_mod cdrom isocd isofs `WhichOfTheseModulesAreLoaded "$SCSI_MODS"`"2838 else2839 list_of_groovy_mods="$CDROM_MODS `WhichOfTheseModulesAreLoaded "$SCSI_MODS"`"2840 fi2841 if [ -e "$MONDO_TMP/NFS-DEV" ] ; then2842 # For PXE boot2843 list_of_groovy_mods="$list_of_groovy_mods $NET_MODS"2844 # Here we need the net busybox2845 mv $mountpoint/bin/busybox.net $mountpoint/bin/busybox2846 else2847 rm -f $mountpoint/bin/busybox.net2848 fi2849 [ -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"2850 for i in $list_of_groovy_mods ; do2851 floppy_modules="$floppy_modules `FindSpecificModuleInPath $floppy_modules_path $i`"2852 done2853 for i in $floppy_modules ; do2854 [ -e "$i" ] && s=`du -sk $i | cut -f1` || s=""2855 [ "$YOUR_KERNEL_SUCKS" ] && i=$TMP_ROOT/$i2856 echo "Adding $i ($s KB) to the rootfs" >> $LOGFILE2857 cp -df $i $mountpoint/ || LogIt "Unable to copy $i to $mountpoint\n"2858 [ "`echo "$i" | grep -F ".gz"`" ] && gunzip -f $mountpoint/`basename $i`2859 done2860 # if [ -e "/dev/.devfsd" ] ; then2861 # echo "Copying devfs stuff to ramdisk" >> $LOGFILE2862 # for i in /dev /etc/devfsd.conf /etc/modules.devfs /lib/dev-state ; do2863 # cp --parents -pRdf $i $mountpoint/ 2>> $LOGFILE2864 # done2865 # fi2866 if [ ! -e "/sbin/devfsd" ] || [ "$disksize" -lt "2880" ] || [ "$kernelpath" = "$MINDI_LIB/vmlinuz" ] ; then2867 echo "Deleting devfsd daemon from ramdisk" >> $LOGFILE2868 [ ! -e "/sbin/devfsd" ] && echo "...because /sbin/devfsd not found" >> $LOGFILE2869 [ "$disksize" -lt "2880" ] && echo "...because disksize = $disksize" >> $LOGFILE2870 [ "$kernelpath" = "$MINDI_LIB/vmlinuz" ] && echo "...because kernel is failsafe" >> $LOGFILE2871 # ls -l $mountpoint/sbin/devfsd &> /dev/null || Die "Can't find devfsd daemon on ramdisk"2872 rm -f $mountpoint/sbin/devfsd2873 fi2874 cd $old_pwd2875 [ "$TAPEDEV" ] && echo -en "$TAPEDEV" > $mountpoint/tmp/TAPEDEV-LIVES-HERE2876 dd if=/dev/zero of=$mountpoint/zero &> /dev/null2877 rm -f $mountpoint/zero2878 if [ "`DidMondoCallMe`" ] ; then2879 MakeMondoConfigFile $mountpoint/tmp/mondo-restore.cfg2880 cp -f $mountpoint/tmp/mondo-restore.cfg $MONDO_TMP &> /dev/null2881 cp -f $TMP_ROOT/mountlist.txt $mountpoint/tmp/ || Die "Cannot copy mountlist to ramdisk"2882 echo -en "$FILES_IN_FILELIST" > $mountpoint/tmp/FILES-IN-FILELIST2883 echo -en "$LAST_FILELIST_NUMBER" > $mountpoint/tmp/LAST-FILELIST-NUMBER2884 [ "$USE_LZO" = "yes" ] && echo -en "Pras 4 Pres 2004" >> $mountpoint/tmp/USING-LZO2885 [ "$USE_COMP" = "yes" ] && echo -en "Compression, yep" >> $mountpoint/tmp/USING-COMP2886 [ "$USE_STAR" = "yes" ] && echo -en "Using star. Hooray." >> $mountpoint/tmp/USING-STAR2887 fi2888 mkdir -p $mountpoint/tmp2889 mkdir -p $mountpoint/proc2890 echo "$disksize" > $mountpoint/tmp/$disksize.siz2891 find $mountpoint -name CVS -exec rm -rf '{}' \;2892 umount $mountpoint || Die "Cannot unmount $tempfile"2893 dd if=$tempfile bs=1k 2> /dev/null | gzip -v9 > $rdz_fname 2> /dev/null2894 # gzip -9 $tempfile2895 # mv $tempfile.gz $rdz_fname2896 if [ "$res" -eq "0" ] ; then2897 echo -en "..."2898 else2899 echo -en "\rMade an rdz WITH ERRORS. \n"2900 fi2901 return 02902 }2903 2904 2905 2906 WhichOfTheseModulesAreLoaded() {2907 local modname loaded_modules2908 loaded_modules=" `lsmod | tr -s ' ' '\t' | cut -f1 | grep -Fvx "Modules" | tr '\n' ' '` "2909 for modname in $1 ; do2910 [ "`echo "$loaded_modules" | grep -F " $modname "`" ] && echo "$modname"2911 done2912 }2913 2914 2915 2916 2917 ZipMinidirsIntoTarballs() {2918 local minidir_root tardir noof_disks diskno old_pwd i2919 minidir_root=$12920 tardir=$22921 noof_disks=$32922 2923 echo -en "Tarring and zipping the group`PluralOrNot $noof_disks`..."2924 mkdir -p $tardir2925 mkdir -p $minidir_root/all2926 old_pwd=`pwd`2927 diskno=12928 while [ "$diskno" -le "$noof_disks" ] ; do2929 cd $minidir_root/$diskno || LogIt "Warning - cannot cd to $minidir_root/$diskno\n"2930 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."2931 diskno=$(($diskno+1))2932 echo -n "..."2933 cp -pRdf * $minidir_root/all2934 done2935 mkdir -p $minidir_root/all/tmp2936 cd $minidir_root/all2937 size_of_all_tools=`du -sk . | cut -f1`2938 if [ "`DidMondoCallMe`" ] ; then2939 for q in filelist.full.gz biggielist.txt ; do2940 [ ! -e "$MONDO_TMP/$q" ] && Die "Cannot find $MONDO_TMP/$q"2941 cp -pRdf $MONDO_TMP/$q tmp/2942 done2943 mkdir -p $minidir_root/all/tmp2944 echo -en "$FILES_IN_FILELIST" > $minidir_root/all/tmp/FILES-IN-FILELIST 2> /dev/null2945 echo -en "$LAST_FILELIST_NUMBER" > $minidir_root/all/tmp/LAST-FILELIST-NUMBER 2> /dev/null2946 fi2947 tar -b 4096 -cf - * 2> /dev/null | gzip -9 > $tardir/all.tar.gz2948 dd if=/dev/zero bs=1k count=64 >> $imagesdir/all.tar.gz 2> /dev/null2949 [ "`du -sm $imagesdir/all.tar.gz | cut -f1`" -ge "30" ] && Die "You have too many tools in your shed"2950 cd $old_pwd2951 rm -Rf $minidir_root2952 echo -e "$DONE"2953 }2954 2955 2956 2957 # BERLIOS: This function is wrong2958 # Should be recoded. Desactivated in between2959 2960 #ListUnsavedKernelModules() {2961 #local fname modules2962 #fname=/tmp/$RANDOM.$$.$RANDOM2963 #lsmod | sed -n '2,$s/ .*//p' > $fname2964 #modules=`sort $fname | uniq -d2 | tr '\n' ' '`2965 #rm -f $fname2966 #[ "$modules" ] && echo "Unsaved kernel modules: $modules" >> $LOGFILE2967 #}2968 2969 2970 2971 2972 2973 ##############################################################################2974 #----------------------------------- main -----------------------------------#2975 ##############################################################################2976 2977 2978 #AWK=`which gawk`2979 #LocateDeps $12980 #MakeModuleLoadingScript /tmp/load-modules.sh2981 #exit 02982 2983 2984 #cat /etc/mindi/deplist.txt | GenerateGiantDependencyList /tmp/deplist.old 2002985 #exit 02986 2987 2988 2989 if [ "$1" = "-V" ] || [ "$1" = "-v" ] || [ "$1" = "--version" ] || [ "$1" = "-version" ] ; then2990 echo "mindi v$MINDI_VERSION"2991 exit 02992 fi2993 2994 > $LOGFILE2995 echo "mindi v$MINDI_VERSION" >> $LOGFILE2996 echo "$ARCH architecture detected" >> $LOGFILE2997 echo "mindi called with the following arguments:" >> $LOGFILE2998 echo "$@" >> $LOGFILE2999 3000 if [ -e "/etc/conf.modules" ] && [ ! -e "/etc/modules.conf" ] ; then3001 LogIt "Warning - Ancient distro detected.\n" 13002 ln -sf /etc/conf.modules /etc/modules.conf3003 fi3004 [ -e "/sbin/mkdosfs" ] && [ ! -e "/sbin/mkfs.vfat" ] && ln -sf /sbin/mkdosfs /sbin/mkfs.vfat3005 3006 FindHomeOfMindiAndMondo3007 trap AbortHere SIGTERM SIGHUP SIGQUIT SIGKILL SIGABRT SIGINT3008 AbortIfYourDistroIsAPieceOfStercus3009 [ "`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"3010 # If we have a 2.6 kernel, the system uses module-init-tools which means that we3011 # may have the modprobe configuration spread out across multiple files in3012 # directory /etc/modprobe.d. If this is the case we concatenate these files into3013 # a temporary file for further processing. Otherwise we continue in the standard3014 # way. Note further that in case /etc/modprobe.d exists, we use it and ignore3015 # /etc/modprobe.conf which is exactly what module-init-tools does. The temporary3016 # modprobe.conf file is created in MakeModuleLoadingScript. AL041128.3017 if [ -d "/etc/modprobe.d" ] && [ `uname -r | cut -c1-3` == "2.6" ] ; then3018 TMPMODPROBE_FLAG="Y"3019 else3020 TMPMODPROBE_FLAG="N"3021 [ -e "/etc/modprobe.conf" ] && [ ! -e "/etc/modules.conf" ] && ln -sf /etc/modprobe.conf /etc/modules.conf3022 [ ! -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..."3023 fi3024 FixPathIfBroken3025 [ -f "$MINDI_LIB/vmlinuz" ] && FAILSAFE_KVER=`strings $MINDI_LIB/vmlinuz 2> /dev/null | grep -E "2\.[46]" | cut -d' ' -f1`3026 AbortIfMkfsVfatMissing3027 ### BCO3028 ### Fix as it's not mandatory on ia643029 if [ "$ARCH" = "ia64" ] ; then3030 FindELiloBinary3031 else3032 FindIsolinuxBinary3033 FindLiloBinary3034 fi3035 grep -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 reason3036 rm -f /tmp/mindi_lo3037 trap "Aborted" SIGTERM3038 DONE="\r\t\t\t\t\t\t\t\tDone. "3039 CHOPSIZE=2403040 BIGNO=03041 MAX_COMPRESSED_SIZE=13003042 imagesdir=/root/images/mindi3043 mkdir -p $imagesdir3044 kernelpath=""3045 MONDO_ROOT=/tmp/mindilinux/mondo-root3046 mkdir -p $MONDO_ROOT3047 3048 if [ -d "/proc/lvm" ]; then3049 # LVM v13050 LVMCMD=""3051 LVM="v1"3052 elif [ -d "/dev/mapper" ]; then3053 # LVM v23054 LVMCMD="lvm"3055 LVM="v2"3056 else3057 LVM="false"3058 fi3059 3060 if [ "$#" -ge "2" ] ; then3061 if [ "$1" = "--max-compressed-size" ] ; then3062 MAX_COMPRESSED_SIZE=$23063 shift; shift3064 fi3065 fi3066 3067 FLOPPY_WAS_MOUNTED=""3068 for mtpt in /media/floppy /mnt/floppy /floppy ; do3069 if mount | grep -w $mtpt &> /dev/null ; then3070 FLOPPY_WAS_MOUNTED="$FLOPPY_WAS_MOUNTED $mtpt"3071 umount $mtpt3072 fi3073 done3074 3075 if [ "$#" -ne "0" ] ; then3076 if [ "$1" = "--findkernel" ] ; then3077 res=`TryToFindKernelPath`3078 # 2> /dev/null`3079 if [ "$res" = "" ] ; then3080 exit 13081 else3082 echo "$res"3083 exit 03084 fi3085 elif [ "$1" = "--makemountlist" ] ; then3086 [ ! "$2" ] && Die "Please specify the output file"3087 MakeMountlist $23088 exit $?3089 elif [ "$1" = " --version" ] || [ "$1" = "-v" ] ; then3090 echo "Mindi v$MINDI_VERSION"3091 exit 03092 elif [ "$#" -ge "9" ] && [ "$1" = "--custom" ] ; then3093 TMP_ROOT=$23094 MONDO_TMP=$23095 imagesdir=$33096 kernelpath=$4; [ "$kernelpath" = "(null)" ] && kernelpath=""3097 ###3098 ### Sq-Modification...3099 ### Attempt to locate kernel specific module path3100 ### if module path is found then use it other wise use uname -r to set it...3101 ###3102 kernelname=`echo $kernelpath | cut -d'-' -f2-`3103 LogIt "kernelname = $kernelname\n"3104 LogIt "kernelpath = $kernelpath\n"3105 if [ ! -d "/lib/modules/$kernelname" ] && [ "$kernelpath" != "FAILSAFE" ]3106 then3107 LogIt "Module path for ${kernelpath} not found...\n"3108 LogIt "using running kernel\'s modules.\n"3109 kernelname=`uname -r`3110 else3111 LogIt "Using modules for kernel: ${kernelname}\n"3112 fi3113 ###3114 ### end of Sq-Modification3115 ###3116 TAPEDEV=$53117 TAPESIZE=$63118 FILES_IN_FILELIST=$73119 USE_LZO=$83120 CDRECOVERY=$93121 if [ "${10}" = "(null)" ] || [ "${10}" = "" ] ; then3122 IMAGE_DEVS=""3123 else3124 IMAGE_DEVS="`echo "${10}" | tr '|' ' '`"3125 fi3126 if [ "${11}" ] ; then3127 LILO_OPTIONS=""3128 # LogIt "LILO will use conservative settings, to be compatible with older BIOSes."3129 fi3130 LAST_FILELIST_NUMBER=${12}3131 ESTIMATED_TOTAL_NOOF_SLICES=${13}3132 EXCLUDE_DEVS="${14}"3133 USE_COMP="${15}"3134 USE_LILO="${16}"3135 USE_STAR="${17}"3136 INTERNAL_TAPE_BLOCK_SIZE="${18}"3137 DIFFERENTIAL="${19}"3138 NOT_BOOT="${20}"3139 [ "$USE_COMP" = "" ] && USE_COMP=yes3140 [ "$NOT_BOOT" = "" ] && NOT_BOOT=no3141 [ "$TAPEDEV" ] && LogIt "This is a tape-based backup. Fine.\n"3142 [ "$kernelpath" = "" ] && kernelpath=`TryToFindKernelPath`3143 kernelname=`echo $kernelpath | cut -d'-' -f2-`3144 if [ ! -d "/lib/modules/$kernelname" ] && [ "$kernelpath" != "FAILSAFE" ]3145 then3146 LogIt "Module path for ${kernelpath} not found...\n"3147 LogIt "using running kernel\'s modules.\n"3148 kernelname=`uname -r`3149 else3150 LogIt "Using modules for kernel: ${kernelname}\n"3151 fi3152 [ "$CDRECOVERY" = "yes" ] && [ "$TAPEDEV" != "" ] && Die "Sorry, you can't use --cd-recovery and --write-tapes at the same time"3153 MONDO_ROOT=`echo $imagesdir | sed 's/\(.*\)\/.*/\1/'`3154 [ "$MONDO_ROOT" = "" ] && Die "MONDO_ROOT is undefined"3155 else3156 echo "Syntax: mindi (--custom ....)" >> /dev/stderr3157 exit 13158 fi3159 fi3160 #ScanCDandTape3161 [ "$CDRECOVERY" = "yes" ] || CDRECOVERY=no3162 if [ "$CDRECOVERY" = "yes" ] ; then3163 iso_cfg_file=$MINDI_LIB/isolinux-H.cfg3164 sys_cfg_file=$MINDI_LIB/syslinux-H.cfg3165 else3166 iso_cfg_file=$MINDI_LIB/isolinux.cfg3167 sys_cfg_file=$MINDI_LIB/syslinux.cfg3168 fi3169 3170 3171 3172 3173 #ReplaceIndividualLine /tmp/init `grep -n "#WHOLIVESINAPINEAPPLEUNDERTHESEA#" /tmp/init | cut -d':' -f1` "$RUN_AFTER_INITIAL_BOOT_PHASE"3174 #exit 03175 3176 3177 #ListKernelModules3178 #exit 03179 3180 3181 3182 3183 [ -e "$iso_cfg_file" ] || Die "Cannot find $iso_cfg_file"3184 rm -Rf $TMP_ROOT/mindilinux/*3185 TMP_ROOT=$TMP_ROOT/mindilinux/$$3186 mkdir -p $TMP_ROOT3187 mkdir -p $imagesdir3188 if [ ! "`DidMondoCallMe`" ] ; then3189 LogIt "Mindi Linux mini-distro generator v$MINDI_VERSION\n"3190 LogIt "Latest Mindi is available from http://mondorescue.berlios.de\n"3191 LogIt "BusyBox sources are available from http://www.busybox.net\n"3192 LogIt "------------------------------------------------------------------------------"3193 else3194 echo "You are using Mindi-Linux v$MINDI_VERSION to make boot+data disks" >> /var/log/mondo-archive.log3195 fi3196 3197 # for Mandrake 9.2, which comes with two aes.o.gz modules :-/3198 insmod /lib/modules/`uname -r`/*/*/misc/aes.*o.gz >> $LOGFILE 2>> $LOGFILE3199 for i in loop cdrom ide-cd isofs linear raid0 raid1 raid5 ; do3200 insmod $i >> $LOGFILE 2>> $LOGFILE3201 done3202 3203 FILE_CACHE=$TMP_ROOT/mindi-file-loc-cache3204 KERN_DISK_MADE=""3205 3206 echo "DIFFERENTIAL = $DIFFERENTIAL" >> $LOGFILE3207 echo "INTERNAL TAPE BLOCK SIZE = $INTERNAL_TAPE_BLOCK_SIZE" >> $LOGFILE3208 echo "NOT_BOOT = '$NOT_BOOT'" >> $LOGFILE3209 if [ "$NOT_BOOT" != "" ] && [ "$NOT_BOOT" != "0" ] && [ "$NOT_BOOT" != "no" ] ; then3210 LogIt "Just creating mondo-restore.cfg and a small all.tar.gz for Mondo. Nothing else.\n"3211 MakeMondoConfigFile $MONDO_TMP/mondo-restore.cfg3212 MakeMountlist $MONDO_TMP/mountlist.txt3213 mkdir -p $MONDO_TMP/small-all/tmp3214 cd $MONDO_TMP/small-all3215 cp -f $MONDO_TMP/{mountlist.txt,mondo-restore.cfg,filelist.full.gz,biggielist.txt} tmp || Die "Cannot copy small all.tar.gz"3216 tar -cv tmp | gzip -9 > $MONDO_TMP/all.tar.gz || Die "Cannot make small all.tar.gz"3217 sleep 23218 LogIt "Done. Exiting.\n"3219 exit 03220 fi3221 3222 if [ "$kernelpath" = "" ] ; then3223 [ "`DidMondoCallMe`" ] && Die "Please use -k <path> to specify kernel."3224 if [ $USE_OWN_KERNEL != "yes" ]; then3225 echo -en "Do you want to use your own kernel to build the boot disk (y/n) ?"3226 read ch3227 if [ "$ch" != "n" ] && [ "$ch" != "N" ] ; then3228 USE_OWN_KERNEL="yes"3229 fi3230 fi3231 if [ "$USE_OWN_KERNEL" = "yes" ]; then3232 YOUR_KERNEL_SUCKS=""3233 kernelpath=`TryToFindKernelPath`3234 if [ "$kernelpath" = "" ] ; then3235 echo -n "Please enter kernel path : "3236 read kernelpath3237 fi3238 else3239 YOUR_KERNEL_SUCKS="That's why you're using mine, dude. :-)"3240 fi3241 fi3242 if [ ! "`DidMondoCallMe`" ] ; then3243 echo -en "Would you like to use LILO (instead of syslinux)\nfor your boot CD/floppies (y/n) ?"3244 read ch3245 if [ "$ch" != "n" ] && [ "$ch" != "N" ] ; then3246 USE_LILO=yes3247 else3248 USE_LILO=no3249 fi3250 fi3251 if [ "$YOUR_KERNEL_SUCKS" != "" ] || [ "$kernelpath" = "" ] || [ "$kernelpath" = "SUCKS" ] || [ "$kernelpath" = "FAILSAFE" ] ; then3252 kernelpath=$MINDI_LIB/vmlinuz3253 LogIt "I shall include Mindi's failsafe kernel, not your kernel, in the boot disks.\n"3254 LogIt "However, you are still running your kernel. If Mindi fails to create your\n"3255 LogIt "disks then it may still be a result of a problem with your kernel.\n"3256 pwd=`pwd`3257 cd $TMP_ROOT3258 bzip2 -dc $MINDI_LIB/lib.tar.bz2 | tar -x || Die "Cannot unzip lib.tar.bz2"3259 cd $pwd3260 YOUR_KERNEL_SUCKS="Your kernel sucks"3261 fi3262 echo -e "Mindi's temp dir = $TMP_ROOT \nMindi's output dir=$imagesdir" >> $LOGFILE3263 [ "$(($RANDOM%64))" -eq "0" ] && LogIt "Dude, I've looked inside your computer and it's really dusty...\n"3264 rm -f /tmp/mindi.err.*.tgz3265 3266 [ "$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."3267 3268 rm -f /root/images/mindi/{*img,*gz,*iso}3269 3270 PrepareDataDiskImages $imagesdir3271 noof_disks=$?3272 ramdisk_size=$(($size_of_all_tools+$EXTRA_SPACE))3273 rds=$(($ramdisk_size-$((ramdisk_size%4096))))3274 ramdisk_size=$rds3275 3276 echo "Ramdisk will be $ramdisk_size KB" >> $LOGFILE3277 if [ "$USE_LILO" = "yes" ] ; then3278 if [ "$ARCH" = "ia64" ] ; then3279 PrepareBootDiskImage_LILO $imagesdir $IA64_BOOT_SIZE $kernelpath $ramdisk_size || Die "Failed to create ia64 floppy disk image."3280 else3281 if ! PrepareBootDiskImage_LILO $imagesdir 1722 $kernelpath $ramdisk_size ; then3282 LogIt "Warning - failed to create 1.72MB boot image. Please reduce your kernel's size\n"3283 LogIt "if you want to make a 1.72MB floppy disk.\n"3284 fi3285 if ! PrepareBootDiskImage_LILO $imagesdir 2880 $kernelpath $ramdisk_size ; then3286 LogIt "Warning - failed to create 2.88MB floppy disk image.\n"3287 LogIt "Please reduce your kernel's size\n"3288 LogIt "if you want to make a 2.88MB floppy disk.\n"3289 PrepareBootDiskImage_LILO $imagesdir 5760 $kernelpath $ramdisk_size || Die "Failed to create 2.88MB floppy disk image."3290 fi3291 fi3292 else3293 if ! PrepareBootDiskImage_SYSLINUX $imagesdir 1722 $kernelpath $ramdisk_size ; then3294 LogIt "Warning - failed to create 1.72MB boot image. Please reduce your kernel's size\n"3295 LogIt "if you want to make a 1.72MB floppy disk.\n"3296 if ! PrepareBootDiskImage_SYSLINUX $imagesdir 2880 $kernelpath $ramdisk_size ; then3297 LogIt "Warning - failed to create 2.88MB floppy disk image.\n"3298 LogIt "Please reduce your kernel's size\n"3299 LogIt "if you want to make a 2.88MB floppy disk.\n"3300 PrepareBootDiskImage_SYSLINUX $imagesdir 5760 $kernelpath $ramdisk_size || Die "Failed to create 5.76MB floppy disk image."3301 fi3302 fi3303 fi3304 3305 3306 3307 [ -e "$MINDI_LIB/memtest.img" ] && BOOT_MEDIA_MESSAGE="$BOOT_MEDIA_MESSAGE\n\3308 ...Or type 'memtest' to test your PC's RAM thoroughly.\n"3309 3310 3311 if [ ! "`DidMondoCallMe`" ] ; then3312 ListImagesForUser $imagesdir3313 boot_dev=/dev/fd0u17223314 [ ! -e "$boot_dev" ] && mknod $boot_dev b 2 603315 [ ! -e "$boot_dev" ] && boot_dev=/dev/fd0H17223316 [ ! -e "$boot_dev" ] && Die "Oh Lord, will you PLEASE tell the vendor to create the 1.72MB devices in /dev?"3317 if [ "$PROMPT_WRITE_BOOT_FLOPPIES" = "yes" ]; then3318 OfferToCopyImagesToDisks $imagesdir $boot_dev $FDDEVICE3319 fi3320 OfferToMakeBootableISO $imagesdir3321 LogIt "Finished.\n"3322 elif [ "$TAPEDEV" ] ; then3323 mkdir -p /root/images/mindi3324 rm -f /root/images/mindi/{*img,*gz,*iso}3325 OfferToMakeBootableISO $imagesdir3326 if [ -e "$imagesdir/all.tar.gz" ] ; then3327 cp -f $imagesdir/all.tar.gz $MONDO_TMP/3328 else3329 Die "Cannot find all.tar.gz, to be written to tape"3330 fi3331 else3332 OfferToMakeBootableISO $imagesdir3333 fi3334 if [ "$imagesdir" != "/root/images/mindi" ] ; then3335 for i in `find $imagesdir -maxdepth 1 -name "*.iso" -o -name "*.img"` ; do3336 cp -f $i /root/images/mindi || LogIt "[line 3260] Cannot copy $i to /root/images/mindi\n"3337 done3338 fi3339 [ "$TMP_ROOT" != "/tmp" ] && rm -Rf $TMP_ROOT3340 # cleanup3341 rm -fR /tmp/mountlist.txt.$$ $FDISKLOG /tmp/mindilinux3342 LogIt "$FRIENDLY_OUTSTRING\n"3343 #ListUnsavedKernelModules3344 for mtpt in $FLOPPY_WAS_MOUNTED ; do3345 mount $mtpt3346 done3347 echo "Mindi is exiting" >> $LOGFILE3348 exit 0 -
branches/stable/mindi/rootfs/sbin/LogIt
r30 r746 1 1 #!/bin/sh 2 # 3 # $Id$ 4 # 2 5 3 6 # if [ ! -e "/bin/date" ] ; then … … 8 11 currdate="" 9 12 10 LOGFILE=/tmp/mondo-restore.log 11 if [ ! -e "/tmp/mondo-restore.log" ] ; then 12 echo "...first line..." > /tmp/mondo-restore.log 13 fi 14 # mkdir -p /var/log 15 # ln -s -f /tmp/mondo-restore.log /var/log/mondo-restore.log 13 LOGFILE=/tmp/mondo-restore.log 14 if [ ! -e "$LOGFILE" ] ; then 15 echo "...first line..." > $LOGFILE 16 fi 16 17 17 18 # LogIt $phrase ------ log only -
branches/stable/mindi/rootfs/sbin/init
r740 r746 78 78 openvt 6 /bin/sh 79 79 openvt 7 /bin/sh /sbin/wait-for-petris 80 # openvt 8 /usr/bin/tail -f /tmp/mondo-restore.log81 80 } 82 81 … … 231 230 LogIt "Devfs found. Testing kernel support..." 232 231 if [ ! -e "/dev/.devfsd" ] ; then 233 mount -t devfs devfs /dev 2>> /tmp/mondo-restore.log232 mount -t devfs devfs /dev 2>> $LOGFILE 234 233 if [ "$?" -ne "0" ] ; then 235 234 LogIt "Error while trying to mount devfs" … … 369 368 mount_cmd="mount /dev/shm -t tmpfs -o size=$size" ; # was 34m until 04/2003 370 369 LogIt "Trying '$mount_cmd'" 371 $mount_cmd /tmp/tmpfs 2>> / tmp/mondo-restore.log370 $mount_cmd /tmp/tmpfs 2>> /$LOGFILE 372 371 res=$? 373 372 [ "$res" -eq "0" ] && break … … 518 517 fi 519 518 hack-cfg-if-necessary || LogIt "Cannot find hack-cfg-if-necessary" 520 openvt 8 /usr/bin/tail -f /tmp/mondo-restore.log519 openvt 8 /usr/bin/tail -f $LOGFILE 521 520 522 521 #-------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.