v_upd_sys_ip 2.6 KB

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