-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathinstall
executable file
·93 lines (74 loc) · 1.88 KB
/
install
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
88
89
90
91
92
93
#!/bin/sh
usage() {
cat <<'EOM'
install [-t TAG] [-p PREFIX]
Options:
-t TAG Choose a specific tag to install. If omitted, latest is used.
-p PREFIX Install to PREFIX/bin. Default is /usr/local.
-h Show this help
The script must be run as a user with write permission in PREFIX. For the
default PREFIX, this means root.
Setting options in a curl|sh invocation is done with `-s --':
curl ... | sh -s -- -p ~/.local
EOM
}
tag=
prefix=/usr/local
while getopts t:p:h opt; do
case "$opt" in
t)
tag=$OPTARG
;;
p)
prefix=$OPTARG
;;
h)
usage
exit 0
;;
\?)
usage >&2
exit 64
;;
esac
done
shift $((OPTIND - 1))
if [ -z "$tag" ]; then
tag=$(curl \
--max-time 10 \
--retry 5 \
--retry-delay 0 \
--retry-max-time 30 \
-sSf https://api.github.com/repos/restyled-io/restyler/releases |
grep -o '"tag_name": ".*"' |
sed 's/^.*: "//; s/"$//' |
grep -v -- '-rc$' |
head -n 1)
fi
if [ -z "$tag" ]; then
echo "Unable to determine latest tag" >&2
exit 1
fi
cd /tmp || exit 1
artifact_name=restyler-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)
artifact_url=https://github.com/restyled-io/restyler/releases/download/$tag/$artifact_name.tar.gz
echo "Downloading $tag/$artifact_name..."
if ! curl -sSf -L "$artifact_url" | tar xzf -; then
cat >&2 <<EOM
Download failed
1. Does https://github.com/restyled-io/restyler/releases/tag/$tag exist?
2. Does it have an artifact named $artifact_name?
3. Does $artifact_url exist?
To request an artifact be added for your platform, or to report a bug with this
script, go to https://github.com/restyled-io/restyler/issues.
EOM
exit 1
fi
echo "Installing binaries in $prefix/bin"
for bin in "$artifact_name"/*; do
if [ -x "$bin" ]; then
cp -v "$bin" "$prefix"/bin
fi
done
echo "Cleaning up..."
rm -rf "$artifact_name"