mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-11-04 03:27:23 -05:00 
			
		
		
		
	
						commit
						0aacaea918
					
				
							
								
								
									
										3
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
								
							@ -1,3 +1,6 @@
 | 
			
		||||
*.bash    text eol=lf whitespace=blank-at-eol,space-before-tab,tab-in-indent,trailing-space,tabwidth=2
 | 
			
		||||
*.sh      text eol=lf whitespace=blank-at-eol,space-before-tab,tab-in-indent,trailing-space,tabwidth=2
 | 
			
		||||
 | 
			
		||||
# files for systemd
 | 
			
		||||
*.path    text eol=lf whitespace=blank-at-eol,space-before-tab,tab-in-indent,trailing-space,tabwidth=2
 | 
			
		||||
*.service text eol=lf whitespace=blank-at-eol,space-before-tab,tab-in-indent,trailing-space,tabwidth=2
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										56
									
								
								build.bash
									
									
									
									
									
								
							
							
						
						
									
										56
									
								
								build.bash
									
									
									
									
									
								
							@ -8,48 +8,48 @@
 | 
			
		||||
#
 | 
			
		||||
# Outputs compiled program in current directory.
 | 
			
		||||
# Default file name is 'ecaddy'.
 | 
			
		||||
#
 | 
			
		||||
set -e
 | 
			
		||||
 | 
			
		||||
output="$1"
 | 
			
		||||
if [ -z "$output" ]; then
 | 
			
		||||
	output="ecaddy"
 | 
			
		||||
fi
 | 
			
		||||
set -euo pipefail
 | 
			
		||||
 | 
			
		||||
: ${output_filename:="${1:-}"}
 | 
			
		||||
: ${output_filename:="ecaddy"}
 | 
			
		||||
 | 
			
		||||
pkg=main
 | 
			
		||||
ldflags=()
 | 
			
		||||
 | 
			
		||||
# Timestamp of build
 | 
			
		||||
builddate_id=$pkg.buildDate
 | 
			
		||||
builddate=`date -u`
 | 
			
		||||
name="${pkg}.buildDate"
 | 
			
		||||
value=$(date --utc +"%F %H:%M:%SZ")
 | 
			
		||||
ldflags+=("-X" "\"${name}=${value}\"")
 | 
			
		||||
 | 
			
		||||
# Current tag, if HEAD is on a tag
 | 
			
		||||
tag_id=$pkg.gitTag
 | 
			
		||||
name="${pkg}.gitTag"
 | 
			
		||||
set +e
 | 
			
		||||
tag=`git describe --exact-match HEAD 2> /dev/null`
 | 
			
		||||
value="$(git describe --exact-match HEAD 2>/dev/null)"
 | 
			
		||||
set -e
 | 
			
		||||
ldflags+=("-X" "\"${name}=${value}\"")
 | 
			
		||||
 | 
			
		||||
# Nearest tag on branch
 | 
			
		||||
lasttag_id=$pkg.gitNearestTag
 | 
			
		||||
lasttag=`git describe --abbrev=0 --tags HEAD`
 | 
			
		||||
name="${pkg}.gitNearestTag"
 | 
			
		||||
value="$(git describe --abbrev=0 --tags HEAD)"
 | 
			
		||||
ldflags+=("-X" "\"${name}=${value}\"")
 | 
			
		||||
 | 
			
		||||
# Commit SHA
 | 
			
		||||
commit_id=$pkg.gitCommit
 | 
			
		||||
commit=`git rev-parse --short HEAD`
 | 
			
		||||
name="${pkg}.gitCommit"
 | 
			
		||||
value="$(git rev-parse --short HEAD)"
 | 
			
		||||
ldflags+=("-X" "\"${name}=${value}\"")
 | 
			
		||||
 | 
			
		||||
# Summary of uncommited changes
 | 
			
		||||
shortstat_id=$pkg.gitShortStat
 | 
			
		||||
shortstat=`git diff-index --shortstat HEAD`
 | 
			
		||||
# Summary of uncommitted changes
 | 
			
		||||
name="${pkg}.gitShortStat"
 | 
			
		||||
