source: trunk/mindi/mindi @ 292

Last change on this file since 292 was 292, checked in by bcornec, 13 years ago

svn merge -r288:291 $SVN_M/branches/2.06

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