source: branches/2.2.5/mindi/mindi @ 1888

Last change on this file since 1888 was 1888, checked in by bruno, 11 years ago

Attempt again to fix #172 (fix from Angelo Pozzi angelo_mose.pozzi_at_alcatel-lucent.it)

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