source: MondoRescue/branches/2.2.5/mindi/mindi @ 1575

Last change on this file since 1575 was 1575, checked in by Bruno Cornec, 13 years ago

Fix a bug in interactive mode on ia64 where lilo wasn't forced.

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