Skip to content

Commit

Permalink
Merge pull request #32 from ferricoxide/Issue_31
Browse files Browse the repository at this point in the history
Issue 31
  • Loading branch information
ferricoxide authored Oct 21, 2024
2 parents ade4c98 + eb5cd6c commit 0568609
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 2 deletions.
67 changes: 65 additions & 2 deletions AWSutils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,78 @@ function InstallCfnBootstrap {
err_exit "Failed making cfn-hup service executable"

err_exit "Using alternatives to configure cfn-hup symlink and initscript..." NONE
chroot "${CHROOTMNT}" alternatives --verbose --install /opt/aws/bin/cfn-hup cfn-hup /usr/local/bin/cfn-hup 1 --initscript cfn-hup || \
err_exit "Failed configuring cfn-hup symlink and initscript"
chroot "${CHROOTMNT}" alternatives --verbose --install /opt/aws/bin/cfn-hup cfn-hup /usr/local/bin/cfn-hup 1 || \
err_exit "Failed configuring cfn-hup symlink"

# Install systemd-supporting content
InstallCfnBootstrap_systemd

err_exit "Cleaning up install files..." NONE
rm -rf "${CHROOTMNT}${TMPDIR}" || \
err_exit "Failed cleaning up install files"
fi
}

# Install systemd bits
function InstallCfnBootstrap_systemd {
local SVC_NAME="cfn-hup"
local ETC_DIR="${CHROOTMNT}/etc/systemd/system"
local SVC_FILE="${ETC_DIR}/${SVC_NAME}.service"
local OS_VERSION

SVC_NAME="cfn-hup"
ETC_DIR="${CHROOTMNT}/etc/systemd/system"
SVC_FILE="${ETC_DIR}/${SVC_NAME}.service"
OS_VERSION="$(
awk -F "=" '/^VERSION=/{ print $2 }' /etc/os-release | \
sed -e 's/"//g' | \
cut -d '.' -f 1
)"

if [[ ${OS_VERSION} -ge 9 ]]
then
err_exit "EL 9+ distros want systemd units..." NONE

if [[ ! -d ${ETC_DIR} ]]
then
err_exit "Creating ${ETC_DIR}" NONE
install -dDm 0755 "${ETC_DIR}" || \
err_exit "Failed creating ${ETC_DIR}"
fi

if [[ ! -f ${SVC_FILE} ]]
then
err_exit "Installing systemd unit-file for ${SVC_NAME}..." NONE
install -bDm 0644 <(
echo "[Unit]"
echo "Description=cfn-hup Service"
echo "After=network.target"
echo ""
echo "[Service]"
echo "ExecStart=/usr/local/bin/cfn-hup"
echo "Type=forking"
echo "PIDFile=/run/cfn-hup.pid"
echo ""
echo "[Install]"
echo "WantedBy=multi-user.target"
) "${SVC_FILE}" || \
err_exit "Failed installing systemd unit-file for ${SVC_NAME}"
fi

if [[ ! -d ${CHROOTMNT}/etc/cfn ]]
then
err_exit "Creating /etc/cfn directory" NONE
install -Z "system_u:object_r:etc_t:s0" -dDm 0755 -o root \
-g root /etc/cfn || err_exit "Failed creating /etc/cfn directory" NONE
fi

chroot "${CHROOTMNT}" /usr/bin/systemctl disable "${SVC_NAME}.service" || \
err_exit "FAILED"
fi

return
}

# shellcheck disable=SC2016,SC1003
function ProfileSetupAwsCli {
install -bDm 0644 -o root -g root <(
Expand Down
29 changes: 29 additions & 0 deletions PostBuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,32 @@ function ConfigureNetworking {
chroot "${CHROOTMNT}" systemctl enable NetworkManager
}

# EL9 is more annoying about SysV-isms
function ConfigureRcLocalGenerator {
local GENERATOR_DIR="${CHROOTMNT}/etc/systemd/system-generators"
local GENERATOR_FIL="${GENERATOR_DIR}/systemd-rc-local-generator"

# Ensure systemd file is present
if [[ ! -f ${GENERATOR_FIL} ]]
then
printf "Creating %s... " "${GENERATOR_DIR}"
install -Z "system_u:object_r:etc_t:s0" -dDm 0755 -o root -g root \
"${GENERATOR_DIR}" || err_exit "Failed creating ${GENERATOR_DIR}"
echo "Success!"

printf "Creating %s... " "${GENERATOR_FIL}"
install -bDm 0600 -o root -g root /dev/null "${GENERATOR_FIL}" || \
err_exit "Failed creating ${GENERATOR_FIL}"
echo "Success!"

printf "Setting SELinux label on %s... " "${GENERATOR_FIL}"
chcon -u system_u -r object_r -t etc_t "${GENERATOR_FIL}" || \
err_exit "Failed creating ${GENERATOR_FIL}"
echo "Success!"
fi
}


# Firewalld config
function FirewalldSetup {
err_exit "Setting up baseline firewall rules..." NONE
Expand Down Expand Up @@ -661,6 +687,9 @@ CreateFstab
# Set /tmp as a tmpfs
SetupTmpfs

# Ensure no systemd-rc-local-generator log-spamming
ConfigureRcLocalGenerator

# Configure logging
ConfigureLogging

Expand Down

0 comments on commit 0568609

Please sign in to comment.