summaryrefslogtreecommitdiffstats
path: root/libk3b/scripts/k3b_automount
blob: e86e960de9ac9bdd536696ddd9ad3cce89772b7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash

#
# This script is able to disable and enable automounting for a device.
# It's usage is as follows:
#
#   k3b_automount disable /dev/cdrom
# or
#   k3b_automount enable /dev/cdrom
#
# /dev/cdrom needs to have an entry in /etc/fstab.
# 
# The supported automounting systems are subfs and supermount.
#
# Exit codes:
#   0 - success
#   1 - wrong usage
#   2 - device not configured with subfs/supermount in /etc/fstab
#   X - failed to mount/umount
#

DISABLE=1

if [ $1 = "disable" ]; then
	DISABLE=1
elif [ $1 = "enable" ]; then
	DISABLE=0
else
	echo "Usage: $0 disable|enable <device>"
	exit 1
fi

DEVICE=$2

if [ -z $DEVICE ]; then
	echo "Usage: $0 disable|enable <device>"
	exit 1
fi

# we have a mode and a device

# open the fstab file and search the DEVICE
if [ -n "`grep $DEVICE /etc/fstab | grep "subfs\|supermount"`" ]; then
	if [ $DISABLE = 1 ]; then
		umount $DEVICE
	else
		mount $DEVICE
	fi
	exit $?
fi

#
# Ok, not using subfs or supermount
# If some other userspace automounter (like ivman) is running it is sufficient
# to unmount the device now to get the burning started. This however does not
# fix the problem with DVD+RW burning which may be mounted once the burning has
# been started.
#
# So we unmount the device in case it is mounted with iso9660 or udf (just to add
# some security to this suid script. :(
#
if [ $DISABLE = 1 ] && [ -n "`grep $DEVICE /etc/mtab | grep "iso9660\|udf"`" ]; then
	umount $DEVICE
	exit $?
fi
exit 2