rc.modules 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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 "" >> $INTERFACES_FILE
  160. echo "" >> $INTERFACES_FILE
  161. fi
  162. if [[ "$ipv6_autoflag" == "3" && "$ipv6_addrss" != "" && "$ipv6_netmask" != "" && "$ipv6_gateway" != "" ]];then
  163. `ifconfig "$interface" "$ipv6_addrss/$ipv6_netmask" up`
  164. #`route -A inet6 add default gw $ipv6_gateway dev $interface`
  165. echo "IPV6 static"
  166. elif [[ "$auto_flag" == "4" ]];then
  167. echo "get is DHCPCP"
  168. else
  169. echo "Other FAILED"
  170. #`ifconfig eth0 192.168.1.132 up`
  171. fi
  172. ./opt/led_flash &
  173. ssh-keygen -A
  174. /etc/init.d/sshd start
  175. export QT_BOOT=/usr/lib/arm-qt
  176. export QTDIR=/usr/lib/arm-qt
  177. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/arm-qt/lib
  178. export LD_LIBRARY_PATH=$QTDIR/lib:$QTDIR/plugins/platforms:$LD_LIBRARY_PATH
  179. export QT_PLUGIN_PATH=$QTDIR/plugins
  180. export QT_QPA_GENERIC_PLUGINS=tslib:$TSLIB_TSDEVICE
  181. export QT_QPA_FONTDIR=$QTDIR/lib/fonts
  182. export QT_QPA_PLATFORM_PLUGIN_PATH=$QTDIR/plugins
  183. export QT_QPA_PLATFORM=linuxfb:fb=/dev/fb1
  184. RUNDIR=/mnt/UDISK
  185. APPDIR=$RUNDIR/app
  186. WEBDIR=$RUNDIR/web
  187. SNMPDIR=$APPDIR/snmp
  188. # source /etc/qtenv.sh
  189. export MIBDIRS=$SNMPDIR/mibs
  190. export LD_LIBRARY_PATH=$APPDIR/lib:${LD_LIBRARY_PATH}
  191. start_snmpd()
  192. {
  193. if [[ -f "$SNMPDIR/bin/snmpd" ]];then
  194. $SNMPDIR/bin/snmpd -Cc $SNMPDIR/conf/snmpd.conf -Lo &
  195. chmod 777 /var/agentx/master
  196. fi
  197. }
  198. start_pdu()
  199. {
  200. #run smartPDU
  201. if [[ -f "$APPDIR/smartPDU" ]];then
  202. $APPDIR/smartPDU &
  203. fi
  204. }
  205. led_on()
  206. {
  207. #light led
  208. echo 160 > /sys/class/gpio/export
  209. echo in > /sys/class/gpio/gpio160/direction
  210. echo 161 > /sys/class/gpio/export
  211. echo in > /sys/class/gpio/gpio161/direction
  212. echo 162 > /sys/class/gpio/export
  213. echo in > /sys/class/gpio/gpio162/direction
  214. echo 131 > /sys/class/gpio/export
  215. echo in > /sys/class/gpio/gpio131/direction
  216. echo 136 > /sys/class/gpio/export
  217. echo out > /sys/class/gpio/gpio136/direction
  218. echo 1 > /sys/class/gpio/gpio136/value
  219. }
  220. start_lcd()
  221. {
  222. # light lcd
  223. led_on
  224. # fbinit
  225. if [[ -f "$APPDIR/Qt_Test" ]];then
  226. $APPDIR/Qt_Test -platform linuxfb:fb=/dev/fb1 &
  227. fi
  228. }
  229. app_start()
  230. {
  231. case "$1" in
  232. smartPDU)
  233. start_pdu
  234. ;;
  235. snmpd)
  236. start_snmpd
  237. ;;
  238. Qt_Test)
  239. start_lcd
  240. ;;
  241. all)
  242. start_snmpd
  243. start_pdu
  244. start_lcd
  245. ;;
  246. *)
  247. exit 1
  248. esac
  249. }
  250. app_stop()
  251. {
  252. case "$1" in
  253. smartPDU)
  254. killall $1
  255. ;;
  256. snmpd)
  257. killall $1
  258. ;;
  259. Qt_Test)
  260. killall $1
  261. ;;
  262. all)
  263. killall snmpd smartPDU Qt_Test
  264. ;;
  265. *)
  266. exit 1
  267. esac
  268. }
  269. #app_start all
  270. start_snmpd
  271. sleep 4
  272. start_pdu
  273. sleep 1
  274. start_lcd
  275. if [[ -f "/mnt/UDISK/app/smartMonitor.sh" ]];then
  276. sh /mnt/UDISK/app/smartMonitor.sh &
  277. fi
  278. # sleep 20
  279. # led_on
  280. # fi