[SCM] live-initscripts branch, master, updated. 41b161b586207379fb9ec57b6181ffb46d4dae39

Daniel Baumann daniel at debian.org
Sun Oct 25 08:47:03 UTC 2009


The following commit has been merged in the master branch:
commit 41b161b586207379fb9ec57b6181ffb46d4dae39
Author: Daniel Baumann <daniel at debian.org>
Date:   Sun Oct 25 09:45:41 2009 +0100

    Adding automount script.

diff --git a/debian/rules b/debian/rules
index 188d4ec..3a315f9 100755
--- a/debian/rules
+++ b/debian/rules
@@ -38,6 +38,7 @@ binary-indep: build install
 	dh_install
 	dh_installinit --name apt-upgrade --onlyscripts --no-restart-on-upgrade --no-start -- start 99 2 6 .
 	dh_installinit --name iptables --onlyscripts --no-restart-on-upgrade --no-start -- start 99 2 6 .
+	dh_installinit --name automount --onlyscripts --no-restart-on-upgrade --no-start -- start 16 2 6 .
 	dh_compress
 	dh_fixperms
 	dh_installdeb
diff --git a/scripts/automount b/scripts/automount
new file mode 100755
index 0000000..26d66d9
--- /dev/null
+++ b/scripts/automount
@@ -0,0 +1,158 @@
+#!/bin/sh
+
+# Copyright (C) 2009 Daniel Baumann <daniel at debian.org>
+#
+# live-helper comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
+# This is free software, and you are welcome to redistribute it
+# under certain conditions; see COPYING for details.
+
+### BEGIN INIT INFO
+# Provides:             automount
+# Required-Start:       $local_fs
+# Required-Stop:        $local_fs
+# Default-Start:        S
+# Default-Stop:         0 6
+# Description:          Automatically mount all block devices
+# Short-Description:    Automatically mount all block devices
+### END INIT INFO
+
+#set -e
+
+grep -qs automount /proc/cmdline || exit 0
+
+##############
+
+sys2dev ()
+{
+	sysdev=${1#/sys}
+	echo "/dev/$($udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
+}
+
+subdevices ()
+{
+	sysblock=${1}
+	r=""
+
+	for dev in "${sysblock}" "${sysblock}"/*
+	do
+		if [ -e "${dev}/dev" ]
+		then
+			r="${r} ${dev}"
+		fi
+	done
+
+	echo ${r}
+}
+
+get_fstype ()
+{
+	local FSTYPE
+	local FSSIZE
+
+	# fstype misreports LUKS devices
+	if is_luks "${1}"
+	then
+	    /lib/udev/vol_id -t ${1} 2>/dev/null
+	    return
+	fi
+
+	eval $(/usr/lib/klibc/bin/fstype ${1} 2>/dev/null)
+
+	if [ "${FSTYPE}" != "unknown" ]
+	then
+		echo ${FSTYPE}
+		return 0
+	fi
+
+	/lib/udev/vol_id -t ${1} 2>/dev/null
+}
+
+is_luks()
+{
+    devname="${1}"
+    if [ -x /sbin/cryptsetup ]
+    then
+	/sbin/cryptsetup isLuks "${devname}" 2>/dev/null || ret=${?}
+	return ${ret}
+    else
+	return 1
+    fi
+
+}
+
+##############################################################################################
+
+Do_stop ()
+{
+	for DIRECTORY in /media/*
+	do
+		umount "${DIRECTORY}" > /dev/null
+	done
+
+	for SYSBLOCK in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
+	do
+		PARTITIONS="$(subdevices ${SYSBLOCK})"
+
+		for ITEM in ${PARTITIONS}
+		do
+			DEVICE="$(sys2dev ${ITEM})"
+
+			rmdir --ignore-fail-on-non-empty /media/$(basename ${DEVICE}) > /dev/null 2>&1
+		done
+	done
+}
+
+Do_start ()
+{
+	# Scanning block devices
+	for SYSBLOCK in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
+	do
+		PARTITIONS="$(subdevices ${SYSBLOCK})"
+
+		for ITEM in ${PARTITIONS}
+		do
+			DEVICE="$(sys2dev ${ITEM})"
+			FS="$(get_fstype ${DEVICE})"
+			MOUNTPOINT="/media/$(basename ${DEVICE})"
+
+			case "${FS}" in
+				ntfs)
+					FS="ntfs-3g"
+					OPTIONS=""
+					;;
+
+				ext*)
+					OPTIONS=""
+					;;
+
+				*)
+					OPTIONS="-o uid=1000,gid=1000"
+					;;
+			esac
+
+			if [ "${FS}" != "iso9660" ]
+			then
+				mkdir -p ${MOUNTPOINT}
+				mount -t ${FS} ${OPTIONS} ${DEVICE} ${MOUNTPOINT} > /dev/null 2>&1
+
+				# Prepare normal partition for later mkswapfile usage.
+				#echo "${DEVICE} /media/$(basename ${DEVICE}) ${FS} defaults,noauto 0 0" >> /etc/fstab
+			fi
+		done
+	done
+}
+
+case "${1}" in
+	start)
+		Do_start
+		;;
+
+	stop|force-reload|restart)
+		Do_stop
+		;;
+
+	*)
+		echo "Usage: ${0} {start|stop|restart|force-reload}"
+		exit 1
+		;;
+esac

-- 
live-initscripts



More information about the debian-live-changes mailing list