source: branches/2.2.10/mindi/mindi @ 2874

Last change on this file since 2874 was 2874, checked in by bruno, 6 years ago

r4323@mzielinski: bruno | 2011-09-29 20:26:04 +0200

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