mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-30 22:34:15 -05: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.
78 lines
2 KiB
Bash
Executable file
78 lines
2 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
# if no files match glob, assume empty list instead of string literal
|
|
shopt -s nullglob
|
|
|
|
: ${build_package:="github.com/mholt/caddy"}
|
|
|
|
: ${dist_dir:="${GOPATH}/src/${build_package}/dist"}
|
|
: ${build_dir:="${dist_dir}/builds"}
|
|
: ${target_dir:="${dist_dir}/release"}
|
|
|
|
# Bundles a single binary, given as first parameter, into an archive.
|
|
package() {
|
|
# Binary inside the zip file is simply the project name
|
|
binbase="$(basename "${build_package}")"
|
|
if [[ "${1}" == *.exe ]]; then
|
|
binbase+=".exe"
|
|
fi
|
|
bin="${build_dir}/${binbase}"
|
|
|
|
# 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
|
|
|
|
# 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
|