forked from achristmascarl/rainfrog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
87 lines (75 loc) · 2.3 KB
/
install.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
main() {
need_cmd "curl"
need_cmd "jq"
need_cmd "fzf"
if check_cmd "shasum"; then
shasum() {
command shasum -a 256 "$@"
}
elif check_cmd "sha256sum"; then
shasum() {
sha256sum "$@"
}
else
echo "Could not find 'shasum' or 'sha256sum' in your path"
exit 1
fi
mkdir -p "$HOME/tmp"
temp="$(mktemp -d "$HOME/tmp/rainfrog-install-XXXXXX")"
echo "temp dir: $temp"
echo "installing 🐸 rainfrog..."
release_json=$(curl -s https://api.github.com/repos/achristmascarl/rainfrog/releases/latest | jq)
binary=$(jq <<<$release_json | jq -r '.["assets"] | .[] | .name' | sed -u "s/^.*[.sha256]$//" | sed -u "s/[.]tar[.]gz//" | awk 'NF' | fzf --header "choose a binary from the latest rainfrog release:" --reverse)
if [ -z "$binary" ]; then
echo "no binary selected"
exit 1
fi
echo "selected binary: $binary"
# make sure local bin dir exists
mkdir -p "$HOME/.local/bin"
# download binary and hash
echo "downloading binary and hash..."
curl -fL $(jq <<<$release_json | jq -r ".assets[] | select(.name | contains(\"$binary.tar.gz\")) | .browser_download_url") >"$temp/$binary.tar.gz"
curl -fL $(jq <<<$release_json | jq -r ".assets[] | select(.name | contains(\"$binary.sha256\")) | .browser_download_url") >"$temp/$binary.sha256"
current=$(pwd)
cd $temp
shasum -c "$temp/$binary.sha256"
sha256check=$?
cd $current
if [ $sha256check -ne 0 ]; then
echo "sha256 check failed"
exit 1
fi
# clean up and unpack
rm -rf "$HOME/.local/rainfrog"
tar -xzf "$temp/$binary.tar.gz" -C "$HOME/.local/"
if [ $? -ne 0 ]; then
echo "failed to unpack binary"
exit 1
fi
# link binary
ln -sf "$HOME/.local/rainfrog" "$HOME/.local/bin/rainfrog"
if [ $? -ne 0 ]; then
echo "failed to link binary"
exit 1
fi
# check installation and PATH
echo ""
if [ "$(which rainfrog)" = "$HOME/.local/bin/rainfrog" ]; then
echo "rainfrog was successfully installed! 🎊"
else
echo "⚠️ to run rainfrog from the terminal, you must add ~/.local/bin to your PATH"
echo "you can run rainfrog now with '~/.local/bin/rainfrog'"
fi
}
# ty rustup for these
need_cmd() {
if ! check_cmd "$1"; then
echo "need '$1' (command not found)" >&2
fi
}
check_cmd() {
command -v "$1" >/dev/null 2>&1
}
main "$@" || exit 1