script_retain.sh 1.8 KB

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