source: trunk/mindi/mindi @ 226

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

merge -r218:225 $SVN_M/branches/2.05

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