Skip to content

Commit

Permalink
do.sh: Changes the shebang to: /usr/bin/env bash since in FreeBSD bas…
Browse files Browse the repository at this point in the history
…h is found at /usr/local/bin/bash. See this post on stackoverflow for more details. https://stackoverflow.com/questions/16365130/what-is-the-difference-between-usr-bin-env-bash-and-usr-bin-bash

do.sh  Added the function Hostname() to hide the detail of querying for a host's fully-qualified domain name since how this is done can vary based on the OS.
  • Loading branch information
borduase committed Feb 21, 2021
1 parent 4e10aee commit 6e33d2a
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions do.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -e

# change dir to where this script is running
Expand All @@ -18,14 +18,39 @@ NAME=vouch-proxy
HTTPPORT=9090
GODOC_PORT=5050

#--YetAnotherBugHunter 02/20/21
#-- Added function Hostname() to hide
#-- the detail of querying for a host's
#-- fully-qualified domain name since how
#-- this is done can vary based on the OS.

Hostname() {
local FQDN
local HOSTNAME_CMD

case $(uname) in
FreeBSD) HOSTNAME_CMD="hostname";;
*) HOSTNAME_CMD="hostname --fqdn"
esac

FQDN=$($HOSTNAME_CMD)
#-- Can't test against $? since the assignment to FQDN always succeeds even if $HOSTNAME_CMD fails.
if [ "$FQDN" = "" ]; then
>&2 echo "error: Could determine the fully qualified domain name using command $HOSTNAME_CMD"
return 1
fi
echo $FQDN
return 0;
}

run () {
go run main.go
}

build () {
local VERSION=$(git describe --always --long)
local DT=$(date -u +"%Y-%m-%dT%H:%M:%SZ") # ISO-8601
local FQDN=$(hostname --fqdn)
local FQDN=$(Hostname)
local SEMVER=$(git tag --list --sort="v:refname" | tail -n -1)
local BRANCH=$(git rev-parse --abbrev-ref HEAD)
go build -i -v -ldflags=" -X main.version=${VERSION} -X main.builddt=${DT} -X main.host=${FQDN} -X main.semver=${SEMVER} -X main.branch=${BRANCH}" .
Expand Down

0 comments on commit 6e33d2a

Please sign in to comment.