source: MondoRescue/branches/2.05/mindi/mindi @ 148

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