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

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

Correct approach of the previous problem

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