source: MondoRescue/branches/2.2.0/mindi/mindi

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

OCBU Special: Adds DENY_MODS initialized with all OCMP modules to the 2.2.0

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