Most of the this script is based on the document “Red Hat Update Infrastructure (RHUI) for on-demand Red Hat Enterprise Linux VMs in Azure” at https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-linux-update-infrastructure-redhat?toc=%2fazure%2fvirtual-machines%2flinux%2ftoc.json
My change will first check if the update was already installed, if not it will follow the process to install
See updates at: https://gitlab.com/Kittell-RedHat/AzureRepo/raw/master/AzureRedHatRepoUpdate.sh
#!/bin/sh # AzureRedHatRepoUpdate.sh # # This will update Azure Red Hat servers to the new RHUI Repo if needed. # # Created by David Kittell on 12/27/16. # clear cd ~/ echo -e "\033[32mChecking for Azure Red Hat Repo Update....\033[0m" if rpm -qa | grep -q rhui-azure-rhel7-2.0-2.noarch; then echo "Installed" #exit 0 else echo "Not Installed.\nStarting process to update..." echo -e "\033[32mDownload (via curl) the public key signature\033[0m" curl -o RPM-GPG-KEY-microsoft-azure-release https://download.microsoft.com/download/9/D/9/9d945f05-541d-494f-9977-289b3ce8e774/microsoft-sign-public.asc echo -e "\033[32mValidate key\033[0m" if ! gpg --list-packets --verbose < RPM-GPG-KEY-microsoft-azure-release | grep -q "keyid: EB3E94ADBE1229CF"; then echo "Keyfile azure.asc NOT valid. Exiting." exit 1 fi echo -e "\033[32mInstall Key\033[0m" sudo install -o root -g root -m 644 RPM-GPG-KEY-microsoft-azure-release /etc/pki/rpm-gpg sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-microsoft-azure-release echo -e "\033[32mDownload RPM package\033[0m" if grep -q "release 7" /etc/redhat-release; then ver=7 elif grep -q "release 6" /etc/redhat-release; then ver=6 else echo "Version not supported, exiting" exit 1 fi url=https://rhui-1.microsoft.com/pulp/repos/microsoft-azure-rhel$ver/rhui-azure-rhel$ver-2.0-2.noarch.rpm curl -o azureclient.rpm "$url" echo -e "\033[32mVerify package\033[0m" if ! rpm -Kv azureclient.rpm | grep -q "key ID be1229cf: OK"; then echo "RPM failed validation ($url)" exit 1 fi echo -e "\033[32mInstall package\033[0m" sudo rpm -U azureclient.rpm echo -e "\033[32mCreating Yum Cache\033[0m" sudo yum -y makecache fast echo -e "\033[32mRunning Yum Update\033[0m" sudo yum -y update # Make sure you are up to date before you start fi
Last Updated on January 9, 2017