source: branches/stable/mindi/mindi @ 1529

Last change on this file since 1529 was 1529, checked in by bruno, 12 years ago
  • ChangeLogs? updated for upcoming 2.2.4
  • Attempt to fix #177 by removing first headers and repodata directory before regenerating them.
  • Fix a problem in directory link handling in mindi (seen on gentoo 64) with the precious help of Francesco Talamona ti.liame_at_email.it
  • Gentoo ebuild are now unmasked on my side
  • usb-storage instead of usb_storage as a module name for Virtual CD support seems better
  • Document support for Proliant Virtual Media with mindi
  • Mandriva packages go first to contrib/testing not backport
  • Size of DVD is 4482 (or more surely 4480 to avoid problems). Fixed everywhere.
  • Fix a bug in Mandriva official package creation

(merge -r1519:1528 $SVN_M/branches/2.2.4)

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