value="$(git diff-index --shortstat HEAD)"
 | 
			
		||||
ldflags+=("-X" "\"${name}=${value}\"")
 | 
			
		||||
 | 
			
		||||
# List of modified files
 | 
			
		||||
files_id=$pkg.gitFilesModified
 | 
			
		||||
files=`git diff-index --name-only HEAD`
 | 
			
		||||
name="${pkg}.gitFilesModified"
 | 
			
		||||
value="$(git diff-index --name-only HEAD | tr "\n" "," | sed -e 's:,$::')"
 | 
			
		||||
ldflags+=("-X" "\"${name}=${value}\"")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
go build -ldflags "
 | 
			
		||||
	-X \"$builddate_id=$builddate\"
 | 
			
		||||
	-X \"$tag_id=$tag\"
 | 
			
		||||
	-X \"$lasttag_id=$lasttag\"
 | 
			
		||||
	-X \"$commit_id=$commit\"
 | 
			
		||||
	-X \"$shortstat_id=$shortstat\"
 | 
			
		||||
	-X \"$files_id=$files\"
 | 
			
		||||
" -o "$output"
 | 
			
		||||
set -x
 | 
			
		||||
go build \
 | 
			
		||||
  -ldflags "${ldflags[*]}" \
 | 
			
		||||
  -o "${output_filename}"
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										116
									
								
								dist/automate.sh
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										116
									
								
								dist/automate.sh
									
									
									
									
										vendored
									
									
								
							@ -1,56 +1,78 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
set -e
 | 
			
		||||
set -o pipefail
 | 
			
		||||
shopt -s nullglob # if no files match glob, assume empty list instead of string literal
 | 
			
		||||
 | 
			
		||||
set -euo pipefail
 | 
			
		||||
# if no files match glob, assume empty list instead of string literal
 | 
			
		||||
shopt -s nullglob
 | 
			
		||||
 | 
			
		||||
## PACKAGE TO BUILD
 | 
			
		||||
Package=github.com/mholt/caddy
 | 
			
		||||
: ${build_package:="github.com/mholt/caddy"}
 | 
			
		||||
 | 
			
		||||
: ${dist_dir:="${GOPATH}/src/${build_package}/dist"}
 | 
			
		||||
: ${build_dir:="${dist_dir}/builds"}
 | 
			
		||||
: ${target_dir:="${dist_dir}/release"}
 | 
			
		||||
 | 
			
		||||
## PATHS TO USE
 | 
			
		||||
DistDir=$GOPATH/src/$Package/dist
 | 
			
		||||
BuildDir=$DistDir/builds
 | 
			
		||||
ReleaseDir=$DistDir/release
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## BEGIN
 | 
			
		||||
 | 
			
		||||
# Compile binaries
 | 
			
		||||
mkdir -p $BuildDir
 | 
			
		||||
cd $BuildDir
 | 
			
		||||
rm -f caddy*
 | 
			
		||||
gox $Package
 | 
			
		||||
 | 
			
		||||
# Zip them up with release notes and stuff
 | 
			
		||||
mkdir -p $ReleaseDir
 | 
			
		||||
cd $ReleaseDir
 | 
			
		||||
rm -f caddy*
 | 
			
		||||
