Created
August 6, 2016 00:52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# rhel68-to-cent68.sh | |
# This script converts a RHEL 6.8 install into CentOS 6.8 | |
# Copyright (C) 2016 Jun Go | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# Jun Go gojun077@gmail.com | |
# Last Updated 2016-08-04 | |
# This script must be executed as root | |
# USAGE: | |
# ./rhel68-to-cent68.sh [mountpt for CentOS 6.8 iso] | |
# ex: ./rhel68-to-cent68.sh /media | |
# no trailing slash in the path! | |
if [ -z "$1" ]; then | |
echo "You must specify the path to the CentOS 6.8 iso mountpoint" | |
exit 1 | |
fi | |
yum clean all | |
if grep --silent "Red Hat" /etc/redhat-release; then | |
cp /etc/redhat-release /etc/redhat-release.old | |
fi | |
DELETE=(rhnlib | |
redhat-release-server-6Server-6.8.0.5.el6.x86_64 | |
redhat-indexhtml | |
plymouth-0.8.3-27.el6_5.1.x86_64 | |
plymouth-scripts-0.8.3-27.el6_5.1.x86_64 | |
plymouth-core-libs-0.8.3-27.el6_5.1.x86_64 | |
dracut-004-409.el6.noarch | |
dracut-kernel-004-409.el6.noarch | |
) | |
for i in ${DELETE[*]}; do | |
if rpm -q "$i" > /dev/null; then | |
echo -e "### Now deleting $i ###\n" | |
rpm -e --nodeps "$i" | |
fi | |
done | |
# Remove RHEL subscription info | |
subscription-manager clean | |
yum remove -y subscription-manager rhn-client-tools | |
if grep --silent "CentOS-6.8" "$1"/RELEASE-NOTES-en-US.html; then | |
cd "$1"/Packages || exit 1 | |
echo -e "### Force updating packages with rpm -Uvh --force ###" | |
rpm -Uvh --force centos-release-6-8.el6.centos.12.3.x86_64.rpm \ | |
centos-indexhtml-6-2.el6.centos.noarch.rpm \ | |
yum-3.2.29-73.el6.centos.noarch.rpm \ | |
yum-plugin-fastestmirror-1.1.30-37.el6.noarch.rpm | |
# Rename CentOS online .repo files so they won't be used | |
echo -e "### Rename CentOS Repo files ###" | |
find /etc/yum.repos.d/ -type f -name "CentOS*" -exec mv {} {}.old \; | |
# check for local.repo file and create it if it doesn't | |
# exist | |
if [ -f /etc/yum.repos.d/local.repo ]; then | |
echo -e "### Local yum repo file exists ###\n" | |
echo -e "### Changing baseurl for local.repo (to CentOS DVD iso) ###\n" | |
# Check if the existing local.repo uses mountpoint '/media/Server' | |
if grep --silent "/media/Server" /etc/yum.repos.d/local.repo; then | |
# change file path to CentOS path | |
sed -i "s%file:///media/Server%file://$1%g" \ | |
/etc/yum.repos.d/local.repo | |
fi | |
else | |
cat << XYZ > /etc/yum.repos.d/local.repo | |
[CentOS] | |
name=CentOS | |
baseurl=file://\$1 | |
enabled=1 | |
gpgkey=file://\$1/RPM-GPG-KEY-CentOS-6 | |
XYZ | |
fi | |
yum clean all | |
yum update -y | |
yum install -y plymouth-0.8.3-27.el6.centos.1.x86_64.rpm \ | |
plymouth-core-libs-0.8.3-27.el6.centos.1.x86_64.rpm \ | |
plymouth-graphics-libs-0.8.3-27.el6.centos.1.x86_64.rpm \ | |
plymouth-scripts-0.8.3-27.el6.centos.1.x86_64.rpm \ | |
dracut-004-409.el6.noarch.rpm \ | |
dracut-kernel-004-409.el6.noarch.rpm | |
#dracut-fips-004-409.el6.noarch.rpm \ | |
#dracut-network-004-409.el6.noarch.rpm | |
else | |
echo -e "Please mount the proper ISO file\n" 1>&2 | |
exit 1 | |
fi | |
# Edit grub.conf to remove references to RHEL | |
sed -i "s:Red Hat Enterprise Linux 6:CentOS release 6.8:g" /boot/grub/grub.conf | |
# Edit grub.conf to remove references to RHEL errata kernel | |
sed -i "s:Red Hat Enterprise Linux Server:CentOS errata:g" /boot/grub/grub.conf | |
# specify that plymouth boot use VESA framebuffer | |
#sed -i "s:rhgb quiet:rhgb quiet vga=0x317:g" /boot/grub/grub.conf | |
echo -e "### Rebuilding initrd to remove RHEL text ###" | |
# Disable the RHEL text mode boot bar by rebuilding initramd | |
plymouth-set-default-theme -R details |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment