Skip to content

Commit 2e9ceb1

Browse files
feat: add install.sh script (#120)
* feat: add installation script * feat(install): ask install path as an envvar * feat: add help command to installation script * docs(install): say that INSTALL_PATH is required * fix(install): should exit early if curl is not found * refactor: rename install -> install.sh
1 parent 6662631 commit 2e9ceb1

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

install.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/sh
2+
3+
_have() { type "$1" >/dev/null 2>&1; }
4+
5+
help() {
6+
cat <<EOF
7+
Usage: ${0##*/} [options] [version]
8+
9+
Options:
10+
-h, --help Show this help message and exit.
11+
12+
Arguments:
13+
version Specify the version of gitmux to install. If not provided, the latest version will be installed.
14+
15+
Environment Variables:
16+
INSTALL_PATH Specify the directory where gitmux should be installed. Required
17+
18+
Description:
19+
This script installs the gitmux tool, which provides Git status information in the tmux status line.
20+
It automatically detects the system architecture and downloads the appropriate version of gitmux.
21+
22+
Examples:
23+
INSTALL_PATH=/usr/local/bin ${0##*/} Install the latest version of gitmux to /usr/local/bin.
24+
INSTALL_PATH=/usr/local/bin ${0##*/} v0.7.0 Install version 0.7.0 of gitmux to /usr/local/bin.
25+
26+
EOF
27+
}
28+
29+
gh_install() {
30+
ver="$1"
31+
repo='arl/gitmux'
32+
[ -z "$ver" ] && {
33+
latest="https://api.github.com/repos/$repo/releases/latest"
34+
ver=$(curl -sS "$latest" | grep tarball_url | sed 's>.*: "\(.*\)".*>\1>') && test -n "$ver"
35+
ver=${ver##*/}
36+
}
37+
tarname=''
38+
archi=$(uname -sm)
39+
case "$archi" in
40+
Darwin\ arm64) tarname="gitmux_${ver}_macOS_arm64.tar.gz" ;;
41+
Darwin\ x86_64) tarname="gitmux_${ver}_macOS_amd64.tar.gz" ;;
42+
Linux\ aarch64*) tarname="gitmux_${ver}_linux_arm64.tar.gz" ;;
43+
Linux\ *64) tarname="gitmux_${ver}_linux_amd64.tar.gz" ;;
44+
*) echo "Unsupported architecture" && return 1 ;;
45+
esac
46+
tmpdir="$(mktemp -d)"
47+
cd "$tmpdir" || :
48+
curl -sSLO "https://github.com/$repo/releases/download/$ver/$tarname"
49+
tar -xf gitmux*.tar.gz &&
50+
mv gitmux "${INSTALL_PATH}"
51+
[ -d "$tmpdir" ] && rm -rf "$tmpdir"
52+
}
53+
54+
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then help && exit 0; fi
55+
56+
! _have curl && echo "This script depends on curl" && exit 1
57+
[ -z "$INSTALL_PATH" ] && echo "Please set the INSTALL_PATH envvar to specify installation directory" && exit 1
58+
59+
echo "Installing gitmux..."
60+
if gh_install "$@"; then
61+
echo "Successfully installed gitmux"
62+
else
63+
echo "Could not install gitmux" && exit 1
64+
fi

0 commit comments

Comments
 (0)