source: branches/2.2.9/mindi/mindi @ 2166

Last change on this file since 2166 was 2166, checked in by Bruno Cornec, 11 years ago

Try to remove useless tar messages

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