Skip to content

Instantly share code, notes, and snippets.

@anacrolix
Forked from Stebalien/ipgo.sh
Last active February 28, 2019 18:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anacrolix/14e776bc5a7a5fb3f5c4035ab0c41a9b to your computer and use it in GitHub Desktop.
Save anacrolix/14e776bc5a7a5fb3f5c4035ab0c41a9b to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eu
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/}"
}
sed=`type gsed 2>&1 > /dev/null && echo gsed || echo sed`
cleanpath() {
echo "$1" | "$sed" 's/[A-Z]/!\L&/g'
}
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) modpath=\(.Path | @sh)"' < "$temp/info.json" \
| while read line; do
eval "$line"
echo bundling $modpath/$VERSION
base="$(dirname "${temp}/bundle/$(basepath "$INFO")")"
mkdir -p "$base"
ln -t "$base" "$INFO" "$GOMOD" "$ZIP"
echo "$VERSION" >> "$base/list"
done
go mod graph | while read _ dep; do
IFS="@" read name ver<<<"$dep"
name="$(cleanpath "$name")"
base="$temp/bundle/$name/@v/"
mkdir -p "$base"
ln -t "$base" "$CACHE_DIR/download/$name/@v/$ver".{info,mod} 2> /dev/null && echo adding info for $name/$ver || true
done
du -hs "$temp/bundle"
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