2005-09-20 15:19:38 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Called from udev
|
|
|
|
#
|
2008-06-23 10:27:10 +00:00
|
|
|
# Attempt to mount any added block devices and umount any removed devices
|
|
|
|
|
2005-09-20 15:19:38 +00:00
|
|
|
|
|
|
|
MOUNT="/bin/mount"
|
|
|
|
PMOUNT="/usr/bin/pmount"
|
|
|
|
UMOUNT="/bin/umount"
|
2006-05-09 19:35:13 +00:00
|
|
|
|
2008-08-08 07:41:48 +00:00
|
|
|
for line in `cat /etc/udev/mount.blacklist`
|
2006-05-09 19:35:13 +00:00
|
|
|
do
|
2008-08-08 07:41:48 +00:00
|
|
|
if [ ` expr match "$DEVNAME" "$line" ` -gt 0 ];
|
2006-05-09 19:35:13 +00:00
|
|
|
then
|
|
|
|
logger "udev/mount.sh" "[$DEVNAME] is blacklisted, ignoring"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
automount() {
|
2008-06-23 10:27:10 +00:00
|
|
|
name="`basename "$DEVNAME"`"
|
|
|
|
|
2006-05-09 19:35:13 +00:00
|
|
|
! test -d "/media/$name" && mkdir -p "/media/$name"
|
|
|
|
|
|
|
|
if ! $MOUNT -t auto -o sync $DEVNAME "/media/$name"
|
|
|
|
then
|
|
|
|
#logger "mount.sh/automount" "$MOUNT -t auto $DEVNAME \"/media/$name\" failed!"
|
|
|
|
rm_dir "/media/$name"
|
|
|
|
else
|
|
|
|
logger "mount.sh/automount" "Auto-mount of [/media/$name] successful"
|
|
|
|
touch "/tmp/.automount-$name"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
rm_dir() {
|
|
|
|
# We do not want to rm -r populated directories
|
|
|
|
if test "`find "$1" | wc -l | tr -d " "`" -lt 2 -a -d "$1"
|
|
|
|
then
|
|
|
|
! test -z "$1" && rm -r "$1"
|
|
|
|
else
|
|
|
|
logger "mount.sh/automount" "Not removing non-empty directory [$1]"
|
|
|
|
fi
|
|
|
|
}
|
2005-09-20 15:19:38 +00:00
|
|
|
|
|
|
|
if [ "$ACTION" = "add" ] && [ -n "$DEVNAME" ]; then
|
|
|
|
if [ -x "$PMOUNT" ]; then
|
|
|
|
$PMOUNT $DEVNAME 2> /dev/null
|
|
|
|
elif [ -x $MOUNT ]; then
|
|
|
|
$MOUNT $DEVNAME 2> /dev/null
|
|
|
|
fi
|
2006-05-09 19:35:13 +00:00
|
|
|
|
|
|
|
# If the device isn't mounted at this point, it isn't configured in fstab
|
2008-06-23 10:27:10 +00:00
|
|
|
grep -q "^$DEVNAME " /proc/mounts || automount
|
2005-09-20 15:19:38 +00:00
|
|
|
fi
|
|
|
|
|
2006-05-09 19:35:13 +00:00
|
|
|
|
|
|
|
|
2005-09-20 15:19:38 +00:00
|
|
|
if [ "$ACTION" = "remove" ] && [ -x "$UMOUNT" ] && [ -n "$DEVNAME" ]; then
|
|
|
|
for mnt in `cat /proc/mounts | grep "$DEVNAME" | cut -f 2 -d " " `
|
|
|
|
do
|
|
|
|
$UMOUNT $mnt
|
|
|
|
done
|
2006-05-09 19:35:13 +00:00
|
|
|
|
|
|
|
# Remove empty directories from auto-mounter
|
2008-06-23 10:27:10 +00:00
|
|
|
name="`basename "$DEVNAME"`"
|
2006-05-09 19:35:13 +00:00
|
|
|
test -e "/tmp/.automount-$name" && rm_dir "/media/$name"
|
2005-09-20 15:19:38 +00:00
|
|
|
fi
|