Commit 74a5cb2f authored by W-Mark Kubacki's avatar W-Mark Kubacki

Convert the barbarism in dist/automate.sh to proper BASH structure

    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.
parent ba2e9d80
*.bash text eol=lf whitespace=blank-at-eol,space-before-tab,tab-in-indent,trailing-space,tabwidth=2 *.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 # files for systemd
*.path text eol=lf whitespace=blank-at-eol,space-before-tab,tab-in-indent,trailing-space,tabwidth=2 *.path text eol=lf whitespace=blank-at-eol,space-before-tab,tab-in-indent,trailing-space,tabwidth=2
......
...@@ -9,9 +9,9 @@ ...@@ -9,9 +9,9 @@
# Outputs compiled program in current directory. # Outputs compiled program in current directory.
# Default file name is 'ecaddy'. # Default file name is 'ecaddy'.
set -e set -euo pipefail
: ${output_filename:="$1"} : ${output_filename:="${1:-}"}
: ${output_filename:="ecaddy"} : ${output_filename:="ecaddy"}
pkg=main pkg=main
......
#!/usr/bin/env bash #!/usr/bin/env bash
set -e
set -o pipefail set -euo pipefail
shopt -s nullglob # if no files match glob, assume empty list instead of string literal # if no files match glob, assume empty list instead of string literal
shopt -s nullglob
## PACKAGE TO BUILD : ${build_package:="github.com/mholt/caddy"}
Package=github.com/mholt/caddy
: ${dist_dir:="${GOPATH}/src/${build_package}/dist"}
: ${build_dir:="${dist_dir}/builds"}
## PATHS TO USE : ${target_dir:="${dist_dir}/release"}
DistDir=$GOPATH/src/$Package/dist
BuildDir=$DistDir/builds # Bundles a single binary, given as first parameter, into an archive.
ReleaseDir=$DistDir/release package() {
# Binary inside the zip file is simply the project name
binbase="$(basename "${build_package}")"
## BEGIN if [[ "${1}" == *.exe ]]; then
binbase+=".exe"
# Compile binaries fi
mkdir -p $BuildDir bin="${build_dir}/${binbase}"
cd $BuildDir
rm -f caddy* # Name .zip file same as binary, but strip .exe from end
gox $Package zipname="$(basename "${1%.exe}")"
case "$(printf "${zipname}" | cut -d '_' -f 2 | sed -e 's:[a-z]*bsd:bsd:')" in
# Zip them up with release notes and stuff linux|bsd) zipname+=".tar.gz" ;;
mkdir -p $ReleaseDir *) zipname+=".zip" ;;
cd $ReleaseDir esac
rm -f caddy*
for f in $BuildDir/* # Compress distributable depending on extension
do case "${zipname##*.}" in
# Name .zip file same as binary, but strip .exe from end zip)
zipname=$(basename ${f%".exe"}) zip -j "${target_dir}/${zipname}" \
if [[ $f == *"linux"* ]] || [[ $f == *"bsd"* ]]; then "${1}" \
zipname=${zipname}.tar.gz "${dist_dir}"/{CHANGES.txt,LICENSES.txt,README.txt}
else printf "@ $(basename "${1}")\n@=${binbase}\n" \
zipname=${zipname}.zip | zipnote -w "${target_dir}/${zipname}"
fi ;;
gz)
# Binary inside the zip file is simply the project name tar -caf "${target_dir}/${zipname}" \
binbase=$(basename $Package) --owner=0 --group=0 \
if [[ $f == *.exe ]]; then --transform="s#$(basename "${1}")#${binbase}#" \
binbase=$binbase.exe -C "$(dirname "${1}")" "$(basename "${1}")" \
fi -C "${dist_dir}" CHANGES.txt LICENSES.txt README.txt
bin=$BuildDir/$binbase ;;
mv $f $bin esac
}
# Compress distributable
if [[ $zipname == *.zip ]]; then prepare_directories() {
zip -j $zipname $bin $DistDir/CHANGES.txt $DistDir/LICENSES.txt $DistDir/README.txt mkdir -p "${build_dir}"
else rm -f "${build_dir}"/caddy*
tar -cvzf $zipname -C $BuildDir $binbase -C $DistDir CHANGES.txt LICENSES.txt README.txt
fi mkdir -p "${target_dir}"
rm -f "${target_dir}"/caddy*
# Put binary filename back to original }
mv $bin $f
done 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment