script.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/sh
  2. obj=pdutar
  3. function is_ipv6()
  4. {
  5. var="$1"
  6. regex='^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$'
  7. if [[ $var =~ $regex ]]; then
  8. return 1
  9. else
  10. return 0
  11. fi
  12. }
  13. function kill_all()
  14. {
  15. killall RestartApp.sh smartMornitor.sh smartMonitor.sh main snmpd Qt_Test smartPDU smartUPG
  16. }
  17. function rm_old()
  18. {
  19. echo rm old files ...
  20. rm -f /etc/init.d/S90PDUStart
  21. rm -rf /usr/local/snmpd
  22. rm -f /usr/lib/libnetsnmp*
  23. rm -f /usr/sbin/smartMornitor.sh
  24. rm -f /usr/libmpr.so /usr/libhttp.so /usr/lib/libesp.o /usr/lib/libmodbus*
  25. }
  26. function set_net()
  27. {
  28. netfile=/etc/network/interfaces
  29. content=$(cat $netfile)
  30. if [[ $content == *"address"* ]]; then
  31. return
  32. fi
  33. ip4=192.168.1.132
  34. mask4=255.255.255.0
  35. gw4=192.168.1.1
  36. str_lo="auto lo\niface lo inet loopback\n\n"
  37. str_e0="auto eth0\niface eth0 inet static\naddress $ip4\nnetmask $mask4\ngateway $gw4\n\n"
  38. str_e1="auto eth1\niface eth1 inet dhcp\npre-up /etc/network/nfs_check\nwait-delay 5\nhostname $(hostname)\n"
  39. echo -e $str_lo > $netfile
  40. echo -e $str_e0 >> $netfile
  41. echo -e $str_e1 >> $netfile
  42. ifconfig eth0 $ip4
  43. }
  44. kill_all
  45. rm_old
  46. shopt -s extglob
  47. echo rm home files except for $obj
  48. rm -rf !("$obj")
  49. shopt -u extglob
  50. echo release $obj ...
  51. tar -xpf $obj -C / >/dev/null 2>&1
  52. rm $obj
  53. set_net
  54. echo +++++++ upgrade ok! +++++++
  55. echo reboot device now ...
  56. reboot