Skip to content

Commit

Permalink
fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
ethernetdan committed Sep 29, 2023
1 parent 29604bf commit d44322f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
58 changes: 35 additions & 23 deletions scripts/get.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,32 @@ set -euo pipefail
SUMS="$(dirname "$(readlink -f "$0")")/get.sha256"
OUTDIR="$(dirname "$(readlink -f "$0")")/../_proto"

arch="$(uname -m)"
kernel="$(uname -s)"
kernelLower="$(tr '[:upper:]' '[:lower:]' <<< "$kernel")"

os="$kernelLower"
if [[ "$kernelLower" == "darwin" ]]; then
os="osx"
fi

# write to temp file and cleanup later
tmpDir="$(mktemp -d)"
function cleanup() {
rm -rf ${tmpDir}
rm -rf "$tmpDir"
}
trap cleanup EXIT

function main() {
local arch
local kernel
local kernelLower
local os

for name in "$@"; do
# computing environment
arch="$(uname -m)"
kernel="$(uname -s)"
kernelLower="$(tr '[:upper:]' '[:lower:]' <<< "$kernel")"

os="$kernelLower"
if [[ "$kernelLower" == "darwin" ]]; then
os="osx"
fi

# install
mkdir -p "$OUTDIR"
case $name in
buf)
version=1.26.1
Expand Down Expand Up @@ -52,13 +60,16 @@ function main() {
if [[ "$kernelLower" == "darwin" ]]; then
os="darwin"
fi
if [[ "$arch" == "x86_64" ]]; then
arch="amd64"
fi

version=v1.31.0
target="protoc-gen-go.${version}.${os}.${arch}.tar.gz"
url="https://github.com/protocolbuffers/protobuf-go/releases/download/${version}/${target}"
download "$url" "$tmpDir/$target"

tar xvf "$tmpDir/$target" -C "${OUTDIR}" protoc-gen-go
tar xvf "$tmpDir/$target" -C "$OUTDIR" protoc-gen-go
;;

*)
Expand All @@ -68,7 +79,6 @@ function main() {

esac
echo "got ${name}!"

done
}

Expand All @@ -81,28 +91,28 @@ function download() {
exit 3
elif [[ -f ${dst} ]]; then
# check if already have copy
check ${dst} && exit 0
check "$dst" && exit 0
fi

echo "Downloading ${url}..."
curl -L -o ${dst} "${url}"
curl -L -o "$dst" "$url"

echo "Verifying checksum of ${dst}"
check ${dst} || (echo "Failed checksum!" && exit 2)
check "$dst" || (echo "Failed checksum!" && exit 2)
echo "Checksum passed!"
}

function check() {
local target="${1}"
local checksum=$(grep $(basename ${target}) ${SUMS})
local checksum
checksum=$(grep "$(basename "$target")" "$SUMS")

# if no checksum provided, add to file
if [[ -z ${checksum} ]]; then
checksum=$(cd $(dirname ${target}) && sha256sum $(basename ${target}))
checksum=$(cd "$(dirname "$target")" && sha256sum "$(basename "$target")")

if [[ -t 0 ]]; then
printf "Checksum not found for ${target}.\nChecksum: ${checksum}\n"
read -p "Do you want to add it? (Y/n) " response
printf "Checksum not found for %s.\nChecksum: %s\n" "$target" "$checksum"
read -r -p "Do you want to add it? (Y/n) " response
case ${response} in
[nN]|[nN][oO]) return 3 ;;
esac
Expand All @@ -111,11 +121,13 @@ function check() {
fi

echo "Adding checksum: ${checksum}"
local newSums=$(echo ${checksum} | cat ${SUMS} - | sort -k2 | uniq)
echo "${newSums}" > ${SUMS}
local newSums
newSums=$(echo "$checksum" | cat "$SUMS" - | sort -k2 | uniq)
echo "$newSums" > "$SUMS"
fi

cd $(dirname ${target}) && sha256sum --check --status <<< "${checksum}"
echo "Verifying ${checksum}"
cd "$(dirname "$target")" && sha256sum --check --status <<< "$checksum"
}

main "$@"
2 changes: 1 addition & 1 deletion scripts/get.sha256
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
673aabfc7f9a15281fb2ac1d1a51919928c0f397a32e2723b017997ea9bbe2ab buf-Darwin-arm64
cc317bbc69af962ebad09ee415dc61f6792784bffbd0a1d6d80246ae7a7e93fc buf-Linux-x86_64
fc793561283d9ea6813fb757ae54f1afea6770afcd930904bdf3e590910420aa protoc-24.3-Linux-x86_64.zip
fc793561283d9ea6813fb757ae54f1afea6770afcd930904bdf3e590910420aa protoc-24.3-linux-x86_64.zip
cca53adb73a6686dd60bb3b0da33961e6b9dab1f833c851b5e1bb7b5df02b36f protoc-24.3-osx-aarch_64.zip
c01ab747f9decfb9bc300c8506a8e741d35dc45860cbf3950c752572129b2139 protoc-gen-go.v1.31.0.darwin.arm64.tar.gz
04414c31a3af6f908d4359ff12a02f7ef864417978e303ccc62053af536ae13c protoc-gen-go.v1.31.0.linux.amd64.tar.gz

0 comments on commit d44322f

Please sign in to comment.