source: MondoRescue/branches/2.2.9/mindi/rootfs/sbin/find-and-mount-cdrom@ 2878

Last change on this file since 2878 was 2878, checked in by Bruno Cornec, 13 years ago
  • Uses the -d option of the mount command to avoid leaving loop devices in use. Probably provoked by the usage of a more recent busybox, but anyway that option doesn't hurt, and does nothing for non-loop devices. Should fix the problems reported on the ML with NFS and more than 8 ISO images (8 being the default number of loop devices available)
  • Property svn:keywords set to Id
File size: 2.4 KB
RevLine 
[1]1#!/bin/sh
2
3
4TryToFindCDROM() {
5# hda1 is there for testing
[1758]6 LogIt "find-and-mount-cdrom --- starting"
7 for device in /dev/hd? /dev/scd? /dev/rcd? /dev/sr? /dev/cd? /dev/ide/*/*/*/*/cd /dev/scsi/*/*/*/*/cd; do
8 [ ! "$SECOND_TRY" ] && LogIt "Trying $device"
[1983]9 if [ "`grep "using-cdstream yes" /tmp/mondo-restore.cfg 2> /dev/null`" ]; then
[1758]10 pwd=`pwd`
11 cd $GROOVY
12 tar -zxf $device 2> /tmp/mount.log
13 res=$?
14 cd $pwd
15 if [ "$res" -eq "0" ] ; then
16 clear
17 LogIt "Using cdstream as extended datadisk ($device). Good." 3
18 echo "Using cdstrea as extd dsk." > /tmp/TAPEDEV-HAS-DATA-DISKS
19 ln -sf $device /dev/cdrom
20 exit 0
21 fi
22 else
23 mount $device -t iso9660 -o ro /mnt/cdrom 2> /tmp/mount.log
24 res=$?
25 fi
[1888]26 if [ "$res" -ne "0" ] ; then
27 res=`cat /tmp/mount.log`
28 if [ "$res" = "mount: No medium found" ] ; then
29 [ ! "$SECOND_TRY" ] && LogIt "There is a CD-ROM drive at $device but no CD in it."
30 else
31 [ ! "$SECOND_TRY" ] && LogIt "It's not in $device; I'll keep looking"
32 fi
33 continue
[1758]34 fi
[1888]35 LogIt "$device has a CD-ROM in it"
[2878]36 umount -d /mnt/cdrom
[1888]37 ln -sf $device /dev/cdrom
38 if [ "$?" -ne "0" ]; then
39 LogIt "Unable to softlink $device to /dev/cdrom. That's weird."
40 continue
41 fi
[1758]42 LogIt "CD-ROM found at $device"
[1888]43 mount $device -t iso9660 -o ro /mnt/cdrom 2> /tmp/mount.log
[1758]44 if [ "$?" -ne "0" ] ; then
[1888]45 LogIt "Cannot mount /dev/cdrom (type iso9660) (dev=$device)"
[1758]46 continue
47 elif [ ! -d "/mnt/cdrom/archives" ] ; then
48 LogIt "There is a CD in $device but it's not a Mondo CD"
49 continue
50 else
51 LogIt "$device is where the Mondo CD lives."
52 which hdparm > /dev/null 2> /dev/null && hdparm -u1 -c3 -d1 $device
[1888]53 return 0
54 fi
[1758]55 done
56 LogIt "Failed to find CD-ROM"
57 return 1
[1]58}
59
60
61# -------------- main ------------
62
63[ "$1" = "--second-try" ] && SECOND_TRY=yes
64if [ ! "$GROOVY" ] ; then
[1758]65 LogIt "I'm not groovy!"
66 exit 1
[1]67fi
68
69TryToFindCDROM
70if [ "$?" -eq "0" ] ; then
[1758]71 [ "$SECOND_TRY" ] && add="At 2nd attempt, " || add=""
72 LogIt $add"CD-ROM found and mounted at $device" 3
73 echo "$device" > /tmp/CDROM-LIVES-HERE
74 LogIt "find-and-mount-cdrom --- leaving (0)"
75 exit 0
[1]76fi
[1885]77[ "$1" = "--second-try" ] && exit 1;
[2734]78if [ "`grep "using-cdstream yes" /tmp/mondo-restore.cfg 2> /dev/null`" ] ; then
[1758]79 LogIt "Because you are using cdstream, I won't try to mount CD."
80 exit 0
[1]81fi
82
[1885]83LogIt "Unable to find and mount your CD-ROM" 1
84LogIt "You probably miss the correct driver to support your CD-ROM drive" 1
85exit 2
Note: See TracBrowser for help on using the repository browser.