source: MondoRescue/branches/3.2/mindi/rootfs/usr/sbin/find-and-mount-cdrom

Last change on this file was 3359, checked in by Bruno Cornec, 9 years ago
  • Adds an Id field for SVN
  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1#!/bin/sh
2#
3# $Id: find-and-mount-cdrom 3359 2015-03-07 13:34:19Z bruno $
4#
5
6
7TryToFindCDROM() {
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
67if [ ! "$GROOVY" ] ; then
68 LogIt "I'm not groovy!"
69 exit 1
70fi
71
72TryToFindCDROM
73if [ "$?" -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
79fi
80[ "$1" = "--second-try" ] && exit 1;
81if [ "`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
84fi
85
86LogIt "Unable to find and mount your CD-ROM" 1
87LogIt "You probably miss the correct driver to support your CD-ROM drive" 1
88exit 2
Note: See TracBrowser for help on using the repository browser.