-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·128 lines (102 loc) · 4.9 KB
/
install.sh
File metadata and controls
executable file
·128 lines (102 loc) · 4.9 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/sh
# Install script for jr — a fast CLI for Jira Cloud
# Usage:
# curl -fsSL https://raw.githubusercontent.com/Zious11/jira-cli/main/install.sh | sh
# curl -fsSL https://raw.githubusercontent.com/Zious11/jira-cli/main/install.sh | sh -s -- v0.3.0
set -eu
REPO="Zious11/jira-cli"
BINARY="jr"
err() {
echo "Error: $1" >&2
exit 1
}
# ── Check dependencies ────────────────────────────────────────────────
command -v curl >/dev/null 2>&1 || err "curl is required but not found. Install curl and try again."
command -v tar >/dev/null 2>&1 || err "tar is required but not found. Install tar and try again."
# ── Detect platform ───────────────────────────────────────────────────
OS="$(uname -s)"
ARCH="$(uname -m)"
case "${OS}" in
Darwin)
case "${ARCH}" in
arm64) TARGET="aarch64-apple-darwin" ;;
x86_64) TARGET="x86_64-apple-darwin" ;;
*) err "Unsupported platform: ${OS} ${ARCH}. jr supports macOS and Linux (x86_64, ARM64)." ;;
esac
;;
Linux)
case "${ARCH}" in
aarch64) TARGET="aarch64-unknown-linux-gnu" ;;
x86_64) TARGET="x86_64-unknown-linux-gnu" ;;
*) err "Unsupported platform: ${OS} ${ARCH}. jr supports macOS and Linux (x86_64, ARM64)." ;;
esac
;;
*)
err "Unsupported platform: ${OS} ${ARCH}. jr supports macOS and Linux (x86_64, ARM64)."
;;
esac
# ── Resolve version ───────────────────────────────────────────────────
if [ $# -gt 0 ]; then
VERSION="$1"
else
VERSION="$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name"' \
| sed 's/.*"tag_name": *"\([^"]*\)".*/\1/')"
if [ -z "${VERSION}" ]; then
err "Failed to fetch release info. Check your internet connection and try again."
fi
fi
# ── Download and verify ───────────────────────────────────────────────
TARBALL="${BINARY}-${VERSION}-${TARGET}.tar.gz"
CHECKSUM_FILE="${TARBALL}.sha256"
BASE_URL="https://github.com/${REPO}/releases/download/${VERSION}"
TMP_DIR="$(mktemp -d 2>/dev/null || mktemp -d -t jr)"
trap 'rm -rf "${TMP_DIR}"' EXIT
echo "Downloading ${BINARY} ${VERSION} for ${TARGET}..."
HTTP_CODE="$(curl -sSL -w "%{http_code}" -o "${TMP_DIR}/${TARBALL}" "${BASE_URL}/${TARBALL}")" || true
case "${HTTP_CODE}" in
200) ;;
404) err "Release ${VERSION} not found. See https://github.com/${REPO}/releases for available versions." ;;
*) err "Failed to download jr ${VERSION} (HTTP ${HTTP_CODE}). Check your internet connection and try again." ;;
esac
HTTP_CODE="$(curl -sSL -w "%{http_code}" -o "${TMP_DIR}/${CHECKSUM_FILE}" "${BASE_URL}/${CHECKSUM_FILE}")" || true
case "${HTTP_CODE}" in
200) ;;
404) err "Checksum file for ${VERSION} not found. The release may be incomplete. See https://github.com/${REPO}/releases." ;;
*) err "Failed to download checksum file (HTTP ${HTTP_CODE}). Check your internet connection and try again." ;;
esac
# Verify checksum (cd required — .sha256 contains bare filename)
cd "${TMP_DIR}"
if command -v sha256sum >/dev/null 2>&1; then
sha256sum -c "${CHECKSUM_FILE}" >/dev/null 2>&1 \
|| err "Checksum verification failed. The download may be corrupted. Try again."
elif command -v shasum >/dev/null 2>&1; then
shasum -a 256 -c "${CHECKSUM_FILE}" >/dev/null 2>&1 \
|| err "Checksum verification failed. The download may be corrupted. Try again."
else
echo "Warning: No checksum tool found. Skipping verification."
fi
# ── Extract and install ───────────────────────────────────────────────
tar xzf "${TMP_DIR}/${TARBALL}" -C "${TMP_DIR}"
if [ -w /usr/local/bin ]; then
INSTALL_DIR="/usr/local/bin"
else
INSTALL_DIR="${HOME}/.local/bin"
mkdir -p "${INSTALL_DIR}"
fi
cp "${TMP_DIR}/${BINARY}" "${INSTALL_DIR}/${BINARY}"
chmod +x "${INSTALL_DIR}/${BINARY}"
# ── Success ───────────────────────────────────────────────────────────
echo "Installed ${BINARY} ${VERSION} to ${INSTALL_DIR}/${BINARY}"
if [ "${INSTALL_DIR}" = "${HOME}/.local/bin" ]; then
case ":${PATH}:" in
*":${INSTALL_DIR}:"*) ;;
*)
echo ""
echo "Add ~/.local/bin to your PATH:"
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
echo ""
;;
esac
fi
echo "Run \"jr init\" to get started."