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

Last change on this file since 861 was 861, checked in by Bruno Cornec, 18 years ago

Fix bugs on ReadAllLink and use it more

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