forked from cargo-bins/cargo-quickinstall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-version.sh
executable file
·55 lines (41 loc) · 1.64 KB
/
build-version.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
set -euxo pipefail
cd "$(dirname "$0")"
CRATE=${1?"USAGE: $0 CRATE"}
date
# FIXME: make a signal handler that cleans this up if we exit early.
if [ ! -d "${TEMPDIR:-}" ]; then
TEMPDIR="$(mktemp -d)"
fi
# see crawler policy: https://crates.io/policies
curl_slowly() {
sleep 1 && curl --user-agent "cargo-quickinstall build pipeline (alsuren@gmail.com)" "$@"
}
curl_slowly --fail "https://crates.io/api/v1/crates/${CRATE}" >"$TEMPDIR/crates.io-response.json"
VERSION=$(
cat "$TEMPDIR/crates.io-response.json" | jq -r .versions[0].num
)
TARGET_ARCH=$(rustc --version --verbose | sed -n 's/host: //p')
if curl_slowly --fail -I --output /dev/null "https://github.com/alsuren/cargo-quickinstall/releases/download/${CRATE}-${VERSION}-${TARGET_ARCH}/${CRATE}-${VERSION}-${TARGET_ARCH}.tar.gz"; then
echo "${CRATE}/${VERSION}/${CRATE}-${VERSION}-${TARGET_ARCH}.tar.gz already uploaded. Skipping."
exit 0
fi
cargo install "$CRATE" --version "$VERSION"
BINARIES=$(
cat ~/.cargo/.crates2.json | jq -r '
.installs | to_entries[] | select(.key|startswith("'${CRATE}' ")) | .value.bins | .[]
' | tr '\r' ' '
)
cd ~/.cargo/bin
for file in $BINARIES; do
if file $file | grep ': data$'; then
echo "something wrong with $file. Should be recognised as executable."
exit 1
fi
done
# Package up the binaries so that they can be untarred in ~/.cargo/bin
#
# TODO: maybe we want to make a ~/.cargo-quickinstall/bin to untar into,
# and add symlinks into ~/.cargo/bin, to aid debugging?
tar -czf "${TEMPDIR}/${CRATE}-${VERSION}-${TARGET_ARCH}.tar.gz" $BINARIES
echo "${TEMPDIR}/${CRATE}-${VERSION}-${TARGET_ARCH}.tar.gz"