#!/bin/bash
# migrate from hybrid channel to normal channel
#
log=/var/log/hybrid-to-normal.log

CL7H_REPO=/etc/yum.repos.d/{cl7h,cl7h_beta}.repo

yum list installed kernel-*el7h* &> /dev/null
kern=$?
yum list installed kmod-lve &> /dev/null
kmodlve=$?

if [ $kern -eq 1 -a $kmodlve -eq 1 ]; then
    echo "CloudLinux 7 Hybrid has been uninstalled already"
    exit 1
fi

if [ -f "$CL7H_REPO" ] ; then
	echo "Remove CloudLinux 7 hybrid repositories..." | tee -a $log
	rm -f "$CL7H_REPO"
	yum clean all 2>&1 | tee -a $log
fi

if [ $kern -eq 0 ]; then
	yum -y downgrade kernel-"$(cat /etc/sysconfig/kernel-version.pre-hybrid)" 2>&1 | tee -a $log
fi

rpm --nodeps -e `rpm -qa kernel* kmod-lve | grep 7h` 2>&1 | tee -a $log

yum list installed kmod-*el7h* &> /dev/null
if [ $? -eq 0 ]; then
	yum -y downgrade kmod
fi
