source: MondoRescue/trunk/mindi/mindi @ 863

Last change on this file since 863 was 863, checked in by Bruno Cornec, 14 years ago

merge -r838:862 $SVN_M/branches/stable

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