source: branches/3.1/mindi/mindi @ 2937

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

svn merge -r 2849:2935 ../3.0

  • Adds 3 binaries called potentially by udev o support USB key mount at restore time (Victor Gattegno)
  • mindi only sets the boot flag of a USB device if none is present already (should avoid flip/flop situation)
  • Fix a compatibility bug in analyze-my-lvm whete exclude lists with '|' was incorrectly analyzed (' ' still expected)
  • Precise that -J is not supported by mondorestore yet.
  • Fix a compatibility bug in mindi where exclude lists with '|' was incorrectly analyzed (' ' still expected)
  • Install an MBR on USB devices when possible
  • Improve error message in case mondorestore isn't found
  • Adds support for more virtio devices for KVM restore
  • Improve mbr.bin handling
  • Fix an issue in test of FindKernel? for Xen and non Xen cases
    • Fix #492 by removing an extra useless fi
    • Move fvat nd fat modules to CDROM_MODS in order to have them in the initrd to support saving logs to a USB device e.g.
    • Fix an error when dmidecode reports comments before system name
    • Fix previous broken patch on comment management for bkphw
    • Improve msgs printed during kbd analysis
    • Fix a small remaining pb with new comment support
    • Try to again improve the mount/umount stuff in mondo -Adds mention to OEL, CentOS, ScientifLinux? as RHEL clones
  • Fix a panadoid_free done on the wrong variable (solve a memory leak)
  • Solve #495 by skipping the potential (auto-read-only) when analyzin /proc/mdstat result
  • Fix some markup in man pages
  • adds the post-nuke script sample for Debian (Guillaume Pernot/Andrée? Leidenfrost)
  • Avoid a useless umount when changing of afio set, let insist_on_cd check and perform if needed
  • Copy everything under .ssh of root account to allow for sshfs mount without passwd at restore time.
  • Adds support for bnx2i driver
  • Try to fix #496 by supporting the protocol in the output of the mount command (sshfs#...)
  • Uses the -d option of the mount command to avoid leaving loop devices in use. Probably provoked by the usage of a more recent busybox, but anyway that option doesn't hurt, and does nothing for non-loop devices. Should fix the problems reported on the ML with NFS and more than 8 ISO images (8 being the default number of loop devices available)
  • Attempt to fix #436 by adding some newtDrawForm where appropriate.
  • Fix bugs in the kernel detection routine of mindi (some echo were done without capturing their output, confusing the return). This should also help the Xen detection issue
  • Change the logging function to be nearer from 2.2.10, and start using some
  • Initialize some global fields with an empty string, now that newt Draws more regularly progress forms
  • Mindi progression still not good, but showing now 3% when calling mindi. Would need a specific handling for the progress bar to evolve more afterwards
  • Add compatibility with the latest SSSTK + PSP content for HP ProLiant? + branding homogeneous now. We only take conrep out of the SSSTK pending a package availability. Using hpacuscripting now. Review of parameters called following test made.
  • Fix #501 by pushing BOOT_SIZE to 36864 for certain Ubuntu cases
  • Fix some remaining inconsistencis in the ProLiant? HW backup. ready for usage.
  • Fix an issue on udevadm call (needs an intermediate variable)
  • Fix a remaining ProLiant? tool call
  • Remove again some wrong variable initialization for Net in order to not have strange messages now we call Draw more often
  • Adds support for hwaddr (MAC addresses) at restore time, and map to the correct NIC if it's found at restore time (based on code from Stefan Heijmans)
  • Try to Fix #499 by changing init in order to never exit, and rebooting using sysrq in /proc (not portable). Maybe should move to using a real init, and a separated rcS script.
  • Fixes the shell msg error by using setsid as per Busybox FAQ
  • Fix #491 by correctly checking Xen kernel used for a dom0 env (apollo13)
  • Improves logging in Die()
  • Improve again ProLiant? HW support, by adding references to the yet to come SSSTK rpm so that conrep is called at its future right place.
  • Improve mindi support for kernel 3.x
  • Fix #499 for good, by using a real init from busybox and moving our init script to etc/init.d/rcS. We also now call the reboot from busybox to exit, which indeed reset the system correctly (in a VM at least which wasn't the case before). Reauires a new mindi-busybox as well.
  • Attempt to solve #503 by handling /lib64 separately for udev and only if not a link (to /lib) for Ubuntu 64
  • Improve again previous tests for bug #503
  • Improve -d option description for NFS
  • Allow http download for ftp content
  • New italian mirror
  • Fix #505 by documenting environment variables
    • Fix a bug where on OBDR mode compression was turned off to create the OBDR content but not back on (report from the mailing list)
  • solve http://trac.mondorescue.org/ticket/520 by Victor Gattegno
  • Fix #524 as option -U needs a size also
  • Removes useless gendf option
  • Fix #511 now stabgrub is called also after conf file modifications
  • Adds support for SUID binaries
  • remove a useless xenkernelname variable from mindi
  • Should fix #512 by clearing old scratchdir before changing to a new
  • Simplify the function engaging SCSI for Smart Array controllers, and support as many controller as we have
  • Add some binaries used on SLES 10 by udev
  • Fix a syntax issue in newt-specific.c
  • Fix a memory free bug where a used variable was freed to early
  • Fix a memory free bug where a used variable was misused in asprintf/free
  • Fix #498 by using an external program (hpsa_obdr_mode) which can set the mode of the tape to CD-ROM or Sequential at will.

That program will have to be downloaded from http://cciss.sf.net

  • Adds support for the route command in mindi-busybox
  • Force block size back to 32768 in OBDR mode after skipping the 2 tape marks, to read the additional rootfs data corerctly - Fix #498 for good it seems
  • Adds support for a new pata_atiixp driver
  • Fix #525 and improve printing when no /etc/raidtab, but still md devices
  • Exclude /run similarly to /sys and /proc
  • Fix a bug in mindi when having multiple swap partiions with same starting string (/dev/dm-1 and /dev/dm-16). We now add a space in the grep to avoid mischoice.
  • Fix grub installation if we had to go in the hack part which wasn't using the correct variables to make decisions !
  • Remove all mention of mondorescue.com from code
  • Fix some website typo on the download page and precise that we now develop on Mageia
  • Exclude sysfs devpts and tmpfs partitions found in RHEL 6.2 from analyze by mindi (made error messages)
  • Force activation of first partition which should not be optional as everything is destroyed before
  • Fix a bug in analyze-my-lvm where LVs were created in random order (the one of lvscan) instead of using the dm-xxx order, which creates issues at restore time between the mapping created then and the one we had at backup time which could be inconssistent

-mondoarchive now exists if the mt command is missing when needed

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