#!/usr/bin/bash

check_previous_step() {
    if [ "$?" -ne 0 ]; then
        echo "Something went wrong. Please check migration_log file"
        exit 1
    fi
}

if [ ! -f "/etc/redhat-release" ]; then
    echo "This server is not RHEL"
    exit
fi

yum clean all &>> migration_log

echo "Removing rhnlib, abrt-plugin-bugzilla, redhat-release-notes*... "
yum remove -y rhnlib abrt-plugin-bugzilla redhat-release-notes* &>> migration_log
check_previous_step

echo "Removing redhat-release-serever, redhat-release-server-6Server... "
yum -e --nodeps redhat-release-serever redhat-release-server-6Server &>> migration_log
check_previous_step

echo "Cleaning RHEL subscription..."
subscription-manager clean &>> migration_log
check_previous_step

echo "Removing subscription-manager... "
yum remove -y subscription-manager &>> migration_log
check_previous_step

echo "Install centos-release-6 package"
wget https://repo.cloudlinux.com/centos/6/os/x86_64/Packages/centos-release-6-10.el6.centos.12.3.x86_64.rpm
yum localinstall -y centos-release-6-10.el6.centos.12.3.x86_64.rpm
check_previous_step

yum clean all &>> migration_log

echo "To finish the migration please do \"yum update\""

