<commit_before>#!/bin/bash -v

set -e -x

# Logger
exec > >(tee /var/log/user-data_3rd-bootstrap.log || logger -t user-data -s 2> /dev/console) 2>&1

#-------------------------------------------------------------------------------
# Set UserData Parameter
#-------------------------------------------------------------------------------

if [ -f /tmp/userdata-parameter ]; then
    source /tmp/userdata-parameter
fi

if [[ -z "${Language}" || -z "${Timezone}" || -z "${VpcNetwork}" ]]; then
    # Default Language
	Language="en_US.UTF-8"
    # Default Timezone
	Timezone="Asia/Tokyo"
	# Default VPC Network
	VpcNetwork="IPv4"
fi

# echo
echo $Language
echo $Timezone
echo $VpcNetwork

#-------------------------------------------------------------------------------
# Parameter Settings
#-------------------------------------------------------------------------------

# Parameter Settings
CWAgentConfig="https://raw.githubusercontent.com/usui-tk/amazon-ec2-userdata/master/Config_AmazonCloudWatchAgent/AmazonCloudWatchAgent_RHEL-v6-HVM.json"

#-------------------------------------------------------------------------------
# Acquire unique information of Linux distribution
#  - RHEL v6
#    https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/
#    https://access.redhat.com/support/policy/updates/extras
#    https://access.redhat.com/articles/1150793
#    https://access.redhat.com/solutions/3358
#
#    https://access.redhat.com/articles/3135121
#
#    https://aws.amazon.com/marketplace/pp/B00CFQWLS6
#
#-------------------------------------------------------------------------------

# Cleanup repository information
yum clean all

# Show Linux Distribution/Distro information
if [ $(command -v lsb_release) ]; then
    lsb_release -a
fi

# Show Linux System Information
uname -a

# Show Linux distribution release Information
cat /etc/redhat-release

# Default installation package [rpm command]
rpm -qa --qf="%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" | sort > /tmp/command-log_rpm_installed-package.txt

# Default installation package [yum command]
yum list installed > /tmp/command-log_yum_installed-package.txt

# Default repository package [yum command]
yum list all > /tmp/command-log_yum_repository-package-list.txt

# Default repository package group [yum command]
yum grouplist -v > /tmp/command-log_yum_repository-package-group-list.txt

# upstartd service config [chkconfig command]
chkconfig --list > /tmp/command-log_chkconfig_list.txt

# Default repository list [yum command]
yum repolist all > /tmp/command-log_yum_repository-list.txt

#-------------------------------------------------------------------------------
# Default Package Update
#-------------------------------------------------------------------------------
#  - RHEL v6 (Non-ELS) - Red Hat Yum Repository Default Status (Enable/Disable)
#
#    [Default - Enable]
#        rhui-REGION-rhel-server-releases
#        rhui-REGION-rhel-server-rh-common
#        rhui-client-config-server-6
#    [Default - Disable]
#        rhui-REGION-rhel-server-extras
#        rhui-REGION-rhel-server-releases-optional
#        rhui-REGION-rhel-server-supplementary
#        rhui-REGION-rhel-server-rhscl
#-------------------------------------------------------------------------------
#  - RHEL v6 (ELS) - Red Hat Yum Repository Default Status (Enable/Disable)
#
#    [Default - Enable]
#        rhui-rhel-6-server-els-rhui-rpms
#        rhui-client-config-server-6
#    [Default - Disable]
#        rhui-REGION-rhel-server-rh-common
#        rhui-REGION-rhel-server-extras
#        rhui-REGION-rhel-server-releases-optional
#        rhui-REGION-rhel-server-supplementary
#        rhui-REGION-rhel-server-rhscl
#-------------------------------------------------------------------------------

# Check if this AMI is RHEL ELS compatible or not.
# If the return value is not 0, it is assumed to be RHEL ELS compatible.
ELS_FLAG=$(yum repolist all | grep -ie "enabled" -ie "disabled" | grep -ve "Loaded plugins" -ve "beta" -ve "debug" -ve "source" -ve "test" -ve "epel" | awk '{print $1}' | awk '{ sub("/.*$",""); print $0; }' | grep -ie "els" | wc -l)

# Configure NTP Client software (Activate Amazon Time Sync Service settings in the Chrony configuration file)
if [ ${ELS_FLAG} -ne 0 ]; then
	echo "Support for RHEL ELS (Extended Life Cycle Support)"

	################################################################################
	# [Workaround] Workarounds for RHUI configuration in RHEL ELS
	#  (Affected AMI information) RHEL-6.10ELS_HVM-20201107-x86_64-1-Hourly2-GP2
	################################################################################

	# RPM file for RHUI repository configuration for RHEL ELS (provided by AWS support team)
	ELS_REPO_RPM="https://raw.githubusercontent.com/usui-tk/amazon-ec2-userdata/master/Workaround/Package/rh-amazon-rhui-client-els-3.0.39-1.el6.noarch.rpm"

	# Remove RHUI configuration RPMs that do not support RHEL ELS
	if [ $(yum list installed | grep -ie "rh-amazon-rhui-client" | grep -ve "rh-amazon-rhui-client-els") ]; then
		rpm -qi rh-amazon-rhui-client

		yum remove -y rh-amazon-rhui-client

		yum --enablerepo="*" --verbose clean all
	fi

	# Install RHUI configuration RPM for RHEL ELS support
	yum localinstall --nogpgcheck -y ${ELS_REPO_RPM}

	yum --enablerepo="*" --verbose clean all<commit_msg>Update 3rd-Bootstrap_RHEL-v6-HVM.sh<commit_after>#!/bin/bash -v

set -e -x

