source: MondoRescue/branches/3.0-mindi-2.1/mindi/rootfs/sbin/find-and-mount-cdrom@ 3563

Last change on this file since 3563 was 3563, checked in by Bruno Cornec, 8 years ago

Many additional backports from 3.2 and 3.0 future

  • Improved support for systemd
  • Launch start-netfs when a network conf is detected in the conf file to avoid an error later on in automatic mode
  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1#!/bin/sh
2#
3# $Id: find-and-mount-cdrom 3563 2016-04-11 17:43:30Z bruno $
4#
5
6TryToFindCDROM() {
7# hda1 is there for testing
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"
11 if [ "`grep "using-cdstream yes" /tmp/mondo-restore.cfg 2> /dev/null`" ]; then
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
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
36 fi
37 LogIt "$device has a CD-ROM in it"
38 umount -d /mnt/cdrom
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
44 LogIt "CD-ROM found at $device"
45 mount $device -t iso9660 -o ro /mnt/cdrom 2> /tmp/mount.log
46 if [ "$?" -ne "0" ] ; then
47 LogIt "Cannot mount /dev/cdrom (type iso9660) (dev=$device)"
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
55 return 0
56 fi
57 done
58 LogIt "Failed to find CD-ROM"
59 return 1
60}
61
62
63# -------------- main ------------
64
65[ "$1" = "--second-try" ] && SECOND_TRY=yes
66if [ ! "$GROOVY" ] ; then
67 LogIt "I'm not groovy!"
68 exit 1
69fi
70
71TryToFindCDROM
72if [ "$?" -eq "0" ] ; then
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
78fi
79[ "$1" = "--second-try" ] && exit 1;
80if [ "`grep "using-cdstream yes" /tmp/mondo-restore.cfg 2> /dev/null`" ] ; then
81 LogIt "Because you are using cdstream, I won't try to mount CD."
82 exit 0
83fi
84
85LogIt "Unable to find and mount your CD-ROM" 1
86LogIt "You probably miss the correct driver to support your CD-ROM drive" 1
87exit 2
Note: See TracBrowser for help on using the repository browser.