source: MondoRescue/branches/2.06/mindi/mindi@ 297

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

ListUnsavedKernelModules and ListKernelModules are gone
(the first is wrong the second useless)

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