# Logger
exec > >(tee /var/log/user-data_3rd-bootstrap.log || logger -t user-data -s 2> /dev/console) 2>&1

#-------------------------------------------------------------------------------
# Set UserData Parameter
#-------------------------------------------------------------------------------

if [ -f /tmp/userdata-parameter ]; then
    source /tmp/userdata-parameter
fi

if [[ -z "${Language}" || -z "${Timezone}" || -z "${VpcNetwork}" ]]; then
    # Default Language
	Language="en_US.UTF-8"
    # Default Timezone
	Timezone="Asia/Tokyo"
	# Default VPC Network
	VpcNetwork="IPv4"
fi

# echo
echo $Language
echo $Timezone
echo $VpcNetwork

#-------------------------------------------------------------------------------
# Parameter Settings
#-------------------------------------------------------------------------------

# Parameter Settings
CWAgentConfig="https://raw.githubusercontent.com/usui-tk/amazon-ec2-userdata/master/Config_AmazonCloudWatchAgent/AmazonCloudWatchAgent_RHEL-v6-HVM.json"

#-------------------------------------------------------------------------------
# Acquire unique information of Linux distribution
#  - RHEL v6
#    https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/
#    https://access.redhat.com/support/policy/updates/extras
#    https://access.redhat.com/articles/1150793
#    https://access.redhat.com/solutions/3358
#
#    https://access.redhat.com/articles/3135121
#
#    https://aws.amazon.com/marketplace/pp/B00CFQWLS6
#
#-------------------------------------------------------------------------------

# Cleanup repository information
yum clean all

# Show Linux Distribution/Distro information
if [ $(command -v lsb_release) ]; then
    lsb_release -a
fi

# Show Linux System Information
uname -a

# Show Linux distribution release Information
cat /etc/redhat-release

# Default installation package [rpm command]
rpm -qa --qf="%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" | sort > /tmp/command-log_rpm_installed-package.txt

# Default installation package [yum command]
yum list installed > /tmp/command-log_yum_installed-package.txt

# Default repository package [yum command]
yum list all > /tmp/command-log_yum_repository-package-list.txt

# Default repository package group [yum command]
yum grouplist -v > /tmp/command-log_yum_repository-package-group-list.txt

# upstartd service config [chkconfig command]
chkconfig --list > /tmp/command-log_chkconfig_list.txt

# Default repository list [yum command]
yum repolist all > /tmp/command-log_yum_repository-list.txt

#-------------------------------------------------------------------------------
# Default Package Update
#-------------------------------------------------------------------------------
#  - RHEL v6 (Non-ELS) - Red Hat Yum Repository Default Status (Enable/Disable)
#
#    [Default - Enable]
#        rhui-REGION-rhel-server-releases
#        rhui-REGION-rhel-server-rh-common
#        rhui-client-config-server-6
#    [Default - Disable]
#        rhui-REGION-rhel-server-extras
#        rhui-REGION-rhel-server-releases-optional
#        rhui-REGION-rhel-server-supplementary
#        rhui-REGION-rhel-server-rhscl
#-------------------------------------------------------------------------------
#  - RHEL v6 (ELS) - Red Hat Yum Repository Default Status (Enable/Disable)
#
#    [Default - Enable]
#        rhui-rhel-6-server-els-rhui-rpms
#        rhui-client-config-server-6
#    [Default - Disable]
#        rhui-REGION-rhel-server-rh-common
#        rhui-REGION-rhel-server-extras
#        rhui-REGION-rhel-server-releases-optional
#        rhui-REGION-rhel-server-supplementary
#        rhui-REGION-rhel-server-rhscl
#-------------------------------------------------------------------------------

# Check if this AMI is RHEL ELS compatible or not.
# If the return value is not 0, it is assumed to be RHEL ELS compatible.
ELS_FLAG=$(yum repolist all | grep -ie "enabled" -ie "disabled" | grep -ve "Loaded plugins" -ve "beta" -ve "debug" -ve "source" -ve "test" -ve "epel" | awk '{print $1}' | awk '{ sub("/.*$",""); print $0; }' | grep -ie "els" | wc -l)

# Configure NTP Client software (Activate Amazon Time Sync Service settings in the Chrony configuration file)
if [ ${ELS_FLAG} -ne 0 ]; then
	echo "Support for RHEL ELS (Extended Life Cycle Support)"

	################################################################################
	# [Workaround] Workarounds for RHUI configuration in RHEL ELS
	#  (Affected AMI information) RHEL-6.10ELS_HVM-20201107-x86_64-1-Hourly2-GP2
	################################################################################

	# RPM file for RHUI repository configuration for RHEL ELS (provided by AWS support team)
	ELS_REPO_RPM="https://raw.githubusercontent.com/usui-tk/amazon-ec2-userdata/master/Workaround/Package/rh-amazon-rhui-client-els-3.0.39-1.el6.noarch.rpm"

	# Remove RHUI configuration RPMs that do not support RHEL ELS
	if [ $(rpm -qa | grep -ve "rh-amazon-rhui-client-els" | grep -ie "rh-amazon-rhui-client") ]; then
		rpm -qi rh-amazon-rhui-client

		yum remove -y rh-amazon-rhui-client

		yum --enablerepo="*" --verbose clean all
	fi

	# Install RHUI configuration RPM for RHEL ELS support
	yum localinstall --nogpgcheck -y ${ELS_REPO_RPM}

	yum --enablerepo="*" --verbose clean all
{'fraction_non_alphanumeric': 0.28399215026633023, 'fraction_numerical': 0.012148397346042426, 'mean_word_length': 2.047266514806378, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 16, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3922490', 'n_tokens_mistral': 3305, 'n_tokens_neox': 3143, 'n_words': 737}