Updated variable names, Using Virtualization instead of chassis for KVM vs. VMware. Added logic for Rocky Linux 9.0. Added qemu guest tool install logic and better error code for unsupported OS

This commit is contained in:
crp3844
2022-11-18 11:03:34 -05:00
parent 742f3a0502
commit b2e35f348c

View File

@@ -14,18 +14,24 @@ fi
# get OS ditro and version
OS=$(hostnamectl | awk '/Operating System/ {print $3}')
Chassis=$(hostnamectl | awk '/Chassis/ {print $2}')
CHASSIS=$(hostnamectl | awk '/Chassis/ {print $2}')
VIRTUALIZATION=$(hostnamectl | awk '/Virtualization/ {print $2}')
if [ "${OS}" == "Ubuntu" ]; then
OS_VER=$(hostnamectl | awk '/Operating System/ {print $4}')
OS_VERSION=$(hostnamectl | awk '/Operating System/ {print $4}')
else
OS_VER=$(hostnamectl | awk '/Operating System/ {print $5}')
OS_VERSION=$(hostnamectl | awk '/Operating System/ {print $5}')
fi
if [ "${Chassis}" == "vm" ]; then
if [ "${VIRTUALIZATION}" == "vmware" ]; then
VM="true"
else
VM="false"
fi
if [ "${VIRTUALIZATION}" == "kvm" ]; then
KVM="true"
else
KVM="false"
fi
# set custom bash settings system wide
cat <<EOF > /etc/profile.d/gaunt_custom_bash.sh
@@ -49,6 +55,10 @@ if [ ${OS} == "Debian" ] || [ ${OS} == "Ubuntu" ]; then
if [ "${VM}" == "true" ]; then
apt install -y open-vm-tools
fi
if [ "${KVM}" == "true" ]; then
apt install -y qemu-guest-agent
fi
# remove unneeded packages
apt autoremove -y
@@ -62,41 +72,44 @@ if [ ${OS} == "Debian" ] || [ ${OS} == "Ubuntu" ]; then
update-ca-certificates
# CentOS OS
elif [ "${OS}" == "CentOS" ]; then
elif [ "${OS}" == "CentOS" ] || [ "${OS}" == "Rocky" ]; then
# Centos 7
if [ "${OS_VER}" == "7" ]; then
# upgrade all packages
yum update -y
# install the epel for other packages and wget
yum install -y elrepo-release epel-release yum-utils
# clean the yum cache
yum clean all
# remove unneeded packages
yum autoremove -y
if [ "${OS_VERSION}" == "7" ]; then
# upgrade all packages
yum update -y
# install the epel for other packages and wget
yum install -y elrepo-release epel-release yum-utils
# clean the yum cache
yum clean all
# remove unneeded packages
yum autoremove -y
# install the packages
yum install -y sudo rsync tar nano htop nload iperf iperf3 bind-utils yum-cron unzip bzip2 nfs-utils git wget uptimed net-tools make realmd oddjob oddjob-mkhomedir sssd adcli mlocate
# install the packages
yum install -y sudo rsync tar nano htop nload iperf iperf3 bind-utils yum-cron unzip bzip2 nfs-utils git wget uptimed net-tools make realmd oddjob oddjob-mkhomedir sssd adcli mlocate
# install vm tools
if [ "${VM}" == "true" ]; then
yum install -y open-vm-tools
fi
# modify yum-cron config to auto install security updates and enable/start the service
sed --in-place "s/^update_cmd\ =\ security/update_cmd\ =\ default/" /etc/yum/yum-cron.conf
sed --in-place "s/^apply_updates\ =\ no/apply_updates\ =\ yes/" /etc/yum/yum-cron.conf
systemctl enable yum-cron
systemctl restart yum-cron
# start and enable uptimed
systemctl start uptimed
systemctl enable uptimed
# install vm tools
if [ "${VM}" == "true" ]; then
yum install -y open-vm-tools
fi
if [ "${KVM}" == "true" ]; then
yum install -y qemu-guest-agent
fi
# modify yum-cron config to auto install security updates and enable/start the service
sed --in-place "s/^update_cmd\ =\ security/update_cmd\ =\ default/" /etc/yum/yum-cron.conf
sed --in-place "s/^apply_updates\ =\ no/apply_updates\ =\ yes/" /etc/yum/yum-cron.conf
systemctl enable yum-cron
systemctl restart yum-cron
# start and enable uptimed
systemctl start uptimed
systemctl enable uptimed
fi
# Centos 7
if [ "${OS_VER}" == "8" ]; then
if [ "${OS_VERSION}" == "8" ] || [ "${OS_VERSION}" == "9.0" ]; then
# upgrade all packages
dnf update -y
@@ -123,6 +136,9 @@ elif [ "${OS}" == "CentOS" ]; then
if [ "${VM}" == "true" ]; then
dnf install -y open-vm-tools
fi
if [ "${KVM}" == "true" ]; then
dnf install -y qemu-guest-agent
fi
fi
# modify ssh to allow root login and then restart the service
@@ -134,7 +150,11 @@ elif [ "${OS}" == "CentOS" ]; then
update-ca-trust
else
echo "Unable to determine linux distro"
echo "Unsupported OS detected."
echo "OS: ${OS}"
echo "OS Version: ${OS_VERSION}"
echo "VM: ${VM}"
echo "KVM: ${KVM}"
exit
fi