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

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

Quality tool improvement
mindi had a dual NET_MODS line

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