for f in $BuildDir/*
 | 
			
		||||
do
 | 
			
		||||
	# Name .zip file same as binary, but strip .exe from end
 | 
			
		||||
	zipname=$(basename ${f%".exe"})
 | 
			
		||||
	if [[ $f == *"linux"* ]] || [[ $f == *"bsd"* ]]; then
 | 
			
		||||
		zipname=${zipname}.tar.gz
 | 
			
		||||
	else
 | 
			
		||||
		zipname=${zipname}.zip
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
# Bundles a single binary, given as first parameter, into an archive.
 | 
			
		||||
package() {
 | 
			
		||||
  # Binary inside the zip file is simply the project name
 | 
			
		||||
	binbase=$(basename $Package)
 | 
			
		||||
	if [[ $f == *.exe ]]; then
 | 
			
		||||
		binbase=$binbase.exe
 | 
			
		||||
  binbase="$(basename "${build_package}")"
 | 
			
		||||
  if [[ "${1}" == *.exe ]]; then
 | 
			
		||||
    binbase+=".exe"
 | 
			
		||||
  fi
 | 
			
		||||
	bin=$BuildDir/$binbase
 | 
			
		||||
	mv $f $bin
 | 
			
		||||
  bin="${build_dir}/${binbase}"
 | 
			
		||||
 | 
			
		||||
	# Compress distributable
 | 
			
		||||
	if [[ $zipname == *.zip ]]; then
 | 
			
		||||
		zip -j $zipname $bin $DistDir/CHANGES.txt $DistDir/LICENSES.txt $DistDir/README.txt
 | 
			
		||||
	else
 | 
			
		||||
		tar -cvzf $zipname -C $BuildDir $binbase -C $DistDir CHANGES.txt LICENSES.txt README.txt
 | 
			
		||||
	fi
 | 
			
		||||
  # Name .zip file same as binary, but strip .exe from end
 | 
			
		||||
  zipname="$(basename "${1%.exe}")"
 | 
			
		||||
  case "$(printf "${zipname}" | cut -d '_' -f 2 | sed -e 's:[a-z]*bsd:bsd:')" in
 | 
			
		||||
    linux|bsd) zipname+=".tar.gz" ;;
 | 
			
		||||
    *)         zipname+=".zip" ;;
 | 
			
		||||
  esac
 | 
			
		||||
 | 
			
		||||
	# Put binary filename back to original
 | 
			
		||||
	mv $bin $f
 | 
			
		||||
done
 | 
			
		||||
  # Compress distributable depending on extension
 | 
			
		||||
  case "${zipname##*.}" in
 | 
			
		||||
    zip)
 | 
			
		||||
      zip -j "${target_dir}/${zipname}" \
 | 
			
		||||
        "${1}" \
 | 
			
		||||
        "${dist_dir}"/{CHANGES.txt,LICENSES.txt,README.txt}
 | 
			
		||||
      printf "@ $(basename "${1}")\n@=${binbase}\n" \
 | 
			
		||||
      | zipnote -w "${target_dir}/${zipname}"
 | 
			
		||||
      ;;
 | 
			
		||||
    gz)
 | 
			
		||||
      tar -caf "${target_dir}/${zipname}" \
 | 
			
		||||
        --owner=0 --group=0 \
 | 
			
		||||
        --transform="s#$(basename "${1}")#${binbase}#" \
 | 
			
		||||
        -C "$(dirname "${1}")" "$(basename "${1}")" \
 | 
			
		||||
        -C "${dist_dir}" CHANGES.txt LICENSES.txt README.txt
 | 
			
		||||
      ;;
 | 
			
		||||
  esac
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
prepare_directories() {
 | 
			
		||||
  mkdir -p "${build_dir}"
 | 
			
		||||
  rm -f "${build_dir}"/caddy*
 | 
			
		||||
 | 
			
		||||
  mkdir -p "${target_dir}"
 | 
			
		||||
  rm -f "${target_dir}"/caddy*
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
compile_binaries() {
 | 
			
		||||
  (cd "${build_dir}"; gox "${build_package}")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
if [[ "${1:-}" == "" ]]; then
 | 
			
		||||
  prepare_directories
 | 
			
		||||
  compile_binaries
 | 
			
		||||
 | 
			
		||||
  case "${OSTYPE}" in
 | 
			
		||||
    linux*)
 | 
			
		||||
      find "${build_dir}" -type f -executable -print0 \
 | 
			
		||||
      | xargs --null --max-args=1 --max-procs=$(nproc --ignore=1) -I '{}' \
 | 
			
		||||
        "${0}" package '{}'
 | 
			
		||||
      ;;
 | 
			
		||||
    *)
 | 
			
		||||
      while read f; do
 | 
			
		||||
        package "${f}"
 | 
			
		||||
      done < <(ls -1 "${build_dir}"/caddy*)
 | 
			
		||||
      ;;
 | 
			
		||||
  esac
 | 
			
		||||
else
 | 
			
		||||
  ${1} "${2}"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user