Skip to content

Instantly share code, notes, and snippets.

@Stebalien
Created January 16, 2019 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stebalien/7bfd1ea07f81c1fbbe9eadac4faeccd3 to your computer and use it in GitHub Desktop.
Save Stebalien/7bfd1ea07f81c1fbbe9eadac4faeccd3 to your computer and use it in GitHub Desktop.
#!/bin/bash
export IPFS_GATEWAY="${IPFS_GATEWAY:-http://127.0.0.1:8080}"
CACHE_DIR="$(go env GOPATH)/pkg/mod/cache"
basepath() {
echo "${1##${CACHE_DIR}/download/}"
}
case "$1" in
ipfs-lock)
export GO111MODULE=on
temp="$(mktemp -d "$CACHE_DIR/.tmpXXXXXXXXX")"
trap 'rm -rf "$temp"' 0
go mod download -json > "$temp/info.json"
jq -r '"VERSION=\(.Version | @sh) INFO=\(.Info | @sh) GOMOD=\(.GoMod | @sh) ZIP=\(.Zip | @sh)"' < "$temp/info.json" \
| while read line; do
eval "$line"
echo $INFO
base="$(dirname "${temp}/bundle/$(basepath "$INFO")")"
mkdir -p "$base"
ln -t "$base" "$INFO" "$GOMOD" "$ZIP"
echo "$VERSION" > "$base/list"
done
HASH="$(ipfs add -Qr "$temp/bundle")"
echo "/ipfs/$HASH" > deps.ipfs
;;
*)
if [[ -e "deps.ipfs" ]]; then
path="$(< deps.ipfs)"
export GOPROXY="${IPFS_GATEWAY}$path"
export GO111MODULE=on
fi
exec go "${@}"
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment