#!/bin/bash ######Update 2 By Maosen 20170419######
qemu=$(pwd)
icon="/opt/unetlab/html/images/icons"
include="/opt/unetlab/html/includes"
template="/opt/unetlab/html/templates" 
if [ ${qemu:25:5} == 'esxi-' ]
then
	cp -rf $qemu/ESXi.png $icon/ESXi.png
	rm -rf $qemu/ESXi.png
	cp -rf $qemu/esxi.php $template/esxi.php
	rm -rf $qemu/esxi.php
	if grep -i ESXi $include/init.php > /dev/null
	then
		echo -e "\033[33mSorry!!!\033[0m Maybe you has already import it!"
	else
        sed -i "/Virtual PC/i\\\t\t'esxi'\t\t\t=>\t'VMware ESXi'," $include/init.php
        echo 'options kvm_intel nested=1' >>  /etc/modprobe.d/kvm-intel.conf
        echo 'options kvm ignore_msrs=1' >>  /etc/modprobe.d/kvm-intel.conf
		echo -e "\033[31mGreat!!!\033[0m \"ESXi Device\" import successfully!!!"
	fi
	rm -rf $qemu/esxi.sh
else
	echo -e "\033[31mSorry!!!\033[0m Your folder name is NOT legal, please modify the directory name, then run the script again !!! \n\033[32mFor example: \"esxi-xxxx\"\033[0m"
fi

