3 # Library to find CD devices.
5 # Copyright (C) 2003-2006 IBM
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License as
9 # published by the Free Software Foundation; either version 2 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 # Create a list of potential devices. Note that this may pick up some non-block
24 # devices; it is assumed that they will be filtered out by find_discs_with_media.
25 function find_disc_devices
() {
26 NUM_DEVICES
=`/bin/ls $(egrep '(cdr|dvd)' /etc/fstab | awk -F " " '{print $1}') /dev/cdr* /dev/dvd* /dev/cdrom/* /dev/sr* 2> /dev/null | sort | uniq | wc -l`
27 if [ $NUM_DEVICES -lt 1 ]; then
31 /bin
/ls $
(egrep '(cdr|dvd)' /etc
/fstab |
awk -F " " '{print $1}') /dev
/cdr
* /dev
/dvd
* /dev
/cdrom
/* /dev
/sr
* 2> /dev
/null |
sort |
uniq
34 # Try to find a disc with media in it. Hopefully, $DEFAULT_MOUNT already exists.
35 function find_discs_with_media
() {
36 # If the caller doesn't specify a DEFAULT_MOUNT point, specify one.
37 if [ -z "$DEFAULT_MOUNT" ]; then
40 POTENTIAL_DEVICES
=`find_disc_devices`
41 # Grab a list of all CD/DVD devices that we can find.
42 for i
in `echo "$POTENTIAL_DEVICES"`
44 # Did we get nothing at all?
45 if [ "$i" == "NONE" ]; then
50 # Is this a link pointing to a device that's in the
51 # list of potential discs AND isn't in fstab?
52 # We want to avoid considering /dev entries that are symlinked
53 # elsewhere ... but we also assume that anything in fstab was
54 # put there for a reason and ought to be considered anyway.
56 IN_LIST
=`echo "$POTENTIAL_DEVICES" | grep "$(readlink $i)" -c`
57 if [ $IN_LIST -gt 0 ]; then
58 IN_FSTAB
=`grep "^$i[ ]" /etc/fstab -c`
59 if [ $IN_FSTAB -eq 0 ]; then
67 IN_FSTAB
=`grep -c "^$i[ ]" /etc/fstab`
68 FSTAB_TYPE
=`grep "^$i[ ]" /etc/fstab | awk -F " " '{print $3}'`
69 if [ $IN_FSTAB -gt 0 -a "$FSTAB_TYPE" != "subfs" ]; then
70 # This device is listed in fstab and is NOT of
71 # type "subfs" (SLES9 weirdness); try to mount it.
72 mount
"$i" > /dev
/null
2> /dev
/null
75 if [ $RESULT -eq 0 ]; then
83 # Not in fstab, or the mount failed.
84 mount
"$i" "$DEFAULT_MOUNT" -t auto
> /dev
/null
2> /dev
/null
87 if [ $RESULT -eq 0 ]; then
88 # Mounted ok once we gave it options.