summaryrefslogtreecommitdiffstats
path: root/libk3b/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'libk3b/scripts')
-rw-r--r--libk3b/scripts/Makefile.am11
-rwxr-xr-xlibk3b/scripts/k3b_automount66
2 files changed, 77 insertions, 0 deletions
diff --git a/libk3b/scripts/Makefile.am b/libk3b/scripts/Makefile.am
new file mode 100644
index 0000000..6318b9b
--- /dev/null
+++ b/libk3b/scripts/Makefile.am
@@ -0,0 +1,11 @@
+bin_SCRIPTS = k3b_automount
+
+# k3b_automount needs to be installed setuid root
+install-exec-hook:
+ @(chown 0 $(DESTDIR)$(bindir)/k3b_automount && chmod 4755 $(DESTDIR)$(bindir)/k3b_automount) || echo "Please make k3b_automount setuid root" >&2
+ @echo ""
+ @echo "k3b_automount is by default installed with a set SETUID root bit!"
+ @echo "This is needed for K3b to be able to temporarily disable automounting via"
+ @echo "subfs or supermount while burning."
+ @echo ""
+
diff --git a/libk3b/scripts/k3b_automount b/libk3b/scripts/k3b_automount
new file mode 100755
index 0000000..e86e960
--- /dev/null
+++ b/libk3b/scripts/k3b_automount
@@ -0,0 +1,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