github.com/safing/portbase@v0.19.5/build (about)

     1  #!/bin/bash
     2  
     3  # get build data
     4  if [[ "$BUILD_COMMIT" == "" ]]; then
     5    BUILD_COMMIT=$(git describe --all --long --abbrev=99 --dirty 2>/dev/null)
     6  fi
     7  if [[ "$BUILD_USER" == "" ]]; then
     8    BUILD_USER=$(id -un)
     9  fi
    10  if [[ "$BUILD_HOST" == "" ]]; then
    11    BUILD_HOST=$(hostname -f)
    12  fi
    13  if [[ "$BUILD_DATE" == "" ]]; then
    14    BUILD_DATE=$(date +%d.%m.%Y)
    15  fi
    16  if [[ "$BUILD_SOURCE" == "" ]]; then
    17    BUILD_SOURCE=$(git remote -v | grep origin | cut -f2 | cut -d" " -f1 | head -n 1)
    18  fi
    19  if [[ "$BUILD_SOURCE" == "" ]]; then
    20    BUILD_SOURCE=$(git remote -v | cut -f2 | cut -d" " -f1 | head -n 1)
    21  fi
    22  BUILD_BUILDOPTIONS=$(echo $* | sed "s/ /ยง/g")
    23  
    24  # check
    25  if [[ "$BUILD_COMMIT" == "" ]]; then
    26    echo "could not automatically determine BUILD_COMMIT, please supply manually as environment variable."
    27    exit 1
    28  fi
    29  if [[ "$BUILD_USER" == "" ]]; then
    30    echo "could not automatically determine BUILD_USER, please supply manually as environment variable."
    31    exit 1
    32  fi
    33  if [[ "$BUILD_HOST" == "" ]]; then
    34    echo "could not automatically determine BUILD_HOST, please supply manually as environment variable."
    35    exit 1
    36  fi
    37  if [[ "$BUILD_DATE" == "" ]]; then
    38    echo "could not automatically determine BUILD_DATE, please supply manually as environment variable."
    39    exit 1
    40  fi
    41  if [[ "$BUILD_SOURCE" == "" ]]; then
    42    echo "could not automatically determine BUILD_SOURCE, please supply manually as environment variable."
    43    exit 1
    44  fi
    45  
    46  echo "Please notice, that this build script includes metadata into the build."
    47  echo "This information is useful for debugging and license compliance."
    48  echo "Run the compiled binary with the -version flag to see the information included."
    49  
    50  # build
    51  BUILD_PATH="github.com/safing/portbase/info"
    52  go build -ldflags "-X ${BUILD_PATH}.commit=${BUILD_COMMIT} -X ${BUILD_PATH}.buildOptions=${BUILD_BUILDOPTIONS} -X ${BUILD_PATH}.buildUser=${BUILD_USER} -X ${BUILD_PATH}.buildHost=${BUILD_HOST} -X ${BUILD_PATH}.buildDate=${BUILD_DATE} -X ${BUILD_PATH}.buildSource=${BUILD_SOURCE}" $@