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

Last change on this file since 449 was 449, checked in by bcornec, 18 years ago

mindi.conf created and use in mindi + install.sh + rpm

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