hotplug2: procd does the hotplugging now
[openwrt/staging/dedeckeh.git] / package / block-mount / files / 40-mount
1 #!/bin/sh
2 # Copyright (C) 2009-2012 OpenWrt.org
3 # Copyright (C) 2010 Vertical Communications
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
8 . /lib/functions/block.sh
9
10 blkdev=`dirname $DEVPATH`
11 if [ `basename $blkdev` != "block" ]; then
12
13 device=`basename $DEVPATH`
14 mountpoint=`sed -ne "s|^[^ ]*/$device ||; T; s/ .*//p" /proc/self/mounts`
15
16 case "$ACTION" in
17 add)
18
19 local from_fstab
20 local anon_mount
21 local anon_swap
22 local anon_fsck
23 local mds_mount_target
24 local mds_mount_device
25 local mds_mount_fstype
26 local sds_swap_device
27 local use_device
28 local do_fsck=0
29 local fsck_type
30
31 local autoswap_from_fstab
32 local automount_from_fstab
33
34 mount_dev_section_cb() {
35 mds_mount_target="$2"
36 mds_mount_device="$3"
37 mds_mount_fstype="$4"
38 mds_mount_enabled="$6"
39 }
40
41 swap_dev_section_cb() {
42 sds_swap_device="$2"
43 return 0
44 }
45
46 config_get_automount
47 automount_from_fstab="$from_fstab"
48 [ "$automount_from_fstab" -eq 1 ] && {
49 config_get_mount_section_by_device "/dev/$device"
50 use_device="$mds_mount_device"
51 [ "$mds_mount_enabled" -eq 1 ] && {
52 if [ -n "$mds_mount_target" ]; then
53 grep -q "/dev/$device" /proc/swaps || grep -q "/dev/$device" /proc/mounts || {
54 ( mkdir -p "$mds_mount_target" && mount "$mds_mount_target" ) 2>&1 | tee /proc/self/fd/2 | logger -t 'fstab'
55 }
56 else
57 logger -t 'fstab' "Mount enabled for $mds_mount_device but it doesn't have a defined mountpoint (target)"
58 fi
59 }
60 }
61
62 [ -z "$use_device" ] && {
63 config_get_autoswap
64 autoswap_from_fstab="$from_fstab"
65
66 [ "$autoswap_from_fstab" -eq 1 ] && {
67 config_get_swap_section_by_device "/dev/$device"
68 use_device="$sds_swap_device"
69 }
70 }
71
72 grep -q "/dev/$device" /proc/swaps || grep -q "/dev/$device" /proc/mounts || {
73 [ "$anon_mount" -eq 1 -a -z "$use_device" ] && {
74 case "$device" in
75 mtdblock*) ;;
76 *)
77 ( mkdir -p /mnt/$device && mount /dev/$device /mnt/$device ) 2>&1 | tee /proc/self/fd/2 | logger -t 'fstab'
78 ;;
79 esac
80 }
81 }
82 reset_dev_section_cb
83 ;;
84 remove)
85 umount /dev/$device
86 umount $mountpoint
87 ;;
88 esac
89
90 fi
91