script.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. ip4=`ip addr show dev eth0 | sed -e's/^.*inet \([^ ]*\)\/.*$/\1/;t;d'`
  29. ip6=`ip addr show dev eth0 | sed -e's/^.*inet6 \([^ ]*\)\/.*$/\1/;t;d'`
  30. str_lo="auto lo\niface lo inet loopback\n\n"
  31. str_e0="auto eth0\niface eth0 inet static\naddress $ip4\nnetmask 255.255.255.0\ngateway 192.168.1.1\n\n"
  32. if [ "$ip6" = "" ]; then
  33. echo ___$ip6
  34. fi
  35. str_e1="auto eth1\niface eth1 inet dhcp\npre-up /etc/network/nfs_check\nwait-delay 5\nhostname $(hostname)\n"
  36. netfile=/etc/network/interfaces
  37. echo -e $str_lo > $netfile
  38. echo -e $str_e0 >> $netfile
  39. echo -e $str_e1 >> $netfile
  40. }
  41. kill_all
  42. rm_old
  43. shopt -s extglob
  44. echo rm home files except for $obj
  45. rm -rf !("$obj")
  46. shopt -u extglob
  47. echo release $obj ...
  48. tar -xpf $obj -C / >/dev/null 2>&1
  49. rm $obj
  50. #set_net
  51. echo +++++++ upgrade ok! +++++++
  52. echo reboot device now ...
  53. reboot