mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-26 02:09:47 +08:00
74a5cb2fe3
When thy variables henceforth accept blessed white-space, guided will thy scripture be along righteous path(s). -- 4 BASH 3:42 Caddy's dist files sometimes ended up being owned by matt:staff or other quite arcane and/or frightening names. If someone extracting didn't pay attention a regular user who happened to have same uid by accident could later tamper with the files' contents. It's 0:0 from now on. Use all available threads when packaging distributables Caddy binaries will be added to their archives in-place: This change eliminates them being renamed within dist/builds one after another. As does 'gox', dist/automate.sh will spare one available thread if possible.
56 lines
1.2 KiB
Bash
Executable File
56 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Caddy build script. Automates proper versioning.
|
|
#
|
|
# Usage:
|
|
#
|
|
# $ ./build.bash [output_filename]
|
|
#
|
|
# Outputs compiled program in current directory.
|
|
# Default file name is 'ecaddy'.
|
|
|
|
set -euo pipefail
|
|
|
|
: ${output_filename:="${1:-}"}
|
|
: ${output_filename:="ecaddy"}
|
|
|
|
pkg=main
|
|
ldflags=()
|
|
|
|
# Timestamp of build
|
|
name="${pkg}.buildDate"
|
|
value=$(date --utc +"%F %H:%M:%SZ")
|
|
ldflags+=("-X" "\"${name}=${value}\"")
|
|
|
|
# Current tag, if HEAD is on a tag
|
|
name="${pkg}.gitTag"
|
|
set +e
|
|
value="$(git describe --exact-match HEAD 2>/dev/null)"
|
|
set -e
|
|
ldflags+=("-X" "\"${name}=${value}\"")
|
|
|
|
# Nearest tag on branch
|
|
name="${pkg}.gitNearestTag"
|
|
value="$(git describe --abbrev=0 --tags HEAD)"
|
|
ldflags+=("-X" "\"${name}=${value}\"")
|
|
|
|
# Commit SHA
|
|
name="${pkg}.gitCommit"
|
|
value="$(git rev-parse --short HEAD)"
|
|
ldflags+=("-X" "\"${name}=${value}\"")
|
|
|
|
# Summary of uncommitted changes
|
|
name="${pkg}.gitShortStat"
|
|
value="$(git diff-index --shortstat HEAD)"
|
|
ldflags+=("-X" "\"${name}=${value}\"")
|
|
|
|
# List of modified files
|
|
name="${pkg}.gitFilesModified"
|
|
value="$(git diff-index --name-only HEAD | tr "\n" "," | sed -e 's:,$::')"
|
|
ldflags+=("-X" "\"${name}=${value}\"")
|
|
|
|
set -x
|
|
go build \
|
|
-ldflags "${ldflags[*]}" \
|
|
-o "${output_filename}"
|