rk3568_ubuntu_r60_v1.3.2/yocto/meta-quectel-app/recipes/usb-mount/files/automountsdcard.sh

75 lines
2.1 KiB
Bash
Raw Normal View History

2023-11-03 14:12:44 +08:00
#! /bin/sh
arg1=$1
if [ "${arg1:0:6}" == mmcblk ];then
destdir=/mnt/sdcard/
fi
if [ "${arg1:0:2}" == sd ];then
destdir=/mnt/${1}/
fi
umount_partition()
{
if grep -qs "^/dev/$1 " /proc/mounts ; then
umount -lf "${destdir}";
fi
if ! grep -qs "^/dev/$1 " /proc/mounts ; then
rmdir "${destdir}";
fi
}
mount_partition()
{
if [ ! -d "${destdir}" ]; then
mkdir "${destdir}"
if [ ! -d "${destdir}" ]; then
mount -o remount -rw /
mkdir "${destdir}"
fi
fi
if ! mount -t auto "/dev/$1" "${destdir}" -o nodev,noexec,nosuid; then
# failed to mount
exit 1
fi
}
check_if_boot_dev()
{
ret_val=`cat /proc/cmdline | grep "androidboot.bootdevice" |wc -l`
if [ $ret_val -ne 0 ]; then
boot_dev_list=`cat /proc/cmdline | awk '{ for ( n=1; n<=NF; n++ ) if($n ~ "androidboot.bootdevice") print $n }' | awk '{split($0,a, "=");print a[2]}'`
boot_dev=`echo $boot_dev_list | awk '{print $NF}'`
real_sysfs_path=`realpath /sys/class/block/$1`
ret_val=`echo $real_sysfs_path | grep /sys/devices/ | grep $boot_dev | wc -l`
fi
echo $ret_val
}
create_symlink()
{
real_sysfs_path=`realpath /sys/class/block/$1`
partition_name=`cat $real_sysfs_path/uevent | awk '{ for ( n=1; n<=NF; n++ ) if($n ~ "PARTNAME") print $n }' | awk '{split($0,a, "=");print a[2]}'`
mkdir -p /dev/block/bootdevice/by-name/
partition_name=/dev/block/bootdevice/by-name/$partition_name
target_dev=/dev/$1
ln -s $target_dev $partition_name
}
case "${ACTION}" in
add|"")
result=`check_if_boot_dev $1`
if [ $result -eq 1 ]; then
create_symlink $1 &
else
umount_partition ${1}
mount_partition ${1}
fi
;;
remove)
umount_partition ${1}
;;
esac