source: branches/2.2.6/mindi/mindi @ 1948

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