source: branches/2.2.4/mindi/mindi @ 1465

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

Adds support for keyboard for Gentoo

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