source: branches/2.2.6/mindi/mindi @ 1927

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