script.sh 1.6 KB

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