v-update-sys-ip 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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-admin}
  13. ip_status=${2-shared}
  14. # Includes
  15. source $VESTA/conf/vesta.conf
  16. source $VESTA/func/main.sh
  17. #----------------------------------------------------------#
  18. # Verifications #
  19. #----------------------------------------------------------#
  20. check_args '0' "$#" '[USER] [IP_STATUS]'
  21. validate_format 'user' 'ip_status'
  22. is_object_valid 'user' 'USER' "$user" "$user"
  23. #----------------------------------------------------------#
  24. # Action #
  25. #----------------------------------------------------------#
  26. ip_list=$(/sbin/ifconfig | grep 'inet addr:' | cut -f 2 -d : | \
  27. cut -f 1 -d ' '| grep -v 127.0.0.1)
  28. for ip in $ip_list; do
  29. if [ ! -e "$VESTA/data/ips/$ip" ]; then
  30. iface=$(/sbin/ifconfig |grep -B1 -w $ip |head -n1 |cut -f1 -d ' ')
  31. interface=$(echo "$iface" | cut -f 1 -d :)
  32. mask=$(/sbin/ifconfig |grep -w $ip |awk -F "Mask:" '{print $2}')
  33. $BIN/v-add-sys-ip $ip $mask $interface
  34. fi
  35. # TBD: revers comparation
  36. done
  37. #----------------------------------------------------------#
  38. # Vesta #
  39. #----------------------------------------------------------#
  40. exit