source: MondoRescue/trunk/mindi/mindi@ 939

Last change on this file since 939 was 939, checked in by Bruno Cornec, 17 years ago

merge -r931:938 $SVN_M/branches/stable

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