This repository was archived by the owner on Dec 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprep-rhel-centos.sh
More file actions
166 lines (138 loc) · 6.22 KB
/
prep-rhel-centos.sh
File metadata and controls
166 lines (138 loc) · 6.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
# Multi-Cloud Linux Prep Script
# For
# Redhat 7.x and CentOS 7.x
#
# Written by Justin Paul (@recklessop)
# https://jpaul.me
#
# Note that this script was designed on a new RHEL 7.x system. Inspect it before running it on a production system.
# Legal Disclaimer
# This script is an example script and is not supported under any Zerto support program or service. The author and Zerto
# further disclaim all implied warranties including, without limitation, any implied warranties of merchantability or of fitness
# for a particular purpose.
# In no event shall Zerto, its authors or anyone else involved in the creation, production or delivery of the scripts be liable
# for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of
# business information, or other pecuniary loss) arising out of the use of or the inability to use the sample scripts or
# documentation, even if the author or Zerto has been advised of the possibility of such damages. The entire risk arising out of
# the use or performance of the sample scripts and documentation remains with you.
# Let's first add some color
red=`tput setaf 1`
green=`tput setaf 2`
yellow=`tput setaf 3`
reset=`tput sgr0`
# Define a few functions
get_script_dir () {
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$( readlink "$SOURCE" )"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
$( cd -P "$( dirname "$SOURCE" )" )
pwd
}
# Start the actual script
echo "${green}Phase 1 - Verify OS Flavor and Verify RedHat Subscription${reset}"
ostype=0
if [ $(hostnamectl | grep -cE "Red Hat") -eq 1 ]
then
ostype=1
echo "${yellow}OS Type appears to be Red Hat${reset}"
elif [ $(hostnamectl | grep -cE 'CentOS') -eq 1 ]
then
ostype=2
echo "${yellow}OS Type appears to be CentOS${reset}"
else
echo "${red}OS type doesn't appear to be RedHat or CentOS, exiting...${reset}"
exit 1
fi
if [ $ostype -eq 1 ]
then
echo "${yellow}Checking to see if system is subscribed to RHEL repos${reset}"
if [ $(subscription-manager status | grep -c 'Current') -eq 0 ]
then
echo "${red}No valid subscription found, please register the system so we can get packages, exiting...${reset}"
fi
echo "${yellow}System appears to be under current Subscription${reset}"
fi
echo "${green}Phase 2 - Enable extra Package Repos${reset}"
if [ $ostype -eq 1 ]
then # enable repos for RHEL
echo "${yellow}Enabling RHEL Optional and Extra RPM repos...${reset}"
subscription-manager repos --enable "rhel-*-optional-rpms" --enable "rhel-*-extras-rpms"
#rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
echo "${yellow}Installing EPEL repo...${reset}"
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm -y
#rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
else
# enable repos for CentOS
echo "${yellow}Installing EPEL repo for CentOS...${reset}"
yum install epel-release -y
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
fi
echo "${yellow}Adding Ngompa's Netplan epel repo...${reset}"
curl -o netplan.repo https://copr.fedorainfracloud.org/coprs/ngompa/Netplan/repo/epel-7/ngompa-Netplan-epel-7.repo
mv netplan.repo /etc/yum.repos.d/
#cat > /etc/yum.repos.d/netplan.repo <<EOF
#[ngompa-Netplan]
#name=Copr repo for Netplan owned by ngompa
#baseurl=https://copr-be.cloud.fedoraproject.org/results/ngompa/Netplan/epel-7-\$basearch/
#type=rpm-md
#skip_if_unavailable=True
#gpgcheck=1
#gpgkey=https://copr-be.cloud.fedoraproject.org/results/ngompa/Netplan/pubkey.gpg
#repo_gpgcheck=0
#enabled=1
#enabled_metadata=1cd
#EOF
echo "${green}Phase 3 - Install Required Packages${reset}"
echo "${yellow}Installing dependencies${reset}"
yum install python34 python34-PyYAML git -y
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
echo "${yellow}Installing Netplan and systemd-networkd and systemd-resolved${reset}"
yum install netplan systemd-networkd systemd-resolved -y
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
echo "${green}Phase 4 - Get example netplan yaml files${reset}"
cd $(get_script_dir)
git clone https://github.com/recklessop/netplancfg.git $PWD/netplancfg
rm $PWD/netplancfg/ubuntu/50-vmware-static.yaml
cp $PWD/netplancfg/ubuntu/*.yaml /etc/netplan/
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
echo "${green}Phase 5 - Enable Systemd services${reset}"
systemctl enable systemd-networkd
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
systemctl enable systemd-resolved
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
systemctl start systemd-networkd
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
systemctl start systemd-resolved
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
echo "${green}Phase 6 - Remove NetworkManager and replace resolv.conf${reset}"
echo "${yellow}Removing NetworkManager...${reset}"
yum erase NetworkManager -y
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
echo "${yellow}Symlinking /etc/resolv.conf to /run/systemd/resolv/resolv.conf"
echo "(which is configured from your Netplan YAML files)...${reset}"
rm /etc/resolv.conf
cd /etc
ln -s /run/systemd/resolve/resolv.conf
echo "${green}Phase 7 - Add Drivers to dracut and rebuild initramfs${reset}"
echo "${yellow}Adding drivers to dracut configuration file...${reset}"
cat >> /etc/dracut.conf <<EOF
add_drivers+=" hv_vmbus hv_netvsc hv_storvsc nvme ena xen_blkfront xen_netfront mptbase mptscsih mptspi "
EOF
echo "${yellow}Rebuilding Dracut${reset}"
dracut -f -v
echo "${green}Phase 9 - Update Grub options and rebuild Grub${reset}"
echo "${yellow}Replacing grub cmdline options...${reset}"
sed -i -e s/"rhgb quiet"/"rootdelay=300 console=ttyS0 console=tty0 earlyprintk=ttyS0"/ /etc/default/grub
echo "${yellow}Running update-grub${reset}"
grub2-mkconfig -o /boot/grub2/grub.cfg
echo "${green}Congrats your system has been prepared!"
echo "${red}!Please! edit /etc/netplan/50-vmware-static.yaml with the correct mac address and ip information before doing anything else!!!${reset}"
echo " "
echo "${yellow}Once you have edited your on-premises YAML config you need to run the following commands as root (or sudo)
sudo netplan --debug generate
sudo netplan --debug apply
Failing to do this means your machine will get a bogus 172.16.1.x address.${reset}"