source: branches/stable/mindi/mindi @ 1049

Last change on this file since 1049 was 1049, checked in by bruno, 12 years ago

libata in double removed

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