@@ -25,46 +25,48 @@ if [[ ! -d "${bin_dir}" ]]; then
2525 exit 1
2626fi
2727
28- krew_tar_archive=" krew.tar.gz"
29- krew_exe=" krew.exe"
30-
31- # copy license
32- cp -- " ${SCRIPTDIR} /../LICENSE" " ./${bin_dir} "
33-
34- # create a out/krew.exe convenience copy
35- if [[ -x " ./${bin_dir} /krew-windows_amd64.exe" ]]; then
36- cp -- " ./${bin_dir} /krew-windows_amd64.exe" " ./out/krew.exe"
28+ checksum_cmd=" shasum -a 256"
29+ if hash sha256sum 2> /dev/null; then
30+ checksum_cmd=" sha256sum"
3731fi
32+ checksum_sed=" "
3833
39- # consistent timestamps for files in bindir to ensure consistent checksums
4034while IFS= read -r -d $' \0' f; do
41- echo " modifying atime/mtime for $f "
42- TZ=UTC touch -at " 0001010000" " $f "
43- TZ=UTC touch -mt " 0001010000" " $f "
44- done < <( find " ${bin_dir} " -print0)
35+ archive_dir=" $( mktemp -d) "
36+ cp " $f " " ${archive_dir} "
37+ cp -- " ${SCRIPTDIR} /../LICENSE" " ${archive_dir} "
38+ name=" $( basename " $f " .exe) "
39+ archive=" ${name} .tar.gz"
40+ echo >&2 " Creating ${archive} archive."
41+ (
42+ cd " ${archive_dir} "
43+ # consistent timestamps for files in archive dir to ensure consistent checksums
44+ TZ=UTC touch -t " 0001010000" ./*
45+ tar --use-compress-program " gzip --no-name" -cvf " ${SCRIPTDIR} /../out/${archive} " ./*
46+ )
4547
46- echo >&2 " Creating ${krew_tar_archive} archive."
47- (
48- cd " ${bin_dir} "
49- tar --use-compress-program " gzip --no-name" -cvf " ${SCRIPTDIR} /../out/${krew_tar_archive} " ./*
50- )
48+ # create sumfile
49+ sumfile=" out/${archive} .sha256"
50+ checksum=" $( eval " ${checksum_cmd[@]} " " out/${archive} " | awk ' {print $1;}' ) "
51+ echo >&2 " ${archive} checksum: ${checksum} "
52+ echo " ${checksum} " > " ${sumfile} "
53+ echo >&2 " Written ${sumfile} ."
5154
52- checksum_cmd=" shasum -a 256"
53- if hash sha256sum 2> /dev/null; then
54- checksum_cmd=" sha256sum"
55- fi
55+ # prepare krew manifest sed
56+ checksum_sed=" ${checksum_sed} ;s/$( tr " [[:lower:]-]" " [[:upper:]_]" <<< ${name} ) _CHECKSUM/${checksum} /"
5657
57- tar_sumfile=" out/${krew_tar_archive} .sha256"
58- tar_checksum=" $( eval " ${checksum_cmd[@]} " " out/${krew_tar_archive} " | awk ' {print $1;}' ) "
59- echo >&2 " ${krew_tar_archive} checksum: ${tar_checksum} "
60- echo " ${tar_checksum} " > " ${tar_sumfile} "
61- echo >&2 " Written ${tar_sumfile} ."
58+ done < <( find " ${bin_dir} " -type f -print0)
6259
63- exe_sumfile=" out/krew.exe.sha256"
64- exe_checksum=" $( eval " ${checksum_cmd[@]} " " out/${krew_exe} " | awk ' {print $1;}' ) "
65- echo >&2 " ${krew_exe} checksum: ${exe_checksum} "
66- echo " ${exe_checksum} " > " ${exe_sumfile} "
67- echo >&2 " Written ${exe_sumfile} ."
60+ # create a out/krew.exe convenience copy
61+ if [[ -x " ./${bin_dir} /krew-windows_amd64.exe" ]]; then
62+ krew_exe=" krew.exe"
63+ cp -- " ./${bin_dir} /krew-windows_amd64.exe" " ./out/${krew_exe} "
64+ exe_sumfile=" out/krew.exe.sha256"
65+ exe_checksum=" $( eval " ${checksum_cmd[@]} " " out/${krew_exe} " | awk ' {print $1;}' ) "
66+ echo >&2 " ${krew_exe} checksum: ${exe_checksum} "
67+ echo " ${exe_checksum} " > " ${exe_sumfile} "
68+ echo >&2 " Written ${exe_sumfile} ."
69+ fi
6870
6971# Copy and process krew manifest
7072git_describe=" $( git describe --tags --dirty --always) "
@@ -74,7 +76,5 @@ if [[ ! "${git_describe}" =~ v.* ]]; then
7476 git_describe=" v0.0.0-detached+${git_describe} "
7577fi
7678krew_version=" ${TAG_NAME:- $git_describe } "
77- cp ./hack/krew.yaml ./out/krew.yaml
78- sed -i " s/KREW_TAR_CHECKSUM/${tar_checksum} /g" ./out/krew.yaml
79- sed -i " s/KREW_TAG/${krew_version} /g" ./out/krew.yaml
79+ sed " ${checksum_sed} ;s/KREW_TAG/${krew_version} /g" ./hack/krew.yaml > ./out/krew.yaml
8080echo >&2 " Written out/krew.yaml."
0 commit comments