在mount.sh上添加执行检测U盘的程序。mount.sh在U盘插入时执行的脚本,在”add”分之中,添加如下语句:
if [ "$ACTION" = "add" ] && [ -n "$DEVNAME" ]; thenif [ -x "$PMOUNT" ]; then$PMOUNT$DEVNAME2> /dev/null
elif [ -x $MOUNT ]; then$MOUNT$DEVNAME2> /dev/null
fi# If the device isn't mounted at this point, it isn't configured in fstab# 20061107: Small correction: The rootfs partition may be called just "rootfs" and not by# its true device name so this would break. If the rootfs is mounted on two places# during boot, it confuses the heck out of fsck. So Im auto-adding the root-partition# to /etc/udev/mount.blacklist via postinst
cat /proc/mounts | awk '{print $1}' | grep -q "^$DEVNAME$" || automount
sh /home/test/checkUdisk #这里是我加上的语句,检测U盘的程序checkUdisk放在了/home/test/#下,如果更改checkUdisk目录,这个地方也要做相应更改fi
添加的语句sh /home/test/checkUdisk,是执行检测U盘的脚本,在插入U盘后,系统会自动执行到add分支,转而会运行该语句。
编写自动检测U盘的程序
首先确定自己U盘的安装路径,在arm上的U盘默认安装是在/media/sda1/,如果使用多个U盘,或者当前文件夹使用时,会使用sdb1,依次类推,故检测程序应能忽略插入U盘时,不同文件夹的影响,首先就是检测U盘所在的文件夹,本程序中是检测U盘中的执行程序来确定U盘所在目录,相应程序如下:
#/bin/shfor var in"a""b""c""d""e""f""g""h"dofor j in1234do
PATH="/media/sd$var$j/copy.sh” #copy.sh是自动更新脚本,检测其存在,则跳出循环
#echo $PATH
if [ -s $PATH ];then
echo "opendevice ${PATH}"
break;
fi
done
if [ -s $PATH ];then
break;
fi
done
if [ -s $PATH ];then
/bin/sh $PATH #执行copy.sh脚本, /bin/sh使用绝对路径可以确保程序执行
fi
写好后,相应的程序应提取权限:chmod 755 checkUdisk ,checkUdisk是相应的文件名。