File indexing completed on 2024-05-05 04:51:14

0001 #!/bin/bash
0002 
0003 #
0004 # This script is able to disable and enable automounting for a device.
0005 # It's usage is as follows:
0006 #
0007 #   k3b_automount disable /dev/cdrom
0008 # or
0009 #   k3b_automount enable /dev/cdrom
0010 #
0011 # /dev/cdrom needs to have an entry in /etc/fstab.
0012 # 
0013 # The supported automounting systems are subfs and supermount.
0014 #
0015 # Exit codes:
0016 #   0 - success
0017 #   1 - wrong usage
0018 #   2 - device not configured with subfs/supermount in /etc/fstab
0019 #   X - failed to mount/umount
0020 #
0021 
0022 DISABLE=1
0023 
0024 if [ $1 = "disable" ]; then
0025         DISABLE=1
0026 elif [ $1 = "enable" ]; then
0027         DISABLE=0
0028 else
0029         echo "Usage: $0 disable|enable <device>"
0030         exit 1
0031 fi
0032 
0033 DEVICE=$2
0034 
0035 if [ -z $DEVICE ]; then
0036         echo "Usage: $0 disable|enable <device>"
0037         exit 1
0038 fi
0039 
0040 # we have a mode and a device
0041 
0042 # open the fstab file and search the DEVICE
0043 if [ -n "`grep $DEVICE /etc/fstab | grep "subfs\|supermount"`" ]; then
0044         if [ $DISABLE = 1 ]; then
0045                 umount $DEVICE
0046         else
0047                 mount $DEVICE
0048         fi
0049         exit $?
0050 fi
0051 
0052 #
0053 # Ok, not using subfs or supermount
0054 # If some other userspace automounter (like ivman) is running it is sufficient
0055 # to unmount the device now to get the burning started. This however does not
0056 # fix the problem with DVD+RW burning which may be mounted once the burning has
0057 # been started.
0058 #
0059 # So we unmount the device in case it is mounted with iso9660 or udf (just to add
0060 # some security to this suid script. :(
0061 #
0062 if [ $DISABLE = 1 ] && [ -n "`grep $DEVICE /etc/mtab | grep "iso9660\|udf"`" ]; then
0063         umount $DEVICE
0064         exit $?
0065 fi
0066 exit 2