-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinstall
61 lines (52 loc) · 1.47 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
#!/usr/bin/env bash
set -e
BINARY_NAME="harpoon"
BINARY_RELEASE_NAME="${BINARY_NAME}"
# Check if a version argument is provided
VERSION="latest"
INSTALL_DIR="/usr/sbin"
# Parse optional flags
while [[ $# -gt 0 ]]; do
case $1 in
--install-version)
VERSION="$2"
shift 2
;;
--install-dir)
INSTALL_DIR="$2"
shift 2
;;
*)
echo "unknown option: $1"
exit 1
;;
esac
done
if [ "$VERSION" == "latest" ]; then
# Download the latest release
DOWNLOAD_URL=$(curl -s https://api.github.com/repos/alegrey91/harpoon/releases/latest |
grep "browser_download_url" |
cut -d : -f 2,3 |
tr -d \" | \
grep "$BINARY_RELEASE_NAME$")
else
# Download the specified version
DOWNLOAD_URL=https://github.com/alegrey91/harpoon/releases/download/"$VERSION"/harpoon
fi
# Validate if the download URL is found
if [ -z "$DOWNLOAD_URL" ]; then
echo "error: unable to find the specified version or the latest release."
exit 1
fi
# Download the binary
wget -q ${DOWNLOAD_URL} -O "$BINARY_RELEASE_NAME"
# Check if the binary has been downloaded, otherwise exit
if [ ! -f "$BINARY_RELEASE_NAME" ]; then
echo "$BINARY_RELEASE_NAME doesn't exist."
exit 1
fi
printf "[download succeeded]\n"
# Install the binary
chmod +x "$BINARY_RELEASE_NAME"
mv "$BINARY_RELEASE_NAME" "$INSTALL_DIR/$BINARY_NAME"
printf "[installation succeeded]\n"