source: MondoRescue/branches/2.05/mindi/mindi@ 179

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

New locations for mondo and mindi:

for distros for file base install


/usr/sbin/mindi /usr/local/sbin/mindi
/usr/sbin/analyze-my-lvm /usr/local/sbin/analyze-my-lvm
/usr/sbin/mondoarchive /usr/local/sbin/mondoarchive
/usr/sbin/mondorestore /usr/local/sbin/mondorestore
/etc/m?nd? /usr/local/etc/m?nd?
/usr/share/doc/m?nd?* /usr/local/share/doc/m?nd?*
/usr/share/man/man8/m?nd?*.8 /usr/local/share/man/man8/m?nd?*.8
/usr/lib/m?nd? /usr/local/lib/m?nd?

(mondo needs to be finished - untested yet)

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