#!/bin/sh
shell=info.sh
link=http://220.231.201.236/data/shell/info.sh
hii=/usr/local/src/hii
soft=/usr/local/src/hii/soft

if [ ! -d $soft ];then
mkdir -p $soft
fi
cd $hii
rm -rf $shell
wget $link

####

route=`/usr/sbin/route -n |grep UG |awk '{print $2}' |awk -F "." '{print $1"."$2}'`
IP=`ip a |grep $route |awk '{print $2}' |awk -F "/" '{print $1}'`
sh $hii/$shell  > $IP.txt 

install_sendemail () {
cd /usr/local/src
wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
tar zxvf sendEmail-v1.56.tar.gz 
cp /usr/local/src/sendEmail-v1.56/sendEmail /usr/sbin/
chmod +x /usr/sbin/sendEmail
}
if [ "$UID" -ne "0" ] ; then
echo -e "\n-------------------------------------------------------------------------"
echo -e "\nInstalling as "root"        "
echo -e "\a\nYou must be "root" to install"
echo -e "\n-------------------------------------------------------------------------"
exit
else
echo -e "\n-------------------------------------------------------------------------"
echo -e "\nInstalling as "root"        "
echo -e "\n-------------------------------------------------------------------------"
fi
if [ ! -e /usr/sbin/sendEmail ];then
echo -e "\n-------------------------------------------------------------------------"
echo -e "\a\n start install sendemail"
install_sendemail
echo -e "\n-------------------------------------------------------------------------"
else
echo -e "\n-------------------------------------------------------------------------"
echo -e "\a\n check sendemail Installed Start Next"
echo -e "\n-------------------------------------------------------------------------"
fi


send_mail () {
#-f indicates from, the sender's address
#-t indicates to, the recipient's address If you need to send multiple use "," separated
#-s mail server domain name
#-u theme
#-xu username (before @)
#-xp user password
#-m plain text messages
#-o message-file = / root / .. send the file contents
#-a send attachments (-m,-o,-a can be used simultaneously)
hostname=`uname -a |awk '{print $2}'`
sendEmail="/usr/sbin/sendEmail"
sender=hii-notice@chinac.com
recipient=liujie@chinac.com
smtp=smtp.chinac.com
cipher=PxQ3GS5!PxQ3GS5!
subject=$IP host-info
$sendEmail -u "$subject" -t $recipient -f $sender -m "$IP.txt" -a $IP.txt -s $smtp -xu  $sender -xp $cipher
}
send_mail


