v_add_sys_ip 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/bash
  2. # info: add system ip address
  3. # options: ip mask [interface] [user] [ip_status] [ip_name]
  4. #
  5. # The function adds ip address into a system. It also creates rc scripts. You
  6. # can specify ip name which will be used as root domain for temporary aliases.
  7. # For example, if you set a1.myhosting.com as name, each new domain created on
  8. # this ip will automaticaly receive alias $domain.a1.myhosting.com. Of course
  9. # you must have wildcard record *.a1.myhosting.com pointed to ip. This feature
  10. # is very handy when customer wants to test domain before dns migration.
  11. #----------------------------------------------------------#
  12. # Variable&Function #
  13. #----------------------------------------------------------#
  14. # Argument defenition
  15. ip=$1
  16. mask=$2
  17. interface="${3-eth0}"
  18. user="${4-vesta}"
  19. ip_status="${5-shared}"
  20. ip_name=$6
  21. # Importing variables
  22. source $VESTA/conf/vars.conf
  23. source $V_CONF/vesta.conf
  24. source $V_FUNC/shared.func
  25. source $V_FUNC/ip.func
  26. source $V_FUNC/domain.func # for namehosting
  27. #----------------------------------------------------------#
  28. # Verifications #
  29. #----------------------------------------------------------#
  30. # Checking arg number
  31. check_args '2' "$#" 'ip mask [interface] [user] [ip_status] [ip_name]'
  32. # Checking argument format
  33. format_validation 'ip' 'mask' 'interface' 'user'
  34. # Checking system ip
  35. is_sys_ip_free
  36. # Checking user
  37. is_user_valid "$user"
  38. # Checking ip_status
  39. if [ ! -z "$ip_status" ]; then
  40. format_validation 'ip_status'
  41. fi
  42. # Checking ip_name
  43. if [ ! -z "$ip_name" ] ; then
  44. format_validation 'ip_name'
  45. fi
  46. #----------------------------------------------------------#
  47. # Action #
  48. #----------------------------------------------------------#
  49. # Get interface number
  50. i_number=$(get_next_interface_number)
  51. iface="$interface$i_number"
  52. # Defining config paths
  53. conf='/etc/httpd/conf.d/vesta.conf'
  54. nconf='/etc/nginx/conf.d/vesta_ip.conf'
  55. iconf='/etc/sysconfig/network-scripts/ifcfg'
  56. rconf='/etc/httpd/conf.d/rpaf.conf'
  57. # Adding ip
  58. /sbin/ifconfig "$iface" "$ip" netmask "$mask"
  59. # Adding startup script
  60. ip_add_startup
  61. # Adding vesta ip
  62. ip_add_vesta
  63. # Importing main config
  64. source $V_CONF/vesta.conf
  65. # Adding namehosting support
  66. namehost_ip_support
  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