#!/bin/bash
#===============================================================================
#
#          FILE: generate_NAT_IP_table
#
#         USAGE: generate_NAT_IP_table
#
#   DESCRIPTION: Generate the NAT IP comparison table to the file ~/bin/NAT_IP_table
#
#       OPTIONS: N/A
#
#  REQUIREMENTS:
#
#         NOTES:
#
#          BUGS:  ---
#        AUTHOR: rickz (Rick Zhang), xlrickz@gmail.com
#       COMPANY: X-LEGEND Entertainment Corp.
#       CREATED: Fri Feb 17 12:24:44 KST 2012
#      REVISION: 1.0
#
#          TODO:
#
#===============================================================================

#set -o nounset                              # Treat unset variables as an error
#set -m                                      # Enable job control


source ~/.gamerc

CENTOS_VERSION="$(grep "^CentOS" /etc/issue | awk -F"[. ]" '{print $3}')"

echo "Generating the NAT IP table and write to ~/bin/NAT_IP_table" | colorize green

if [[ -z ${CENTOS_VERSION} ]]; then
        sendscript allall nohostname <<< 'source ~/.gamerc;echo $(ifconfig -a|awk "/inet / {print \$2}"|grep -v 127.0.0.1|awk "{print \$1}") $(wget -q -O- --header="Metadata-Flavor: Google" $URL_TO_GET_NAT_EXT_IP)' | tee ~/bin/NAT_IP_table
else
        sendscript allall nohostname <<< 'source ~/.gamerc;echo $(ifconfig -a|awk -F: "/inet/ {print \$2}"|grep -v 127.0.0.1|awk "{print \$1}") $(wget -q -O- --header="Metadata-Flavor: Google" $URL_TO_GET_NAT_EXT_IP)' | tee ~/bin/NAT_IP_table
fi
