From 6e33d2aa9e5d5cda2595fe53c9e02e07af331db8 Mon Sep 17 00:00:00 2001 From: borduase Date: Sun, 21 Feb 2021 05:30:40 -0800 Subject: [PATCH] do.sh: Changes the shebang to: /usr/bin/env bash since in FreeBSD bash 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. --- do.sh | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/do.sh b/do.sh index a0dbb97a..c98b017d 100755 --- a/do.sh +++ b/do.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e # change dir to where this script is running @@ -18,6 +18,31 @@ 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 } @@ -25,7 +50,7 @@ run () { 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}" .