source: branches/2.05/mindi/mindi @ 242

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