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

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

MINDI_LIB var is now correct on x86_64

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