Changeset 747 in MondoRescue for branches


Ignore:
Timestamp:
Aug 5, 2006, 12:24:28 PM (18 years ago)
Author:
Bruno Cornec
Message:

mindi was accidentaly destroyed. Restored now

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mindi/mindi

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