source: branches/stable/mindi/mindi @ 1062

Last change on this file since 1062 was 1062, checked in by andree, 12 years ago

Add script for finding distribution specific FAILSAFE kernel and add
hooks for calling it to mindi.
(Merge Debian enhancement into mainstream.)

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