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