#!/bin/bash
check=$(grep -c 'digipower.vn' /etc/yum.repos.d/CentOS-Base.repo)
if [ $check = "0" ]; then
	echo ""
	echo "Would you like to add our Yum Repository (CentOS) into your Server ?"
	echo "(Note : we only add to your Centos-Base,not effect to your another repo on Server )"
	echo ""
	echo ""
	read -p "Please confirm your choice ? (Y or N)" choice
	if [ $choice = "Y" ] || [ $choice = "YES" ] || [ $choice = "y" ] || [ $choice = "yes" ]; then
		echo; echo -n 'Checking your OS Platform .....'
		os=$(cat /etc/redhat-release | awk '{print $3}' | cut -c 1)
		if [ $os = 5 ]; then
		echo; echo -n 'Import Repository....'
		wget -q -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.digipower.vn/CentOS-Base-5.repo
		yum clean all
		echo -n '.'
		elif [ $os = 4 ]; then
		wget -q -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.digipower.vn/CentOS-Base-4.repo
		yum clean all
		echo -n '.'
		elif [ $os = r ]; then
			os2=$(cat /etc/redhat-release | awk '{print $4}' | cut -c 1)
			if [ $os2 = 6 ]; then
                	wget -q -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.digipower.vn/CentOS-Base-6.repo
                	yum clean all
                	echo -n '.'
			else
				:
			fi
		fi
		echo ""
		echo "New Repo is added into Your Server . Please run this before update any package you want"
		echo "yum clean all"
		echo ""
		echo "Install....done"
	else
		echo "We are very honored when you cared about Our Repository . Hope you'll use it in future . Thank You"
	fi
else
	echo ""
	echo "You've installed Our Yum Repository . Would you like to uninstall(Y) or going on to use it(N) ?"
	echo ""
	echo ""
	read -p "Please confirm your choice ? (Y or N)" choice2
	if [ $choice2 = "Y" ] || [ $choice2 = "YES" ] || [ $choice2 = "y" ] || [ $choice2 = "yes" ]; then
                echo; echo -n 'Checking your OS Platform .........'
                os=$(cat /etc/redhat-release | awk '{print $3}' | cut -c 1)
                if [ $os = 5 ]; then
		echo; echo -n 'Remove Repository....'
		wget -q -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.digipower.vn/CentOS-Base-org-5.repo
		yum clean all
		echo -n '.'
		elif [ $os = 4 ]; then
		wget -q -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.digipower.vn/CentOS-Base-org-4.repo
		yum clean all
		echo -n '.'
                elif [ $os = r ]; then
                        os2=$(cat /etc/redhat-release | awk '{print $4}' | cut -c 1)
                        if [ $os2 = 6 ]; then
                        wget -q -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.digipower.vn/CentOS-Base-org-6.repo
                        yum clean all
                        echo -n '.'
                        else    
                                :
                        fi

                echo -n '.'
		fi
		echo "Our Repository has been removed on your Server and return to Default Centos Yum Repository"
		echo ""
		echo "Uninstall....done"
	else
		echo "Thank you for continued use"
	fi
fi

