SecPod Community › Forums › SanerScript › Patch repository creation for Amazon Linux
Tagged: SanerScripts
- This topic has 0 replies, 1 voice, and was last updated by
Community Manager.
-
AuthorPosts
-
-
February 14, 2025 at 10:40 am #6348
#!/bin/bash
# Exit script on any error
set -e# Update the system and install necessary packages
sudo yum update -y
sudo yum install -y httpd createrepo yum-utils# Start and enable Apache web server
sudo systemctl start httpd
sudo systemctl enable httpd# Create directory for the repository
REPO_DIR=”/var/www/html/repo”
sudo mkdir -p ${REPO_DIR}# Sync the Amazon Linux 2 base and updates repositories to the local directory
sudo reposync -p ${REPO_DIR} -r amzn2-core -r amzn2extra-docker# Create repository metadata
sudo createrepo ${REPO_DIR}/amzn2-core
sudo createrepo ${REPO_DIR}/amzn2extra-docker# Create the update script to update the repository metadata
UPDATE_SCRIPT=”/usr/local/bin/update-repo.sh”
sudo bash -c “cat << ‘EOF’ > ${UPDATE_SCRIPT}
#!/bin/bash
# Sync the Amazon Linux 2 base and updates repositories
sudo reposync -p ${REPO_DIR} -r amzn2-core -r amzn2extra-docker
# Update the repository metadata
sudo createrepo –update ${REPO_DIR}/amzn2-core
sudo createrepo –update ${REPO_DIR}/amzn2extra-docker
# Reload Apache to ensure changes are picked up
sudo systemctl reload httpd
EOF”# Make the update script executable
sudo chmod +x ${UPDATE_SCRIPT}# Optionally, set up a cron job to update the repository metadata periodically
CRON_JOB=”0 0 * * * ${UPDATE_SCRIPT}”
( sudo crontab -l 2>/dev/null; echo “${CRON_JOB}” ) | sudo crontab –# Provide instructions for setting up EC2 instances to use the repository
echo “Repository setup is complete.”
echo “To configure your EC2 instances to use this repository, create a file /etc/yum.repos.d/custom.repo with the following content:”
echo
echo “[custom-repo-core]”
echo “name=Custom Repository Core”
echo “baseurl=http://$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4)/repo/amzn2-core/”
echo “enabled=1”
echo “gpgcheck=0”
echo
echo “[custom-repo-extra-docker]”
echo “name=Custom Repository Extra Docker”
echo “baseurl=http://$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4)/repo/amzn2extra-docker/”
echo “enabled=1”
echo “gpgcheck=0”
echo
echo “Then run the following commands on each EC2 instance:”
echo “sudo yum clean all”
echo “sudo yum makecache”echo “Your custom repository is now ready to use.”
-
-
AuthorPosts
- You must be logged in to reply to this topic.