v_update_sys_ip 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/bin/bash
  2. # info: update system ip
  3. # options: [user] [ip_status]
  4. #
  5. # The function scans configured ip in the system and register them with vesta
  6. # internal database. This call is intended for use on vps servers, where ip is
  7. # set by hypervizor.
  8. #----------------------------------------------------------#
  9. # Variable&Function #
  10. #----------------------------------------------------------#
  11. # Argument defenition
  12. user=${1-vesta}
  13. ip_status=${2-shared}
  14. # Importing variables
  15. source $VESTA/conf/vars.conf
  16. source $V_CONF/vesta.conf # include for internal func
  17. source $V_FUNC/shared.func
  18. source $V_FUNC/ip.func
  19. source $V_FUNC/domain.func
  20. #----------------------------------------------------------#
  21. # Verifications #
  22. #----------------------------------------------------------#
  23. # Checking arg number
  24. check_args '0' "$#" '[user] [ip_status]'
  25. # Checking user
  26. if [ ! -z "$1" ]; then
  27. format_validation 'user'
  28. is_user_valid "$user"
  29. fi
  30. # Checking ip_status
  31. if [ ! -z "$2" ]; then
  32. format_validation 'ip_status'
  33. fi
  34. #----------------------------------------------------------#
  35. # Action #
  36. #----------------------------------------------------------#
  37. # Get ip list
  38. ip_list=$(/sbin/ifconfig |grep 'inet addr:'|cut -f 2 -d :|\
  39. cut -f 1 -d ' '| grep -v 127.0.0.1)
  40. # Get vesta registered ip list
  41. vesta_ip_list=$(ls $V_IPS/)
  42. # Defining config paths
  43. conf='/etc/httpd/conf.d/vesta.conf'
  44. nconf='/etc/nginx/conf.d/vesta_ip.conf'
  45. iconf='/etc/sysconfig/network-scripts/ifcfg'
  46. rconf='/etc/httpd/conf.d/rpaf.conf'
  47. # Comparing each ip
  48. for ip in $ip_list; do
  49. check_ip=$(echo $vesta_ip_list|grep -w "$ip")
  50. # Checking ip registered
  51. if [ -z "$check_ip" ]; then
  52. # Parsing additional params
  53. iface=$(/sbin/ifconfig|grep -B1 -w "$ip"|head -n 1|cut -f 1 -d ' ')
  54. interface=$(echo "$iface" | cut -f 1 -d :)
  55. mask=$(/sbin/ifconfig |grep -w "$ip"|awk -F "Mask:" '{print $2}')
  56. # Adding vesta ip
  57. ip_add_vesta
  58. # Adding namehosting support
  59. namehost_ip_support
  60. # Creating startup script
  61. if [ ! -e "$iconf-$iface" ]; then
  62. ip_add_startup
  63. fi
  64. fi
  65. # NOTE: later we'll make revers comparation
  66. done
  67. #----------------------------------------------------------#
  68. # Vesta #
  69. #----------------------------------------------------------#
  70. # Updating user conf
  71. increase_user_value "$user" '$IP_OWNED'
  72. # Adding task to the vesta pipe
  73. if [ "$web_restart" = 'yes' ]; then
  74. restart_schedule 'web'
  75. fi
  76. # Logging
  77. log_event 'system' "$V_EVENT"
  78. exit