forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package-rpm.sh
executable file
·80 lines (63 loc) · 1.93 KB
/
package-rpm.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env bash
set -euo pipefail
# package-rpm.sh
#
# SUMMARY
#
# Packages a .rpm file to be distributed in the YUM package manager.
#
# ENV VARS
#
# $TARGET a target triple. ex: x86_64-apple-darwin (no default)
TARGET="${TARGET:?"You must specify a target triple, ex: x86_64-apple-darwin"}"
#
# Local vars
#
PROJECT_ROOT="$(pwd)"
PACKAGE_VERSION="$("$PROJECT_ROOT/scripts/version.sh")"
ARCHIVE_NAME="vector-$PACKAGE_VERSION-$TARGET.tar.gz"
ARCHIVE_PATH="target/artifacts/$ARCHIVE_NAME"
#
# Header
#
echo "Packaging .rpm for $ARCHIVE_NAME"
echo "TARGET: $TARGET"
#
# Package
#
# RPM has a concept of releases, but we do not need this so every
# release is 1.
export RELEASE=1
# The RPM spec does not like a leading `v` or `-` in the version name.
# Therefore we clean the version so that the `rpmbuild` command does
# not fail.
export CLEANED_VERSION="${PACKAGE_VERSION//-/.}"
# The arch is the first part of the target
# For some architectures, like armv7hl it doesn't match the arch
# from Rust target triple and needs to be specified manually.
ARCH="${ARCH:-"$(echo "$TARGET" | cut -d'-' -f1)"}"
# Prepare rpmbuild dir
RPMBUILD_DIR="$(mktemp -td "rpmbuild.XXXX")"
# Create build dirs
for ITEM in RPMS SOURCES SPECS SRPMS BUILD; do
rm -rf "${RPMBUILD_DIR:?}/${ITEM:?}"
mkdir -p "$RPMBUILD_DIR/$ITEM"
done
# Init support data
mkdir -p \
"$RPMBUILD_DIR/SOURCES/systemd"
cp -av distribution/systemd/. "$RPMBUILD_DIR/SOURCES/systemd"
# Copy the archive into the sources dir
cp -av "$ARCHIVE_PATH" "$RPMBUILD_DIR/SOURCES/vector-$ARCH.tar.gz"
# Perform the build.
rpmbuild \
--define "_topdir $RPMBUILD_DIR" \
--target "$ARCH-redhat-linux" \
--define "_arch $ARCH" \
--nodebuginfo \
-ba distribution/rpm/vector.spec
#
# Move the RPM into the artifacts dir
#
ls "$RPMBUILD_DIR/RPMS/$ARCH"
mv -v "$RPMBUILD_DIR/RPMS/$ARCH/vector-$CLEANED_VERSION-$RELEASE.$ARCH.rpm" "target/artifacts/vector-${CLEANED_VERSION}-${RELEASE}.${ARCH}.rpm"