|
| 1 | +#!/bin/bash |
| 2 | +set -eux |
| 3 | + |
| 4 | +# Used to update a SUSE repository, e.g. during a staging build or release process |
| 5 | + |
| 6 | +# SUSE/openSUSE version and arch, e.g. "opensuse/leap/15.6" or "sles/15-sp5" |
| 7 | +RPM_REPO=${RPM_REPO:?} |
| 8 | + |
| 9 | +# Where the base of all the repos is |
| 10 | +BASE_PATH=${BASE_PATH:-$1} |
| 11 | +if [[ ! -d "$BASE_PATH" ]]; then |
| 12 | + echo "ERROR: invalid base path: $BASE_PATH" |
| 13 | + exit 1 |
| 14 | +fi |
| 15 | + |
| 16 | +# Set true to prevent signing |
| 17 | +DISABLE_SIGNING=${DISABLE_SIGNING:-false} |
| 18 | +if [[ "$DISABLE_SIGNING" != "true" ]]; then |
| 19 | + echo "INFO: RPM signing configuration" |
| 20 | + rpm --showrc | grep gpg |
| 21 | + rpm -q gpg-pubkey --qf '%{name}-%{version}-%{release} --> %{summary}\n' |
| 22 | +fi |
| 23 | + |
| 24 | +# createrepo is available on SUSE |
| 25 | +CREATE_REPO_CMD="createrepo" |
| 26 | +CREATE_REPO_ARGS=${CREATE_REPO_ARGS:--dvp} |
| 27 | + |
| 28 | +# Check for createrepo |
| 29 | +if ! command -v createrepo &> /dev/null; then |
| 30 | + echo "ERROR: 'createrepo' command not found. Please install it, e.g., 'zypper install createrepo'." |
| 31 | + exit 1 |
| 32 | +fi |
| 33 | + |
| 34 | +echo "INFO: updating $RPM_REPO" |
| 35 | + |
| 36 | +REPO_DIR=$(realpath -sm "$BASE_PATH/$RPM_REPO") |
| 37 | +if [[ ! -d "$REPO_DIR" ]]; then |
| 38 | + echo "ERROR: missing $REPO_DIR" |
| 39 | + exit 1 |
| 40 | +fi |
| 41 | + |
| 42 | +if [[ "$DISABLE_SIGNING" != "true" ]]; then |
| 43 | + # Sign all RPMs created for this target, cover both fluent-bit and legacy packages |
| 44 | + find "$REPO_DIR" -name "*-bit-*.rpm" -exec rpm --define "_gpg_name $GPG_KEY" --addsign {} \; |
| 45 | +fi |
| 46 | + |
| 47 | +# Create full metadata for all RPMs in the directory |
| 48 | +"$CREATE_REPO_CMD" "$CREATE_REPO_ARGS" "$REPO_DIR" |
| 49 | + |
| 50 | +# Set up repo info in SUSE format |
| 51 | +if [[ -n "${AWS_S3_BUCKET:-}" ]]; then |
| 52 | + # Create top-level file and replace path separator with dash |
| 53 | + # opensuse/leap/15.6 --> opensuse-leap-15.6.repo |
| 54 | + REPO_TYPE=${RPM_REPO//\//-} |
| 55 | + echo "INFO: setting up $BASE_PATH/$REPO_TYPE.repo" |
| 56 | + cat << EOF > "$BASE_PATH/$REPO_TYPE.repo" |
| 57 | +[Fluent-Bit] |
| 58 | +name=Fluent Bit Packages - $REPO_TYPE |
| 59 | +type=rpm-md |
| 60 | +baseurl=https://$AWS_S3_BUCKET.s3.amazonaws.com/$RPM_REPO/ |
| 61 | +enabled=1 |
| 62 | +gpgkey=https://$AWS_S3_BUCKET.s3.amazonaws.com/fluentbit.key |
| 63 | +gpgcheck=1 |
| 64 | +autorefresh=1 |
| 65 | +EOF |
| 66 | +fi |
| 67 | + |
| 68 | +# Ensure we sign the repository metadata |
| 69 | +if [[ "$DISABLE_SIGNING" != "true" ]]; then |
| 70 | + while IFS= read -r -d '' REPO_METADATA_FILE; do |
| 71 | + echo "INFO: signing $REPO_METADATA_FILE" |
| 72 | + gpg --detach-sign --batch --armor --yes -u "$GPG_KEY" "$REPO_METADATA_FILE" |
| 73 | + done < <(find "$REPO_DIR" -name repomd.xml -print0) |
| 74 | + # Debug output for checking |
| 75 | + find "$REPO_DIR" -name "repomd.xml*" -exec ls -l {} \; |
| 76 | +fi |
| 77 | + |
| 78 | +echo "INFO: Completed $RPM_REPO" |
0 commit comments