#!/usr/bin/bash # Function to perform reposync perform_reposync() { local reponame="$1" local basepath="$2" /usr/bin/dnf reposync \ --gpgcheck \ --delete \ --downloadcomps \ --download-metadata \ --remote-time \ --disablerepo="*" \ --enablerepo="${reponame}" \ --download-path="${basepath}/live" } # Function to download GPG keys download_gpg_key() { local gpgkeyurl="$1" local reponame="$2" local basepath="$3" # Extract filename from URL local filename=$(basename "$gpgkeyurl") # Download GPG key to the specified path with the filename from the URL wget -q -O "${basepath}/live/${reponame}/${filename}" "$gpgkeyurl" || { echo "Failed to download GPG key from $gpgkeyurl" } } # Function to perform rsync with hard links perform_rsync() { local source_path="$1" local dest_path="$2" # Create the destination directory if it doesn't exist mkdir -p "$dest_path" # Use rsync to create hard links to the files in the destination directory rsync -a --link-dest="$source_path" "$source_path"/* "$dest_path" } create_repo_metadata() { local basepath="${1}" local osname="${2}" local release="${3}" local repository="${4}" local current_date="${5}" local repo_path="${basepath}/snap/${osname}/${release}/${repository}-${current_date}" if [[ -d "$repo_path" ]]; then echo "Running createrepo on ${repo_path}..." createrepo --update "${repo_path}" if [[ $? -eq 0 ]]; then echo "Successfully created repository metadata for ${repository}" else echo "Failed to create repository metadata for ${repository}" >&2 return 1 fi else echo "The specified repository path does not exist: ${repo_path}" >&2 return 1 fi } # Current date in the required format DATE=$(date +%Y%m%d) # iterate over each configuration file for conf in /etc/reposync/conf.d/*.conf; do # source the configuration to get the variables source "$conf" # Call the function to download the GPG key download_gpg_key "$GPGKEYURL" "$REPONAME" "$BASEPATH" # Call the reposync function perform_reposync "$REPONAME" "$BASEPATH" # Path for rsync source live_path="${BASEPATH}/live/${REPONAME}" # Path for rsync destination snap_path="${BASEPATH}/snap/${OSNAME}/${RELEASE}/${REPOSITORY}-${DATE}/${ARCH}/os" # Call the rsync function perform_rsync "$live_path" "$snap_path" # After syncing each repo, fix the repository metadata create_repo_metadata "${BASEPATH}" "${OSNAME}" "${RELEASE}" "${REPOSITORY}" "${DATE}" done