source: branches/3.0/mindi/rootfs/sbin/find-and-mount-cdrom @ 3360

Last change on this file since 3360 was 3360, checked in by Bruno Cornec, 5 years ago

Backports from 3.2 (rev 3336-3359):

  • Improve kernel 3.14+ detection for initramfs
  • Fix installation of parted2fdisk under rootfs by removing useless -s option of install
  • Remove usage of internal function basename in parted2fdisk use File::Basename instead
  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1#!/bin/sh
2#
3# $Id: find-and-mount-cdrom 3360 2015-03-07 13:41:11Z 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.