mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-29 01:12:24 +08:00
Merge pull request #2584 from ipfs/fix/build-process
add a dist_get script for getting bins from dist.ipfs.io
This commit is contained in:
@ -14,7 +14,6 @@ env:
|
|||||||
- TEST_NO_FUSE=1 TEST_VERBOSE=1 TEST_SUITE=test_sharness_expensive
|
- TEST_NO_FUSE=1 TEST_VERBOSE=1 TEST_SUITE=test_sharness_expensive
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- make toolkit_upgrade
|
|
||||||
- make install
|
- make install
|
||||||
|
|
||||||
script:
|
script:
|
||||||
|
30
Makefile
30
Makefile
@ -9,6 +9,12 @@ else
|
|||||||
go_test=go test
|
go_test=go test
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
gx_bin=bin/gx-v0.7.0
|
||||||
|
gx-go_bin=bin/gx-go-v1.2.0
|
||||||
|
|
||||||
|
# use things in our bin before any other system binaries
|
||||||
|
export PATH := bin:$(PATH)
|
||||||
export IPFS_API ?= v04x.ipfs.io
|
export IPFS_API ?= v04x.ipfs.io
|
||||||
|
|
||||||
all: help
|
all: help
|
||||||
@ -21,21 +27,25 @@ toolkit_upgrade: gx_upgrade gxgo_upgrade
|
|||||||
go_check:
|
go_check:
|
||||||
@bin/check_go_version $(IPFS_MIN_GO_VERSION)
|
@bin/check_go_version $(IPFS_MIN_GO_VERSION)
|
||||||
|
|
||||||
gx_upgrade:
|
bin/gx-v%:
|
||||||
go get -u github.com/whyrusleeping/gx
|
@echo "installing gx $(@:bin/gx-%=%)"
|
||||||
|
@bin/dist_get gx $@ $(@:bin/gx-%=%)
|
||||||
|
rm -f bin/gx
|
||||||
|
ln -s $(@:bin/%=%) bin/gx
|
||||||
|
|
||||||
gxgo_upgrade:
|
bin/gx-go-v%:
|
||||||
go get -u github.com/whyrusleeping/gx-go
|
@echo "installing gx-go $(@:bin/gx-go-%=%)"
|
||||||
|
@bin/dist_get gx-go $@ $(@:bin/gx-go-%=%)
|
||||||
|
rm -f bin/gx-go
|
||||||
|
ln -s $(@:bin/%=%) bin/gx-go
|
||||||
|
|
||||||
|
gx_check: ${gx_bin} ${gx-go_bin}
|
||||||
|
|
||||||
path_check:
|
path_check:
|
||||||
@bin/check_go_path $(realpath $(shell pwd)) $(realpath $(GOPATH)/src/github.com/ipfs/go-ipfs)
|
@bin/check_go_path $(realpath $(shell pwd)) $(realpath $(GOPATH)/src/github.com/ipfs/go-ipfs)
|
||||||
|
|
||||||
gx_check:
|
|
||||||
@bin/check_gx_program "gx" $(IPFS_MIN_GX_VERSION) 'Upgrade or install gx using your package manager or run `make gx_upgrade`'
|
|
||||||
@bin/check_gx_program "gx-go" $(IPFS_MIN_GX_GO_VERSION) 'Upgrade or install gx-go using your package manager or run `make gxgo_upgrade`'
|
|
||||||
|
|
||||||
deps: go_check gx_check path_check
|
deps: go_check gx_check path_check
|
||||||
gx --verbose install --global
|
${gx_bin} --verbose install --global
|
||||||
|
|
||||||
# saves/vendors third-party dependencies to Godeps/_workspace
|
# saves/vendors third-party dependencies to Godeps/_workspace
|
||||||
# -r flag rewrites import paths to use the vendored path
|
# -r flag rewrites import paths to use the vendored path
|
||||||
@ -58,7 +68,7 @@ clean:
|
|||||||
uninstall:
|
uninstall:
|
||||||
make -C cmd/ipfs uninstall
|
make -C cmd/ipfs uninstall
|
||||||
|
|
||||||
PHONY += all help godep toolkit_upgrade gx_upgrade gxgo_upgrade gx_check
|
PHONY += all help godep toolkit_upgrade gx_check
|
||||||
PHONY += go_check deps vendor install build nofuse clean uninstall
|
PHONY += go_check deps vendor install build nofuse clean uninstall
|
||||||
|
|
||||||
##############################################################
|
##############################################################
|
||||||
|
149
bin/dist_get
Executable file
149
bin/dist_get
Executable file
@ -0,0 +1,149 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
die() {
|
||||||
|
echo "$@" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
have_binary() {
|
||||||
|
type "$1" > /dev/null 2> /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
check_writeable() {
|
||||||
|
printf "" > "$1" && rm "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
download() {
|
||||||
|
dl_url="$1"
|
||||||
|
dl_output="$2"
|
||||||
|
|
||||||
|
test "$#" -eq "2" || die "download requires exactly two arguments, was given $@"
|
||||||
|
|
||||||
|
if ! check_writeable "$dl_output"; then
|
||||||
|
die "download error: cannot write to $dl_output"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if have_binary wget; then
|
||||||
|
printf '==> Using wget to download "%s" to "%s"\n' "$dl_url" "$dl_output"
|
||||||
|
wget "$dl_url" -O "$dl_output" || return
|
||||||
|
elif have_binary curl; then
|
||||||
|
printf '==> Using curl to download "%s" to "%s"\n' "$dl_url" "$dl_output"
|
||||||
|
curl --silent "$dl_url" > "$dl_output" || return
|
||||||
|
elif have_binary fetch; then
|
||||||
|
printf '==> Using fetch to download "%s" to "%s"\n' "$dl_url" "$dl_output"
|
||||||
|
fetch "$dl_url" -o "$dl_output" || return
|
||||||
|
else
|
||||||
|
die "no binary found to download $dl_url. exiting."
|
||||||
|
fi
|
||||||
|
echo "==> download complete!"
|
||||||
|
}
|
||||||
|
|
||||||
|
unarchive() {
|
||||||
|
ua_archivetype="$1"
|
||||||
|
ua_infile="$2"
|
||||||
|
ua_outfile="$3"
|
||||||
|
ua_distname="$4"
|
||||||
|
|
||||||
|
if ! check_writeable "$ua_outfile"; then
|
||||||
|
die "unarchive error: cannot write to $ua_outfile"
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$ua_archivetype" in
|
||||||
|
tar.gz)
|
||||||
|
if have_binary tar; then
|
||||||
|
echo "==> using 'tar' to extract binary from archive"
|
||||||
|
cat "$ua_infile" | tar -O -z -x "$ua_distname/$ua_distname" > "$ua_outfile"
|
||||||
|
else
|
||||||
|
die "no binary on system for extracting tar files"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
zip)
|
||||||
|
if have_binary unzip; then
|
||||||
|
echo "==> using 'unzip' to extract binary from archive"
|
||||||
|
unzip -p "$ua_infile" "$ua_distname/$ua_distname" > "$ua_outfile"
|
||||||
|
else
|
||||||
|
die "no installed method for extracting .zip archives"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
die "unrecognized archive type '$ua_archivetype'"
|
||||||
|
esac
|
||||||
|
|
||||||
|
chmod +x "$ua_outfile"
|
||||||
|
}
|
||||||
|
|
||||||
|
get_go_vars() {
|
||||||
|
if [ ! -z "$GOOS" ] && [ ! -z "$GOARCH" ]; then
|
||||||
|
printf "%s-%s" "$GOOS" "$GOARCH"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if have_binary go; then
|
||||||
|
printf "%s-%s" "$(go env GOOS)" "$(go env GOARCH)"
|
||||||
|
else
|
||||||
|
die "no way of determining system GOOS and GOARCH\nPlease manually set GOOS and GOARCH then retry."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
mkurl() {
|
||||||
|
m_name="$1"
|
||||||
|
m_vers="$2"
|
||||||
|
m_archive="$3"
|
||||||
|
m_govars=$(get_go_vars) || die "could not get go env vars"
|
||||||
|
|
||||||
|
echo "http://dist.ipfs.io/$m_name/$m_vers/${m_name}_${m_vers}_$m_govars.$m_archive"
|
||||||
|
}
|
||||||
|
|
||||||
|
distname="$1"
|
||||||
|
outpath="$2"
|
||||||
|
version="$3"
|
||||||
|
|
||||||
|
if [ -z "$distname" ] || [ -z "$outpath" ] || [ -z "$version" ]; then
|
||||||
|
die "usage: dist_get <distname> <outpath> <version>"
|
||||||
|
fi
|
||||||
|
|
||||||
|
case $version in
|
||||||
|
v*)
|
||||||
|
# correct input
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "invalid version '$version'" >&2
|
||||||
|
die "versions must begin with 'v', for example: v0.4.0"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# TODO: don't depend on the go tool being installed to detect this
|
||||||
|
goenv=$(get_go_vars) || die "could not get go env vars"
|
||||||
|
|
||||||
|
case $goenv in
|
||||||
|
linux-*)
|
||||||
|
archive="tar.gz"
|
||||||
|
;;
|
||||||
|
darwin-*)
|
||||||
|
archive="tar.gz"
|
||||||
|
;;
|
||||||
|
windows-*)
|
||||||
|
archive="zip"
|
||||||
|
;;
|
||||||
|
freebsd-*)
|
||||||
|
archive="tar.gz"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "unrecognized system environment: $goenv" >&2
|
||||||
|
die "currently only linux, darwin, windows and freebsd are supported by this script"
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
mkdir -p bin/tmp
|
||||||
|
|
||||||
|
url=$(mkurl "$distname" "$version" "$archive")
|
||||||
|
tmpfi="bin/tmp/$distname.$archive"
|
||||||
|
|
||||||
|
download "$url" "$tmpfi"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
die "failed to download $url to $tmpfi"
|
||||||
|
fi
|
||||||
|
|
||||||
|
unarchive "$archive" "$tmpfi" "$outpath" "$distname"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
die "failed to extract archive $tmpfi"
|
||||||
|
fi
|
@ -9,6 +9,8 @@ GOSLEEP_SRC = ./dependencies/go-sleep
|
|||||||
|
|
||||||
GX_RELATIVE_PATH = ../../../../gx/ipfs
|
GX_RELATIVE_PATH = ../../../../gx/ipfs
|
||||||
|
|
||||||
|
export PATH := ../bin:${PATH}
|
||||||
|
|
||||||
# User might want to override those on the command line
|
# User might want to override those on the command line
|
||||||
GOFLAGS =
|
GOFLAGS =
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user