1#!/bin/bash
2
3# Copyright The OpenTelemetry Authors
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17set -euxo pipefail
18
19SCRIPT_DIR="$( cd "$( dirname ${BASH_SOURCE[0]} )" && pwd )"
20REPO_DIR="$( cd "$SCRIPT_DIR/../../../../../" && pwd )"
21VERSION="${1:-}"
22ARCH="${2:-"amd64"}"
23OUTPUT_DIR="${3:-"$REPO_DIR/dist/"}"
24OTELCOL_PATH="$REPO_DIR/bin/otelcol_linux_$ARCH"
25CONFIG_PATH="$REPO_DIR/examples/local/otel-config.yaml"
26
27mkdir -p $OUTPUT_DIR
28
29. $SCRIPT_DIR/../common.sh
30
31if [[ -z "$VERSION" ]]; then
32    latest_tag="$( git describe --abbrev=0 --match v[0-9]* )"
33    VERSION="${latest_tag}~post"
34fi
35
36fpm -s dir -t rpm -n $PKG_NAME -v ${VERSION#v} -f -p "$OUTPUT_DIR" \
37    --vendor "$PKG_VENDOR" \
38    --maintainer "$PKG_MAINTAINER" \
39    --description "$PKG_DESCRIPTION" \
40    --license "$PKG_LICENSE" \
41    --url "$PKG_URL" \
42    --architecture "$ARCH" \
43    --config-files /etc/otel-collector/otel-collector.conf \
44    --config-files /etc/otel-collector/config.yaml \
45    --rpm-summary "$PKG_DESCRIPTION" \
46    --rpm-user "$PKG_USER" \
47    --rpm-group "$PKG_GROUP" \
48    --before-install "$PREINSTALL_PATH" \
49    --after-install "$POSTINSTALL_PATH" \
50    --pre-uninstall "$PREUNINSTALL_PATH" \
51    $OTELCOL_PATH=/usr/bin/$PROCESS_NAME \
52    $SERVICE_PATH=/lib/systemd/system/$SERVICE_NAME.service \
53    $ENVFILE_PATH=/etc/otel-collector/otel-collector.conf \
54    $CONFIG_PATH=/etc/otel-collector/config.yaml
55