source: MondoRescue/trunk/mindi/mindi@ 1041

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

merge -r954:978 $SVN_M/branches/stable

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