|
#!/bin/sh |
|
|
|
. /lib/functions/block.sh |
|
|
|
set_devices(){ |
|
set_section="$(uci show fstab | grep "$get_uuid" | awk -F "." '{print $2}')" |
|
old_device=$(uci get fstab.${set_section}.device) |
|
[ "$old_device" != "/dev/$device" ]&&{ |
|
uci set fstab.${set_section}.device="/dev/$device" |
|
uci commit fstab |
|
} |
|
} |
|
|
|
set_fstab(){ |
|
|
|
# modified to fit for blkid of barrier breaker |
|
my_fstype="`blkid | grep "/dev/$device" | awk -F 'TYPE="' '{print $2}' | sed 's/\" //' | awk -F 'PARTUUID=' '{print $1}' | sed 's/"//g'`" |
|
|
|
[ -n "$my_fstype" ] && { |
|
|
|
if [ "$my_fstype" = 'swap' ]; then |
|
|
|
n=$(uci show fstab | grep "fstab.@swap" | grep -c "=swap") |
|
|
|
[ $n -gt 0 ] && { |
|
for i in $(seq 0 $n) |
|
do |
|
old_swap="$(uci get fstab.@swap[$i].device)" |
|
[ "$old_swap" = "/dev/$device" ] && { |
|
FLAG="SKIP" |
|
break |
|
} |
|
done |
|
} |
|
|
|
[ "$FLAG" != "SKIP" ] && { |
|
uci add fstab swap |
|
uci set fstab.@swap[$n]="swap" |
|
uci set fstab.@swap[$n].enabled='1' |
|
uci set fstab.@swap[$n].device="/dev/$device" |
|
} |
|
|
|
else |
|
|
|
n=$(uci show fstab | grep "fstab.@mount" | grep -c "=mount") |
|
|
|
uci add fstab mount |
|
uci set fstab.@mount[$n]="mount" |
|
uci set fstab.@mount[$n].enabled=1 |
|
uci set fstab.@mount[$n].device="/dev/$device" |
|
uci set fstab.@mount[$n].uuid="${get_uuid}" |
|
uci set fstab.@mount[$n].target="/mnt/$device" |
|
uci set fstab.@mount[$n].fstype="$my_fstype" |
|
|
|
case "$my_fstype" in |
|
ext*) |
|
uci set fstab.@mount[$n].options="rw";; |
|
'ntfs') |
|
uci set fstab.@mount[$n].options="noatime";; |
|
'exfat') |
|
uci set fstab.@mount[$n].options="noatime";; |
|
'vfat') |
|
uci set fstab.@mount[$n].options="utf8=1,umask=0000,dmask=0000,fmask=0000";; |
|
esac |
|
fi |
|
uci commit fstab |
|
} |
|
} |
|
|
|
blkdev=`dirname $DEVPATH` |
|
if [ `basename $blkdev` != "block" ]; then |
|
|
|
device=`basename $DEVPATH` |
|
mountpoint=`sed -ne "s|^[^ ]*/$device ||; T; s/ .*//p" /proc/self/mounts` |
|
|
|
case "$ACTION" in |
|
add) |
|
get_uuid=`blkid | grep "/dev/${device}" | awk -F "UUID=" '{print $2}'| awk -F "\"" '{print $2}'` |
|
[ -n "$get_uuid" ] && { |
|
have_uuid=$(uci show fstab | grep -c "$get_uuid") |
|
[ "$have_uuid" = "0" ] && set_fstab |
|
[ "$have_uuid" != "0" ] && set_devices |
|
} |
|
local from_fstab |
|
local anon_mount |
|
local anon_swap |
|
local anon_fsck |
|
local mds_mount_target |
|
local mds_mount_device |
|
local mds_mount_fstype |
|
local sds_swap_device |
|
local use_device |
|
|
|
local autoswap_from_fstab |
|
local automount_from_fstab |
|
|
|
mount_dev_section_cb() { |
|
mds_mount_target="$2" |
|
mds_mount_device="$3" |
|
mds_mount_fstype="$4" |
|
mds_mount_options="$5" |
|
mds_mount_enabled="$6" |
|
} |
|
|
|
swap_dev_section_cb() { |
|
sds_swap_device="$2" |
|
return 0 |
|
} |
|
|
|
config_get_automount |
|
automount_from_fstab="$from_fstab" |
|
[ "$automount_from_fstab" -eq 1 ] && { |
|
config_get_mount_section_by_device "/dev/$device" |
|
use_device="$mds_mount_device" |
|
[ "$mds_mount_enabled" -eq 1 ] && { |
|
if [ -n "$mds_mount_target" ]; then |
|
grep -q "/dev/$device" /proc/mounts || { |
|
mkdir -p "$mds_mount_target" |
|
logger -t 'fstab' "Chang permission of mount point ${mds_mount_target}" |
|
chmod 777 "$mds_mount_target" |
|
case "$mds_mount_fstype" in |
|
'ntfs') |
|
env -i /bin/mount -o "$mds_mount_options" /dev/$device "$mds_mount_target" 2>&1 | tee /proc/self/fd/2 | logger -t 'fstab' |
|
;; |
|
*) |
|
env -i /bin/mount -t "$mds_mount_fstype" -o "$mds_mount_options" /dev/$device "$mds_mount_target" 2>&1 | tee /proc/self/fd/2 | logger -t 'fstab';; |
|
esac |
|
} |
|
else |
|
logger -t 'fstab' "Mount enabled for $mds_mount_device but it doesn't have a defined mountpoint (target)" |
|
fi |
|
} |
|
pgrep aria2c >/dev/null 2>&1 || /etc/init.d/aria2 start |
|
pgrep smbd >/dev/null 2>&1 || /etc/init.d/samba start |
|
# hack for 2.5 inch hard drive delay |
|
#[ -n "`which hdparm`" -a -n "hdparm -I /dev/$device | grep 5400" ] && hdparm -B 254 /dev/$device |
|
} |
|
|
|
[ -z "$use_device" ] && { |
|
config_get_autoswap |
|
autoswap_from_fstab="$from_fstab" |
|
|
|
[ "$autoswap_from_fstab" -eq 1 ] && { |
|
config_get_swap_section_by_device "/dev/$device" |
|
use_device="$sds_swap_device" |
|
} |
|
} |
|
|
|
grep -q "/dev/$device" /proc/mounts || { |
|
[ "$anon_mount" -eq 1 -a -z "$use_device" ] && { |
|
case "$device" in |
|
mtdblock*) ;; |
|
*) |
|
[ -z "`blkid | grep "/dev/$device" | awk -F 'TYPE="' '{print $2}' | sed 's/\" //'`" ] && { |
|
logger -t 'fstab' "/dev/$device is a Logic Disk or has not supported filesystem " |
|
return 0 |
|
} |
|
( mkdir -p /mnt/$device && chmod 777 /mnt/$device && mount /dev/$device /mnt/$device ) 2>&1 | tee /proc/self/fd/2 | logger -t 'fstab' |
|
;; |
|
esac |
|
} |
|
} |
|
;; |
|
remove) |
|
umount $mountpoint |
|
rm -rf $mountpoint |
|
;; |
|
esac |
|
|
|
fi |
kmod-nls-utf-8 应该是 kmod-nls-utf8