source: branches/2.05/mindi/mindi @ 208

Last change on this file since 208 was 208, checked in by bcornec, 14 years ago

Add the $Rev$ tag to mindi to help debug

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