#!/bin/bash

root_path=`cat /var/log/version_control`

cd $root_path

$prog_type
name=`cat command_control | grep script_server: | awk '{print $2}'`
if [ "$name" = "yunsuo" ];then
	prog_type="normal"
elif [ "$name" = "jhse" ];then
	prog_type="jhse"
elif [ "$name" = "anyu" ];then
	prog_type="anyu"
elif [ "$name" = "wsssr" ];then
	prog_type="wsssr"	
else
	prog_type="gov"
fi

function confirm_uninstall()
{
	while true
	do
		echo -n "Are you sure to uninstall?(y/n)"
		read confirm

		if [ ! -z "$confirm" ];then
			break
		fi
	done

	if [ "$confirm" != "y" ] && [ "$confirm" != "Y" ];then
		echo "Exit Uninstall program!"
		exit
	fi
}

confirm_uninstall

if [ -f $root_path/ubuntu ];then
	os_type=ubuntu
elif [ -f $root_path/suse ];then
	os_type=suse
else
	os_type=centos
fi


export LANG="C"
export JHSE_SAFE_PATH=$root_path

# 解除绑定
${root_path}/register_cloud_center unbind

# 卸载云锁
# 生成configure_file文件, 该文件内容为具体的配置信息
echo "2:$prog_type:x64:$root_path:$os_type" > configure_file
./setup_configure -c setup.xml -l runlog/setup.log -e "ALL" -t "ALL" -s safe -m cmdline 2>/dev/null

rm -rf /usr/local/lib/jlib64
rm -rf /usr/local/lib/jlibs
rm -rf $root_path

echo ""
echo "Uninstall Success."
