#!/bin/sh
major=$(cat /etc/centos-release | tr -dc '0-9.'|cut -d \. -f1)
inf=$(cat /etc/yum.repos.d/jormrepo.repo)
inf2=$(cat /etc/yum.repos.d/epel.repo)
if [[ $major == '7' ]]; then
	if [[ $inf2 == '' ]]; then
		echo "Install EPEL 7 repo"
		rpm -ihv https://cdn.ninja/repo/centos7/noarch/epel-release-7-15.2.noarch.rpm
	else
		echo "Epel 7 already installed. Skipped."
	fi
	if [[ $inf == '' ]]; then
		echo "Installing Jormungand Repo"
		rpm -ihv https://cdn.ninja/repo/centos7/noarch/jorm-release-7.0-0.el7.noarch.rpm
		echo "Complete"
		rm -f install.sh
	else 
		echo "don't need any actions"
	fi
elif [[ $major == '6' ]]; then
	if [[ $inf2 == '' ]]; then
		echo "Install EPEL repo"
		rpm -ihv http://mirror.yandex.ru/epel/6/x86_64/epel-release-6-8.noarch.rpm
	else
		echo "Epel already installed. Skipped."
	fi
	if [[ $inf == '' ]]; then
		echo "Installing Jormungand Repo"
		echo '[jormungandrepo]
name=Jormungand Release - $basearch
baseurl=http://cdn.ninja/repo/centos6/$basearch/
enabled=1
gpgcheck=0' > /etc/yum.repos.d/jormrepo.repo
		echo "Complete"
		rm -f install.sh
	else 
		echo "don't need any actions"
	fi
else 
	echo "Unknown OS. $major"
fi