rc.modules 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. #!/bin/sh
  2. echo "------run rc.modules file-----"
  3. #export boot_partition=$(fw_printenv -n boot_partition 2>/dev/null)
  4. # if [ x${boot_partition} == xboot ];then
  5. # /sbin/insmod /lib/modules/5.4.61/usb-storage.ko
  6. # /sbin/insmod /lib/modules/5.4.61/sunxi_gpadc.ko
  7. /sbin/insmod /lib/modules/5.4.61/gt9xxnew_ts.ko
  8. echo 0x07090160 0x083F10F7 > /sys/class/sunxi_dump/write
  9. # /sbin/insmod /lib/modules/5.4.61/8723ds.ko
  10. # /sbin/insmod /lib/modules/5.4.61/8189fs.ko
  11. # /sbin/insmod /lib/modules/5.4.61/r8188eu.ko
  12. # /sbin/insmod /lib/modules/5.4.61/8821cu.ko
  13. # sleep 1
  14. # wpa_supplicant -D wext -c /etc/wpa_supplicant.conf -i wlan0 &
  15. # udhcpc -i wlan0
  16. # wpa_supplicant -Dnl80211 -iwlan0 -c /etc/wifi/wpa_supplicant.conf -B
  17. amixer -D hw:audiocodec cset name='Headphone Switch' 1 && \
  18. amixer -D hw:audiocodec cset name='Headphone volume' 25
  19. #ifconfig eth0 192.168.1.132 up
  20. # 读取interfaces文件
  21. INTERFACES_FILE="/etc/network/interfaces"
  22. # 检查文件是否存在
  23. if [ ! -f "$INTERFACES_FILE" ]; then
  24. echo "Error: $INTERFACES_FILE not found."
  25. `ifconfig eth0 192.168.1.132 up`
  26. fi
  27. # else
  28. # ifconfig eth0 up
  29. # sleep 2
  30. # /sbin/udhcpc -n
  31. # if [ $? -eq 1 ]; then
  32. # sleep 1
  33. # interface="eth0"
  34. # ip_address=""
  35. # netmask=""
  36. # gateway=""
  37. # while IFS= read -r line; do
  38. # # 检查行是否以 iface 开始,并包含指定的接口名
  39. # if [[ "$line" == "iface $interface inet static" ]]; then
  40. # # 读取下一行,它应该是 address
  41. # while read -r next_line; do
  42. # # 检查下一行是否以 address 开始
  43. # if echo "$next_line" | grep -q "address" ; then
  44. # # 提取IP地址(从"address "之后开始)
  45. # ip_address=`echo ${next_line} | awk -F ' ' '{print $2}'`
  46. # #echo $ip_address
  47. # #break # 找到IP后退出循环
  48. # elif echo "$next_line" | grep -q "netmask" ;then
  49. # netmask=`echo ${next_line} | awk -F ' ' '{print $2}'`
  50. # elif echo "$next_line" | grep -q "gateway" ;then
  51. # gateway=`echo ${next_line} | awk -F ' ' '{print $2}'`
  52. # else
  53. # break
  54. # #echo "asdas"
  55. # fi
  56. # done
  57. # fi
  58. # done < $INTERFACES_FILE
  59. # echo "$interface" "$ip_address" "$gateway" "$netmask"
  60. # if [[ "$ip_address" == "" ]]; then
  61. # `ifconfig eth0 192.168.1.132 up`
  62. # else
  63. # `ifconfig "$interface" "$ip_address" netmask "$netmask" up`
  64. # `route del default`
  65. # `route add default gw "$gateway"`
  66. # fi
  67. # else
  68. # echo "hello udhcp!!!"
  69. # fi
  70. # fi
  71. interface="eth0"
  72. ip_address=""
  73. netmask=""
  74. gateway=""
  75. auto_flag=""
  76. ip_flag=""
  77. ipv6_addrss=""
  78. ipv6_netmask=""
  79. ipv6_gateway=""
  80. ipv6_autoflag=""
  81. hw_addr=""
  82. #if [[ -f /sys/class/addr_mgt/addr_eth ]];then
  83. # hw_addr=`cat /sys/class/addr_mgt/addr_eth`
  84. #fi
  85. #echo "hw $hw_addr"
  86. #ifconfig $interface hw ether $hw_addr
  87. #ifconfig $interface up
  88. while IFS= read -r line; do
  89. if [[ "$line" == "iface $interface inet static" ]]; then
  90. ip_flag="1"
  91. auto_flag="1"
  92. elif [[ "$line" == "iface $interface inet dhcp" ]];then
  93. ip_flag="2"
  94. auto_flag="2"
  95. elif [[ "$line" == "iface $interface inet6 static" ]];then
  96. ip_flag="3"
  97. ipv6_autoflag="3"
  98. elif [[ "$line" == "iface $interface inet6 dhcp" ]];then
  99. ip_flag="4"
  100. ipv6_autoflag="4"
  101. fi
  102. if [[ "$ip_flag" == "1" ]]; then
  103. if echo "$line" | grep -q "address" ; then
  104. # 提取IP地址(从"address "之后开始)
  105. ip_address=`echo ${line} | awk -F ' ' '{print $2}'`
  106. #echo $ip_address
  107. #break # 找到IP后退出循环
  108. elif echo "$line" | grep -q "netmask" ;then
  109. netmask=`echo ${line} | awk -F ' ' '{print $2}'`
  110. elif echo "$line" | grep -q "gateway" ;then
  111. gateway=`echo ${line} | awk -F ' ' '{print $2}'`
  112. fi
  113. if [[ "$ip_address" != "" && "$netmask" != "" && "$gateway" != "" ]]; then
  114. ip_flag=""
  115. fi
  116. elif [[ "$ip_flag" == "3" ]]; then
  117. if echo "$line" | grep -q "address" ; then
  118. # 提取IP地址(从"address "之后开始)
  119. ipv6_addrss=`echo ${line} | awk -F ' ' '{print $2}'`
  120. #echo $ip_address
  121. #break # 找到IP后退出循环
  122. elif echo "$line" | grep -q "netmask" ;then
  123. ipv6_netmask=`echo ${line} | awk -F ' ' '{print $2}'`
  124. elif echo "$line" | grep -q "gateway" ;then
  125. ipv6_gateway=`echo ${line} | awk -F ' ' '{print $2}'`
  126. fi
  127. if [[ "$ipv6_addrss" != "" && "$ipv6_netmask" != "" && "$ipv6_gateway" != "" ]]; then
  128. ip_flag=""
  129. fi
  130. fi
  131. done < $INTERFACES_FILE
  132. echo $ip_address $netmask $gateway $auto_flag $ip_flag
  133. echo $ipv6_addrss $ipv6_netmask $ipv6_gateway $ipv6_autoflag $ip_flag
  134. if [[ "$auto_flag" == "1" && "$ip_address" != "" && "$netmask" != "" && "$gateway" != "" ]];then
  135. # `ifconfig $interface hw ether $hw_addr`
  136. `ifconfig "$interface" "$ip_address" netmask "$netmask" up`
  137. `route del default`
  138. `route add default gw "$gateway"`
  139. echo "Static"
  140. elif [[ "$auto_flag" == "2" ]];then
  141. echo "get is DHCPC"
  142. /sbin/udhcpc &
  143. sleep 4
  144. # `ifconfig $interface hw ether $hw_addr`
  145. else
  146. echo "Other FAILED"
  147. `ifconfig eth0 192.168.1.132 up`
  148. #`ifconfig $interface hw ether $hw_addr`
  149. echo "" > $INTERFACES_FILE
  150. echo "# interface file auto-generated by buildroot" >> $INTERFACES_FILE
  151. echo "auto lo" >> $INTERFACES_FILE
  152. echo " iface lo inet loopback" >> $INTERFACES_FILE
  153. echo "auto eth0" >> $INTERFACES_FILE
  154. echo "iface eth0 inet static" >> $INTERFACES_FILE
  155. echo " address 192.168.1.132" >> $INTERFACES_FILE
  156. echo " netmask 255.255.255.0" >> $INTERFACES_FILE
  157. echo " gateway 192.168.1.0" >> $INTERFACES_FILE
  158. echo "" >> $INTERFACES_FILE
  159. echo "iface eth0 inet6 static" >> $INTERFACES_FILE
  160. echo " address fe80::132" >> $INTERFACES_FILE
  161. echo " netmask 64" >> $INTERFACES_FILE
  162. echo " gateway fe80::1" >> $INTERFACES_FILE
  163. echo "" >> $INTERFACES_FILE
  164. fi
  165. if [[ "$ipv6_autoflag" == "3" && "$ipv6_addrss" != "" && "$ipv6_netmask" != "" && "$ipv6_gateway" != "" ]];then
  166. `ifconfig "$interface" "$ipv6_addrss/$ipv6_netmask" up`
  167. #`route -A inet6 add default gw $ipv6_gateway dev $interface`
  168. echo "IPV6 static"
  169. elif [[ "$auto_flag" == "4" ]];then
  170. echo "get is DHCPCP"
  171. else
  172. echo "Other FAILED"
  173. #`ifconfig eth0 192.168.1.132 up`
  174. fi
  175. ./opt/led_flash &
  176. ssh-keygen -A
  177. /etc/init.d/sshd start
  178. export QT_BOOT=/usr/lib/arm-qt
  179. export QTDIR=/usr/lib/arm-qt
  180. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/arm-qt/lib
  181. export LD_LIBRARY_PATH=$QTDIR/lib:$QTDIR/plugins/platforms:$LD_LIBRARY_PATH
  182. export QT_PLUGIN_PATH=$QTDIR/plugins
  183. export QT_QPA_GENERIC_PLUGINS=tslib:$TSLIB_TSDEVICE
  184. export QT_QPA_FONTDIR=$QTDIR/lib/fonts
  185. export QT_QPA_PLATFORM_PLUGIN_PATH=$QTDIR/plugins
  186. export QT_QPA_PLATFORM=linuxfb:fb=/dev/fb1
  187. RUNDIR=/mnt/UDISK
  188. APPDIR=$RUNDIR/app
  189. WEBDIR=$RUNDIR/web
  190. SNMPDIR=$APPDIR/snmp
  191. # source /etc/qtenv.sh
  192. export MIBDIRS=$SNMPDIR/mibs
  193. export LD_LIBRARY_PATH=$APPDIR/lib:${LD_LIBRARY_PATH}
  194. start_snmpd()
  195. {
  196. if [[ -f "$SNMPDIR/bin/snmpd" ]];then
  197. $SNMPDIR/bin/snmpd -Cc $SNMPDIR/conf/snmpd.conf -Lo &
  198. chmod 777 /var/agentx/master
  199. fi
  200. }
  201. start_pdu()
  202. {
  203. #run smartPDU
  204. if [[ -f "$APPDIR/smartPDU" ]];then
  205. $APPDIR/smartPDU &
  206. fi
  207. }
  208. led_on()
  209. {
  210. #light led
  211. echo 160 > /sys/class/gpio/export
  212. echo in > /sys/class/gpio/gpio160/direction
  213. echo 161 > /sys/class/gpio/export
  214. echo in > /sys/class/gpio/gpio161/direction
  215. echo 162 > /sys/class/gpio/export
  216. echo in > /sys/class/gpio/gpio162/direction
  217. echo 131 > /sys/class/gpio/export
  218. echo in > /sys/class/gpio/gpio131/direction
  219. echo 136 > /sys/class/gpio/export
  220. echo out > /sys/class/gpio/gpio136/direction
  221. echo 1 > /sys/class/gpio/gpio136/value
  222. }
  223. start_lcd()
  224. {
  225. # light lcd
  226. led_on
  227. # fbinit
  228. if [[ -f "$APPDIR/Qt_Test" ]];then
  229. $APPDIR/Qt_Test -platform linuxfb:fb=/dev/fb1 &
  230. fi
  231. }
  232. app_start()
  233. {
  234. case "$1" in
  235. smartPDU)
  236. start_pdu
  237. ;;
  238. snmpd)
  239. start_snmpd
  240. ;;
  241. Qt_Test)
  242. start_lcd
  243. ;;
  244. all)
  245. start_snmpd
  246. start_pdu
  247. start_lcd
  248. ;;
  249. *)
  250. exit 1
  251. esac
  252. }
  253. app_stop()
  254. {
  255. case "$1" in
  256. smartPDU)
  257. killall $1
  258. ;;
  259. snmpd)
  260. killall $1
  261. ;;
  262. Qt_Test)
  263. killall $1
  264. ;;
  265. all)
  266. killall snmpd smartPDU Qt_Test
  267. ;;
  268. *)
  269. exit 1
  270. esac
  271. }
  272. #app_start all
  273. start_snmpd
  274. sleep 4
  275. start_pdu
  276. sleep 1
  277. start_lcd
  278. if [[ -f "/mnt/UDISK/app/smartMonitor.sh" ]];then
  279. sh /mnt/UDISK/app/smartMonitor.sh &
  280. fi
  281. /usr/sbin/smartUPG &
  282. # sleep 20
  283. # led_on
  284. # fi