forked from stepchowfun/docuum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·72 lines (59 loc) · 2.08 KB
/
install.sh
File metadata and controls
executable file
·72 lines (59 loc) · 2.08 KB
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
#!/usr/bin/env sh
# Usage examples:
# ./install.sh
# VERSION=x.y.z ./install.sh
# PREFIX=/usr/local/bin ./install.sh
# We wrap everything in parentheses for two reasons:
# 1. To prevent the shell from executing only a prefix of the script if the download is interrupted
# 2. To ensure that any working directory changes with `cd` are local to this script and don't
# affect the calling user's shell
(
# Where the binary will be installed
DESTINATION="${PREFIX:-/usr/local/bin}/docuum"
# Which version to download
RELEASE="v${VERSION:-0.9.4}"
# Determine which binary to download.
FILENAME=''
if uname -a | grep -qi 'x86_64.*GNU/Linux'; then
echo 'x86_64 GNU/Linux detected.'
FILENAME=docuum-x86_64-unknown-linux-gnu
fi
if uname -a | grep -qi 'Darwin.*x86_64'; then
echo 'macOS detected.'
FILENAME=docuum-x86_64-apple-darwin
fi
# Find a temporary location for the binary.
TEMPDIR=$(mktemp -d /tmp/docuum.XXXXXXXX)
# This is a helper function to clean up and fail.
fail() {
echo "$1" >&2
cd "$TEMPDIR/.." || exit 1
rm -rf "$TEMPDIR"
exit 1
}
# Enter the temporary directory.
cd "$TEMPDIR" || fail "Unable to access the temporary directory $TEMPDIR."
# Fail if there is no pre-built binary for this platform.
if [ -z "$FILENAME" ]; then
fail 'Unfortunately, there is no pre-built binary for this platform.'
fi
# Download the binary.
if ! curl "https://github.com/stepchowfun/docuum/releases/download/$RELEASE/$FILENAME" \
-o "$FILENAME" -LSf; then
fail 'There was an error downloading the binary.'
fi
# Make it executable.
if ! chmod a+rx "$FILENAME"; then
fail 'There was an error setting the permissions for the binary.'
fi
# Install it at the requested destination.
# shellcheck disable=SC2024
mv "$FILENAME" "$DESTINATION" 2> /dev/null ||
sudo mv "$FILENAME" "$DESTINATION" < /dev/tty ||
fail "Unable to install the binary at $DESTINATION."
# Remove the temporary directory.
cd ..
rm -rf "$TEMPDIR"
# Let the user know it worked.
echo "$("$DESTINATION" --version) is now installed."
)