[initscripts] prevent to create /dev/tty0.
[vuplus_openvuplus_3.0] / meta-openvuplus / recipes-core / udev / udev-124 / mount.sh
1 #!/bin/sh
2 #
3 # Called from udev
4 # Attemp to mount any added block devices 
5 # and remove any removed devices
6 #
7
8 MOUNT="/bin/mount"
9 PMOUNT="/usr/bin/pmount"
10 UMOUNT="/bin/umount"
11 name="`basename "$DEVNAME"`"
12
13 for line in `cat /etc/udev/mount.blacklist | grep -v ^#`
14 do
15         if ( echo "$DEVNAME" | grep -q "$line" )
16         then
17                 logger "udev/mount.sh" "[$DEVNAME] is blacklisted, ignoring"
18                 exit 0
19         fi
20 done
21
22 automount() {   
23         ! test -d "/media/$name" && mkdir -p "/media/$name"
24         
25         if ! $MOUNT -t auto -o sync $DEVNAME "/media/$name"
26         then
27                 #logger "mount.sh/automount" "$MOUNT -t auto $DEVNAME \"/media/$name\" failed!"
28                 rm_dir "/media/$name"
29         else
30                 logger "mount.sh/automount" "Auto-mount of [/media/$name] successful"
31                 touch "/tmp/.automount-$name"
32         fi
33 }
34         
35 rm_dir() {
36         # We do not want to rm -r populated directories
37         if test "`find "$1" | wc -l | tr -d " "`" -lt 2 -a -d "$1"
38         then
39                 ! test -z "$1" && rm -r "$1"
40         else
41                 logger "mount.sh/automount" "Not removing non-empty directory [$1]"
42         fi
43 }
44
45 if [ "$ACTION" = "add" ] && [ -n "$DEVNAME" ]; then
46         if [ -x "$PMOUNT" ]; then
47                 $PMOUNT $DEVNAME 2> /dev/null
48         elif [ -x $MOUNT ]; then
49                 $MOUNT $DEVNAME 2> /dev/null
50         fi
51         
52         # If the device isn't mounted at this point, it isn't configured in fstab
53         # 20061107: Small correction: The rootfs partition may be called just "rootfs" and not by
54         #           its true device name so this would break. If the rootfs is mounted on two places
55         #           during boot, it confuses the heck out of fsck. So Im auto-adding the root-partition
56         #           to /etc/udev/mount.blacklist via postinst 
57
58         cat /proc/mounts | awk '{print $1}' | grep -q "^$DEVNAME$" || automount 
59         
60 fi
61
62
63
64 if [ "$ACTION" = "remove" ] && [ -x "$UMOUNT" ] && [ -n "$DEVNAME" ]; then
65         for mnt in `cat /proc/mounts | grep "$DEVNAME" | cut -f 2 -d " " `
66         do
67                 $UMOUNT $mnt
68         done
69         
70         # Remove empty directories from auto-mounter
71         test -e "/tmp/.automount-$name" && rm_dir "/media/$name"
72 fi