Repository navigation
Expand file tree
/
Copy pathinstall
More file actions
executable file
·51 lines (41 loc) · 1.57 KB
/
Copy pathinstall
File metadata and controls
executable file
·51 lines (41 loc) · 1.57 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
#!/usr/bin/env bash
set -eou pipefail
# which release to install and where to download it from
# (point RAW_URL at a mirror or a fork to install from
# somewhere else)
VERSION="${BASHCARDS_VERSION:-0.2.0}"
RAW_URL="${BASHCARDS_RAW_URL:-https://raw.githubusercontent.com/rpearce/bashcards}"
# where to put it: your home directory, so there's no need
# for sudo, unless you're root (like under sudo), in which
# case it goes where everyone can use it
if [ "$EUID" -eq 0 ]; then
PREFIX="${PREFIX:-/usr/local}"
else
PREFIX="${PREFIX:-$HOME/.local}"
fi
RELEASE_URL="$RAW_URL/v$VERSION"
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT
install_bashcards() {
# download everything first, so a failed download
# can't leave a half-written bashcards behind
curl -fsSL "$RELEASE_URL/bashcards" -o "$TMP_DIR/bashcards"
curl -fsSL "$RELEASE_URL/bashcards.1" -o "$TMP_DIR/bashcards.1"
install -d "$PREFIX/bin" "$PREFIX/share/man/man1"
install -m 0755 "$TMP_DIR/bashcards" "$PREFIX/bin/bashcards"
install -m 0644 "$TMP_DIR/bashcards.1" "$PREFIX/share/man/man1/bashcards.1"
echo "Installed $PREFIX/bin/bashcards and its man page from $RELEASE_URL"
# ~/.local/bin isn't on everyone's PATH (like on macOS);
# once it is, man finds the man page next to it, too
case ":$PATH:" in
*":$PREFIX/bin:"*) ;;
*)
echo ""
echo "$PREFIX/bin isn't on your PATH, so add this line to your shell's"
echo "startup file (like ~/.bashrc or ~/.zshrc) and open a new terminal:"
echo ""
echo " export PATH=\"$PREFIX/bin:\$PATH\""
;;
esac
}
install_bashcards