source: trunk/mindi/mindi @ 903

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

merge -r862:888 $SVN_M/branches/stable

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