source: MondoRescue/branches/stable/mindi/mindi @ 1570

Last change on this file since 1570 was 1570, checked in by Bruno Cornec, 13 years ago
  • Add support of Debian ia64 in mondo
  • Fix mindi iso build for ia64 (test was reversed)
  • Add support for gzip compressed kernel in mindi (ia64 SLES 10 is in that category)
  • arch => uname -m everywhere
  • parted2fdisk adapted for parted differences on SLES 10 ia64
  • reiserfs support added for parted2fdisk
  • decode_Bsuf function added for parted2fdisk
  • README.ia64 improved for SLES 10

(merge -r 1563:1567 $SVN_M/branches/2.2.5)

Also begin to remove floppy support from mindi

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