[1] | 1 | #!/bin/sh
|
---|
[3360] | 2 | #
|
---|
| 3 | # $Id: find-and-mount-cdrom 3360 2015-03-07 13:41:11Z bruno $
|
---|
| 4 | #
|
---|
[1] | 5 |
|
---|
| 6 | TryToFindCDROM() {
|
---|
| 7 | # hda1 is there for testing
|
---|
[1758] | 8 | LogIt "find-and-mount-cdrom --- starting"
|
---|
| 9 | for device in /dev/hd? /dev/scd? /dev/rcd? /dev/sr? /dev/cd? /dev/ide/*/*/*/*/cd /dev/scsi/*/*/*/*/cd; do
|
---|
| 10 | [ ! "$SECOND_TRY" ] && LogIt "Trying $device"
|
---|
[1983] | 11 | if [ "`grep "using-cdstream yes" /tmp/mondo-restore.cfg 2> /dev/null`" ]; then
|
---|
[1758] | 12 | pwd=`pwd`
|
---|
| 13 | cd $GROOVY
|
---|
| 14 | tar -zxf $device 2> /tmp/mount.log
|
---|
| 15 | res=$?
|
---|
| 16 | cd $pwd
|
---|
| 17 | if [ "$res" -eq "0" ] ; then
|
---|
| 18 | clear
|
---|
| 19 | LogIt "Using cdstream as extended datadisk ($device). Good." 3
|
---|
| 20 | echo "Using cdstrea as extd dsk." > /tmp/TAPEDEV-HAS-DATA-DISKS
|
---|
| 21 | ln -sf $device /dev/cdrom
|
---|
| 22 | exit 0
|
---|
| 23 | fi
|
---|
| 24 | else
|
---|
| 25 | mount $device -t iso9660 -o ro /mnt/cdrom 2> /tmp/mount.log
|
---|
| 26 | res=$?
|
---|
| 27 | fi
|
---|
[1888] | 28 | if [ "$res" -ne "0" ] ; then
|
---|
| 29 | res=`cat /tmp/mount.log`
|
---|
| 30 | if [ "$res" = "mount: No medium found" ] ; then
|
---|
| 31 | [ ! "$SECOND_TRY" ] && LogIt "There is a CD-ROM drive at $device but no CD in it."
|
---|
| 32 | else
|
---|
| 33 | [ ! "$SECOND_TRY" ] && LogIt "It's not in $device; I'll keep looking"
|
---|
| 34 | fi
|
---|
| 35 | continue
|
---|
[1758] | 36 | fi
|
---|
[1888] | 37 | LogIt "$device has a CD-ROM in it"
|
---|
[2878] | 38 | umount -d /mnt/cdrom
|
---|
[1888] | 39 | ln -sf $device /dev/cdrom
|
---|
| 40 | if [ "$?" -ne "0" ]; then
|
---|
| 41 | LogIt "Unable to softlink $device to /dev/cdrom. That's weird."
|
---|
| 42 | continue
|
---|
| 43 | fi
|
---|
[1758] | 44 | LogIt "CD-ROM found at $device"
|
---|
[1888] | 45 | mount $device -t iso9660 -o ro /mnt/cdrom 2> /tmp/mount.log
|
---|
[1758] | 46 | if [ "$?" -ne "0" ] ; then
|
---|
[1888] | 47 | LogIt "Cannot mount /dev/cdrom (type iso9660) (dev=$device)"
|
---|
[1758] | 48 | continue
|
---|
| 49 | elif [ ! -d "/mnt/cdrom/archives" ] ; then
|
---|
| 50 | LogIt "There is a CD in $device but it's not a Mondo CD"
|
---|
| 51 | continue
|
---|
| 52 | else
|
---|
| 53 | LogIt "$device is where the Mondo CD lives."
|
---|
| 54 | which hdparm > /dev/null 2> /dev/null && hdparm -u1 -c3 -d1 $device
|
---|
[1888] | 55 | return 0
|
---|
| 56 | fi
|
---|
[1758] | 57 | done
|
---|
| 58 | LogIt "Failed to find CD-ROM"
|
---|
| 59 | return 1
|
---|
[1] | 60 | }
|
---|
| 61 |
|
---|
| 62 |
|
---|
| 63 | # -------------- main ------------
|
---|
| 64 |
|
---|
| 65 | [ "$1" = "--second-try" ] && SECOND_TRY=yes
|
---|
| 66 | if [ ! "$GROOVY" ] ; then
|
---|
[1758] | 67 | LogIt "I'm not groovy!"
|
---|
| 68 | exit 1
|
---|
[1] | 69 | fi
|
---|
| 70 |
|
---|
| 71 | TryToFindCDROM
|
---|
| 72 | if [ "$?" -eq "0" ] ; then
|
---|
[1758] | 73 | [ "$SECOND_TRY" ] && add="At 2nd attempt, " || add=""
|
---|
| 74 | LogIt $add"CD-ROM found and mounted at $device" 3
|
---|
| 75 | echo "$device" > /tmp/CDROM-LIVES-HERE
|
---|
| 76 | LogIt "find-and-mount-cdrom --- leaving (0)"
|
---|
| 77 | exit 0
|
---|
[1] | 78 | fi
|
---|
[1885] | 79 | [ "$1" = "--second-try" ] && exit 1;
|
---|
[2734] | 80 | if [ "`grep "using-cdstream yes" /tmp/mondo-restore.cfg 2> /dev/null`" ] ; then
|
---|
[1758] | 81 | LogIt "Because you are using cdstream, I won't try to mount CD."
|
---|
| 82 | exit 0
|
---|
[1] | 83 | fi
|
---|
| 84 |
|
---|
[1885] | 85 | LogIt "Unable to find and mount your CD-ROM" 1
|
---|
| 86 | LogIt "You probably miss the correct driver to support your CD-ROM drive" 1
|
---|
| 87 | exit 2
|
---|