script.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/sh
  2. tmpdir=tmp
  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. rm -rf /mnt/UDISK
  26. }
  27. function set_net()
  28. {
  29. netfile=/etc/network/interfaces
  30. content=$(cat $netfile)
  31. if [[ $content == *"address"* ]]; then
  32. return
  33. fi
  34. ip4=192.168.1.132
  35. mask4=255.255.255.0
  36. gw4=192.168.1.1
  37. str_lo="auto lo\niface lo inet loopback\n\n"
  38. str_e0="auto eth0\niface eth0 inet static\naddress $ip4\nnetmask $mask4\ngateway $gw4\n\n"
  39. str_e1="auto eth1\niface eth1 inet dhcp\npre-up /etc/network/nfs_check\nwait-delay 5\nhostname $(hostname)\n"
  40. echo -e $str_lo > $netfile
  41. echo -e $str_e0 >> $netfile
  42. echo -e $str_e1 >> $netfile
  43. ifconfig eth0 $ip4
  44. }
  45. kill_all
  46. cd /mnt/UDISK
  47. rm -rf app web fw
  48. echo release file ...
  49. tar -xpf $tmpdir/pdutar -C / >/dev/null 2>&1
  50. if [ -e $tmpdir/logo.png ]; then
  51. cp -f $tmpdir/logo.png run/app/image/
  52. fi
  53. if [ -e $tmpdir/smartPDU.ini ]; then
  54. cp -f $tmpdir/smartPDU.ini run/app/
  55. cp -f $tmpdir/smartPDU.ini run/app/smartPDU_bak.ini
  56. rm -rf /root/bak/*
  57. fi
  58. rm -rf $tmpdir
  59. echo +++++++ upgrade ok! +++++++
  60. echo reboot device
  61. reboot -d 1
  62. exit 0