<commit_before>#!/bin/bash

set -e

function printHelp() {
  >&2 echo "\
USAGE: $0 -O OS -A ARCH

Creates packages for the given OS/ARCH, using the influxdb source tarball mounted at
/influxdb-src.tar.gz and the binaries tarball mounted at /influxdb-bin.tar.gz .
"
}

if [ $# -eq 0 ]; then
  printHelp
  exit 1
fi

OS=""
ARCH=""
STATIC=""

while getopts hO:A:s arg; do
  case "$arg" in
    h) printHelp; exit 1;;
    O) OS="$OPTARG";;
    A) ARCH="$OPTARG";;
    s) STATIC="1";;
  esac
done

if [ -z "$OS" ] || [ -z "$ARCH" ]; then
  printHelp
  exit 1
fi

mkdir -p /go
tar x -C /go -zf /influxdb-src.tar.gz
ln -s /go/src/github.com/influxdata/influxdb /isrc # Shorthand for influxdb source.
SHA=$(jq -r .sha < "/isrc/.metadata.json")
VERSION=$(jq -r .version < "/isrc/.metadata.json")

# Extract the respective binaries to dedicated folders.
mkdir -p /ibin
(cd /ibin && tar xzf /influxdb-bin.tar.gz)

if [ "$OS" == "linux" ] || [ "$OS" == "darwin" ]; then
  #############################
  ####### Data packages #######
  #############################

  # Create layout for packaging in /pkg.
  mkdir -p /pkg/usr/bin \
           /pkg/var/log/influxdb \
           /pkg/var/lib/influxdb \
           /pkg/usr/lib/influxdb/scripts \
           /pkg/usr/share/man/man1 \
           /pkg/etc/influxdb \
           /pkg/etc/logrotate.d
  chmod -R 0755 /pkg

  # Copy service scripts.
  cp /isrc/scripts/init.sh /pkg/usr/lib/influxdb/scripts/init.sh
  chmod 0644 /pkg/usr/lib/influxdb/scripts/init.sh
  cp /isrc/scripts/influxdb.service /pkg/usr/lib/influxdb/scripts/influxdb.service
  chmod 0644 /pkg/usr/lib/influxdb/scripts/influxdb.service

  # Copy logrotate script.
  cp /isrc/scripts/logrotate /pkg/etc/logrotate.d/influxdb
  chmod 0644 /pkg/etc/logrotate.d/influxdb

  # Copy sample config.
  cp /isrc/etc/config.sample.toml /pkg/etc/influxdb/influxdb.conf

  # Copy data binaries.
  cp /ibin/* /pkg/usr/bin/

  # Copy man pages.
  cp /isrc/man/*.1.gz /pkg/usr/share/man/man1

  # Make tarball of files in packaging.
  BIN_GZ_NAME="/out/influxdb-oss-${VERSION}_${OS}_${ARCH}.tar.gz"
  if [ "$STATIC" == "1" ]; then
    BIN_GZ_NAME="/out/influxdb-${VERSION}-static_${OS}_${ARCH}.tar.gz"
  fi

  (cd /pkg && tar czf $BIN_GZ_NAME ./*)

  # don't need static install packages.
  if [ "$OS" == "linux" ] && [ "$STATIC" != "1" ]; then
    # Call fpm to build .deb and .rpm packages.
    for typeargs in "-t deb" "-t rpm --depends coreutils"; do
      FPM_NAME=$(
      fpm \
        -s dir \
        $typeargs \
        --log error \
        --vendor InfluxData \
        --url "https://influxdata.com" \
        --after-install /isrc/scripts/post-install.sh \
        --before-install /isrc/scripts/pre-install.sh \
        --after-remove /isrc/scripts/post-uninstall.sh \
        --license Proprietary \
        --maintainer "<EMAIL>" \
        --directories /var/log/influxdb \
        --directories /var/lib/influxdb \
        --description 'Distributed time-series database.' \
        --config-files /etc/influxdb/influxdb.conf \
        --config-files /etc/logrotate.d/influxdb \
        --name "influxdb" \
        --architecture "$ARCH" \
        --version "$VERSION" \<commit_msg>took -oss out of tar.gz names<commit_after>#!/bin/bash

set -e

function printHelp() {
  >&2 echo "\
USAGE: $0 -O OS -A ARCH

Creates packages for the given OS/ARCH, using the influxdb source tarball mounted at
/influxdb-src.tar.gz and the binaries tarball mounted at /influxdb-bin.tar.gz .
"
}

if [ $# -eq 0 ]; then
  printHelp
  exit 1
fi

OS=""
ARCH=""
STATIC=""

while getopts hO:A:s arg; do
  case "$arg" in
    h) printHelp; exit 1;;
    O) OS="$OPTARG";;
    A) ARCH="$OPTARG";;
    s) STATIC="1";;
  esac
done

if [ -z "$OS" ] || [ -z "$ARCH" ]; then
  printHelp
  exit 1
fi

mkdir -p /go
tar x -C /go -zf /influxdb-src.tar.gz
ln -s /go/src/github.com/influxdata/influxdb /isrc # Shorthand for influxdb source.
SHA=$(jq -r .sha < "/isrc/.metadata.json")
VERSION=$(jq -r .version < "/isrc/.metadata.json")

# Extract the respective binaries to dedicated folders.
mkdir -p /ibin
(cd /ibin && tar xzf /influxdb-bin.tar.gz)

if [ "$OS" == "linux" ] || [ "$OS" == "darwin" ]; then
  #############################
  ####### Data packages #######
  #############################

  # Create layout for packaging in /pkg.
  mkdir -p /pkg/usr/bin \
           /pkg/var/log/influxdb \
           /pkg/var/lib/influxdb \
           /pkg/usr/lib/influxdb/scripts \
           /pkg/usr/share/man/man1 \
           /pkg/etc/influxdb \
           /pkg/etc/logrotate.d
  chmod -R 0755 /pkg

  # Copy service scripts.
  cp /isrc/scripts/init.sh /pkg/usr/lib/influxdb/scripts/init.sh
  chmod 0644 /pkg/usr/lib/influxdb/scripts/init.sh
  cp /isrc/scripts/influxdb.service /pkg/usr/lib/influxdb/scripts/influxdb.service
  chmod 0644 /pkg/usr/lib/influxdb/scripts/influxdb.service

  # Copy logrotate script.
  cp /isrc/scripts/logrotate /pkg/etc/logrotate.d/influxdb
  chmod 0644 /pkg/etc/logrotate.d/influxdb

  # Copy sample config.
  cp /isrc/etc/config.sample.toml /pkg/etc/influxdb/influxdb.conf

  # Copy data binaries.
  cp /ibin/* /pkg/usr/bin/

  # Copy man pages.
  cp /isrc/man/*.1.gz /pkg/usr/share/man/man1

  # Make tarball of files in packaging.
  BIN_GZ_NAME="/out/influxdb-${VERSION}_${OS}_${ARCH}.tar.gz"
  if [ "$STATIC" == "1" ]; then
    BIN_GZ_NAME="/out/influxdb-${VERSION}-static_${OS}_${ARCH}.tar.gz"
  fi

  (cd /pkg && tar czf $BIN_GZ_NAME ./*)

  # don't need static install packages.
  if [ "$OS" == "linux" ] && [ "$STATIC" != "1" ]; then
    # Call fpm to build .deb and .rpm packages.
    for typeargs in "-t deb" "-t rpm --depends coreutils"; do
      FPM_NAME=$(
      fpm \
        -s dir \
        $typeargs \
        --log error \
        --vendor InfluxData \
        --url "https://influxdata.com" \
        --after-install /isrc/scripts/post-install.sh \
        --before-install /isrc/scripts/pre-install.sh \
        --after-remove /isrc/scripts/post-uninstall.sh \
        --license Proprietary \
        --maintainer "<EMAIL>" \
        --directories /var/log/influxdb \
        --directories /var/lib/influxdb \
        --description 'Distributed time-series database.' \
        --config-files /etc/influxdb/influxdb.conf \
        --config-files /etc/logrotate.d/influxdb \
        --name "influxdb" \
        --architecture "$ARCH" \
        --version "$VERSION" \
{'fraction_non_alphanumeric': 0.18043818466353678, 'fraction_numerical': 0.008763693270735524, 'mean_word_length': 2.275756022552537, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '369626', 'n_tokens_mistral': 2452, 'n_tokens_neox': 2343, 'n_words': 545}