source: MondoRescue/trunk/mindi/mindi @ 729

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

merge -r686:728 $SVN_M/branches/stable

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