#!/bin/bash

log_file="/var/log/post-install.log"

if [ -f /etc/yum/pluginconf.d/ptoken.conf ]; then
    sed -i s/1/0/g /etc/yum/pluginconf.d/ptoken.conf
fi

mkdir -pv /etc/pki/rpm-gpg/ >> $log_file
curl -o /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 https://vault.centos.org/RPM-GPG-KEY-CentOS-7 >> $log_file

mkdir -pv /etc/yum.repos.d/ >> $log_file

cat <<EOF >/etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
baseurl=https://vault.centos.org/7.9.2009/os/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1

[updates]
name=CentOS-$releasever - Updates
baseurl=https://vault.centos.org/7.9.2009/updates/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1

[extras]
name=CentOS-$releasever - Extras
baseurl=https://vault.centos.org/7.9.2009/extras/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1

[centosplus]
name=CentOS-$releasever - CentOSPlus
baseurl=https://vault.centos.org/7.9.2009/centosplus/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=0
EOF

yum -y install cloud-init python-oauthlib >> $log_file
yum clean all >> $log_file

# This is no longer required
rm -v /etc/yum.repos.d/CentOS-Base.repo >> $log_file

exit 0
