自动挂载U盘
现在Kernel中一般都有udev mdev.在U盘接入后会自动升成节点/dev/sd*[0,9] ,不过在udev配置文件中并没有挂载到目录,仅生成了设备节点. 这时可以自已写个脚本来实现
1 2 3 4 5 6 |
#!/bin/sh if [ ! -f "/dev/sda1" ]; then mount /dev/sda1 /udisk -t vfat fi #按理说修改udev的配置文件才是最好的选择.在这里只挂载了指定设备,并只支持fat32 |
自用的开机检测脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
#!/bin/sh liveFile=liveRtspServer decoderFile=decoder filepath=/root/ updatapath=/udisk/ configFile=/root/config.json # 判断文件是否存在 checkFile(){ if [ -e $1 ]; then echo "$1 ready" return 0 else echo "$1 not ready" return 1 fi } # 判断两个文件是否相同 diffFile(){ diff $1 $2 > /dev/null if [ $? == 0 ]; then echo "Both file are same" return 1 else echo "Both file are different" return 0 fi } # 检测升级文件 audoUpdata(){ # 检测U盘里的升级文件 updataFile="${updatapath}${liveFile}" checkFile $updataFile fileReady1=$? if [ 1 == $fileReady1 ]; then updataFile="${updatapath}${decoderFile}" checkFile $updataFile fileReady1=$? if [ ! 0 == $fileReady1 ]; then # echo "not find updata file exit.." return 0 else localFile="${filepath}${decoderFile}" fi else localFile="${filepath}${liveFile}" fi diffFile $updataFile $localFile if [ 0 == $? ]; then echo "upgrade file..." rm "${filepath}${decoderFile}" rm "${filepath}${liveFile}" cp $updataFile $filepath fi } #读取json变量值 $1 文件名 $2变量名 getJsonval(){ str=$(grep \"$2\" $1) #找到变量所在的行 "xx": "ss:x,s", str=${str#*:} #裁减掉第一个冒号前所有内容 "ss:x,s", str=${str#*\"} #裁减掉第一个双引号前所有内容 ss:x,s", str=${str%,} #如果最后一个逗号,则删除 ss:x,s" str=${str%\"*} #裁减最后一个双引号后所有内容 ss:x,s echo $str } # 检查IP合法 checkip(){ IP=$1 VALID_CHECK=$(echo $IP|awk -F. '$1<=255&&$2<=255&&$3<=255&&$4<=255{print "yes"}') if echo $IP|grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$">/dev/null; then if [ ${VALID_CHECK:-no} == "yes" ]; then return 0 else return 1 fi else return 1 fi } ################# 加载海思驱动MPP文件 ################ export LD_LIBRARY_PATH="/usr/local/lib:/usr/lib:/root/lib" echo ======================= LOAD HISICON MPP ====================== cd /root/ko/ ./load3520dv300 -i cd /root/ ################# 挂载U盘并检查升级文件 ################ echo ======================= CHECK U DISK ====================== if [ -e "/dev/sda1" ]; then mount /dev/sda1 /udisk -t vfat audoUpdata fi ################# 检查IP MAC等配置 ################### echo ======================= CHECK IP CONFIG ====================== dhcp=$(getJsonval $configFile ipmode) if [ "true" == $dhcp ];then echo config eth0 to dhcp mode!! udhcpc -i eth0 else ip=$(getJsonval $configFile ip) mac=$(getJsonval $configFile mac) gateway=$(getJsonval $configFile gateway) checkip $ip if [ 1 == $? ];then echo IP address error! reset to 192.168.10.168 ip="192.168.10.168" fi checkip $gateway if [ 1 == $? ];then echo gateway address error! reset to 192.168.10.1 gateway="192.168.10.1" fi macok=$(echo $mac | grep "[A-Fa-f0-9][A-Fa-f0-9]:[A-Fa-f0-9][A-Fa-f0-9]:[A-Fa-f0-9][A-Fa-f0-9]:[A-Fa-f0-9][A-Fa-f0-9]:[A-Fa-f0-9][A-Fa-f0-9]:[A-Fa-f0-9][A-Fa-f0-9]") if [ ! $macok ]; then echo mac error! set to default! mac="52:54:00:69:ac:fd" fi echo configure eth0 ... ifconfig eth0 hw ether ${mac}; ifconfig eth0 $ip netmask 255.255.255.0; route add default gw $gateway fi telnetd & ################# 启动程序 ################### echo ======================= START APP ====================== checkFile ${filepath}${decoderFile} if [ 0 == $? ]; then nohup ${filepath}${decoderFile} >/dev/null & else nohup ${filepath}${liveFile} >/dev/null & fi echo ======================= DONE ====================== |