source: MondoRescue/trunk/mindi/mindi @ 932

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

merge -r913:931 $SVN_M/branches/stable

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