source: branches/2.2.2/mindi/mindi @ 1315

Last change on this file since 1315 was 1315, checked in by bruno, 12 years ago

Log files are now consistent: mondoarchive.log for mondoarchive (containing also mindi.log) and mondorestore.log for mondorestore (copied from /tmp (ram) to /var/log (disk) at the end of the restore)
One include has been created for each bianry containing only that declaration ofr the moment, but which will be extended to include all local definitions (ps_* e.g.)
Doc updated accordingly
LOGFILE in restore process is now passed in the environment and not duplicated anymore
LogIt? is not redifined either
LOGFILE should be put in environment by mondoarchive for mindi's usage but that's a step left for later.

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