RHEL 6.9 to CentOS 6.9 Script
Sometimes, it’s a bit of a pain to work with RedHat Enterprise Linux. I’ve been developing a solution with a co-worker that will allow you to convert a RHEL 6.9 box to a CentOS 6.9 box. So here you have it. The script that converts RHEL 6.9 to Cent 6.9:
#!/bin/bash # Make sure this script is running as root if [ "$EUID" != "0" ]; then printf "\n\033[1;91mYou must run this as root!\033[0m\n\n" exit 1 fi printf "\n\n\033[1;96mPrepping environment\033[0m" yum clean all > /dev/null 2>&1 yum clean metadata > /dev/null 2>&1 printf "\n\033[1;96mCreating temp directory\033[0m" mkdir ~/centos > /dev/null 2>&1 cd ~/centos # Grab the CentOS 6 RPM Signing key - not totally catastrophic if it fails printf "\n\033[1;96mRetrieving RPM GPG Key for CentOS 6... \033[0m" wget http://mirror.centos.org/centos/6.9/os/x86_64/RPM-GPG-KEY-CentOS-6 > /dev/null 2>&1 if [[ ! $? -eq 0 ]]; then printf "\033[1;91mFAILED!\033[0m" else printf "\033[1;92mSUCCESS!\033[0m" fi # Grab the CentOS 6 update packages printf "\n\033[1;96mRetrieving 'centos-release'... \033[0m" wget http://mirror.centos.org/centos/6.9/os/x86_64/Packages/centos-release-6-9.el6.12.3.x86_64.rpm > /dev/null 2>&1 if [[ ! $? -eq 0 ]]; then printf "\033[1;91mFAILED!\033[0m" echo "Cannot continue without this package... exiting." else printf "\033[1;92mSUCCESS!\033[0m" fi printf "\n\033[1;96mRetrieving 'yum'... \033[0m" wget http://mirror.centos.org/centos/6.9/os/x86_64/Packages/yum-3.2.29-81.el6.centos.noarch.rpm > /dev/null 2>&1 if [[ ! $? -eq 0 ]]; then printf "\033[1;91mFAILED!\033[0m" echo "Cannot continue without this package... exiting." else printf "\033[1;92mSUCCESS!\033[0m" fi printf "\n\033[1;96mRetrieving 'yum-utils'... \033[0m" wget http://mirror.centos.org/centos/6.9/os/x86_64/Packages/yum-utils-1.1.30-40.el6.noarch.rpm > /dev/null 2>&1 if [[ ! $? -eq 0 ]]; then printf "\033[1;91mFAILED!\033[0m" echo "Cannot continue without this package... exiting." else printf "\033[1;92mSUCCESS!\033[0m" fi printf "\n\033[1;96mRetrieving 'yum-plugin-fastestmirror'... \033[0m" wget http://mirror.centos.org/centos/6.9/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-40.el6.noarch.rpm > /dev/null 2>&1 if [[ ! $? -eq 0 ]]; then printf "\033[1;91mFAILED!\033[0m" echo "Cannot continue without this package... exiting." else printf "\033[1;92mSUCCESS!\033[0m" fi # Not catastrophic to the process if it fails printf "\n\033[1;96mImporting RPM GPG Key for CentOS 6.x... \033[0m" rpm --import RPM-GPG-KEY-CentOS-6 > /dev/null 2>&1 if [[ ! $? -eq 0 ]]; then printf "\033[1;91mFAILED!\033[0m" else printf "\033[1;92mSUCCESS!\033[0m" fi printf "\n\033[1;96mRemoving RHEL packages: rhnlib abrt-plugin-bugzilla redhat-release-notes* ... \033[0m" yum -y remove rhnlib abrt-plugin-bugzilla redhat-release-notes* > /dev/null 2>&1 if [[ ! $? -eq 0 ]]; then printf "\033[1;91mFAILED!\033[0m" else printf "\033[1;92mSUCCESS!\033[0m" fi printf "\n\033[1;96mErasing additional packages: redhat-release-server-6Server redhat-indexhtml ... \033[0m" rpm -e --nodeps redhat-release-server-6Server redhat-indexhtml > /dev/null 2>&1 if [[ ! $? -eq 0 ]]; then printf "\033[1;91mFAILED!\033[0m" else printf "\033[1;92mSUCCESS!\033[0m" fi printf "\n\033[1;96mErasing RHN packages: yum-rhn-plugin rhn-check rhnsd rhn-setup rhn-setup-gnome ... \033[0m" rpm -e yum-rhn-plugin rhn-check rhnsd rhn-setup rhn-setup-gnome > /dev/null 2>&1 if [[ ! $? -eq 0 ]]; then printf "\033[1;91mFAILED!\033[0m (It's ok - will still work)" else printf "\033[1;92mSUCCESS!\033[0m" fi printf "\n\033[1;96mPrepping 'subscription-manager' ... \033[0m" subscription-manager clean > /dev/null 2>&1 if [[ ! $? -eq 0 ]]; then printf "\033[1;91mFAILED!\033[0m" else printf "\033[1;92mSUCCESS!\033[0m" fi printf "\n\033[1;96mRemoving package: subscription-manager ... \033[0m" yum remove -y subscription-manager > /dev/null 2>&1 if [[ ! $? -eq 0 ]]; then printf "\033[1;91mFAILED!\033[0m" else printf "\033[1;92mSUCCESS!\033[0m" fi printf "\n\033[1;96mInstalling the CentOS packages... \033[0m" rpm -Uhv --force *.rpm > /dev/null 2>&1 if [[ ! $? -eq 0 ]]; then printf "\033[1;91mFAILED!\033[0m" else printf "\033[1;92mSUCCESS!\033[0m" fi printf "\n\033[1;96mPrepping system for CentOS... " yum clean all > /dev/null 2>&1 yum clean metadata > /dev/null 2>&1 printf "\033[1;92mDONE!\033[0m" printf "\n\033[1;96mUpgrading to CentOS 6.9 (May take awhile)... \033[0m" yum -y upgrade