1#!/bin/bash 2 3function printHelp() { 4 >&2 echo "USAGE: $0 -s INFLUXDB_SHA -b INFLUXDB_BRANCH -v INFLUXDB_VERSION 5 6Emits a tarball of influxdb source code and dependencies to /out, 7which must be a mounted volume if you want to access the file. 8 9If the directory /influxdb-git exists and is mounted, 10that will be used as the git repository used when cloning influxdb. 11" 12} 13 14if [ $# -eq 0 ]; then 15 printHelp 16 exit 1 17fi 18 19SHA="" 20BRANCH="" 21VERSION="" 22 23while getopts hs:b:v: arg; do 24 case "$arg" in 25 h) printHelp; exit 1;; 26 s) SHA="$OPTARG";; 27 b) BRANCH="$OPTARG";; 28 v) VERSION="$OPTARG";; 29 esac 30done 31 32if [ -z "$SHA" ] || [ -z "$BRANCH" ] || [ -z "$VERSION" ]; then 33 printHelp 34 exit 1 35fi 36 37IPATH=/go/src/github.com/influxdata 38mkdir -p "$IPATH" && cd "$IPATH" 39if [ -d /influxdb-git ]; then 40 git clone /influxdb-git "$IPATH/influxdb" 41else 42 43 git clone https://github.com/influxdata/influxdb.git 44fi 45 46cd influxdb 47git checkout "$SHA" 48dep ensure -vendor-only 49cd .. 50 51# Emit version metadata to appropriate files. 52 53# Include machine-parseable metadata JSON file. 54printf '{ 55"version": "%s", 56"branch": "%s", 57"sha": "%s" 58}' "$VERSION" "$BRANCH" "$SHA" > "./influxdb/.metadata.json" 59 60# Set version info for influxdb binaries. 61 62printf 'package main 63 64// Code generated by influxdata/releng tooling. DO NOT EDIT. 65 66func init() { 67 version = "%s" 68 branch = "%s" 69 commit = "%s" 70}' "$VERSION" "$BRANCH" "$SHA" > "./influxdb/cmd/influxd/version.generated.go" 71 72 73# influx uses just version. 74printf 'package main 75 76// Code generated by influxdata/releng tooling. DO NOT EDIT. 77 78 func init() { 79 version = "%s" 80}' "$VERSION" > "./influxdb/cmd/influx/version.generated.go" 81 82# Prebuild the man pages so that consumers of the source tarball don't have to build it themselves. 83(cd /go/src/github.com/influxdata/influxdb/man && make build && gzip -9 ./*.1) 84 85TARBALL_NAME="influxdb-src-$SHA.tar.gz" 86(cd /go && tar czf "/out/$TARBALL_NAME" --exclude-vcs ./*) # --exclude-vcs is a GNU tar option. 87(cd /out && md5sum "$TARBALL_NAME" > "$TARBALL_NAME.md5") 88(cd /out && sha256sum "$TARBALL_NAME" > "$TARBALL_NAME.sha256") 89