source: MondoRescue/branches/stable/mindi/mindi@ 966

Last change on this file since 966 was 966, checked in by Bruno Cornec, 17 years ago

mindi defaults are now visible in the main messages

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