-
-
Notifications
You must be signed in to change notification settings - Fork 169
Expand file tree
/
Copy pathinstall.sh
More file actions
102 lines (90 loc) · 2.93 KB
/
install.sh
File metadata and controls
102 lines (90 loc) · 2.93 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
#!/usr/bin/env bash
set -euo pipefail
REPO="rudrankriyam/App-Store-Connect-CLI"
BIN_NAME="asc"
DEFAULT_INSTALL_DIR="/usr/local/bin"
if [ -n "${HOME:-}" ]; then
DEFAULT_INSTALL_DIR="${HOME}/.local/bin"
fi
INSTALL_DIR="${INSTALL_DIR:-${DEFAULT_INSTALL_DIR}}"
OS="$(uname -s)"
ARCH="$(uname -m)"
case "${OS}" in
Darwin) OS="macOS" ;;
Linux) OS="linux" ;;
*)
echo "Unsupported OS: ${OS}"
exit 1
;;
esac
case "${ARCH}" in
x86_64|amd64) ARCH="amd64" ;;
arm64|aarch64) ARCH="arm64" ;;
*)
echo "Unsupported architecture: ${ARCH}"
exit 1
;;
esac
LATEST_URL="$(curl -fsSL -o /dev/null -w "%{url_effective}" "https://github.com/${REPO}/releases/latest")"
VERSION="${LATEST_URL##*/}"
if [ -z "${VERSION}" ] || [ "${VERSION}" = "latest" ]; then
echo "Could not determine latest version."
exit 1
fi
ASSET="${BIN_NAME}_${VERSION}_${OS}_${ARCH}"
BASE_URL="https://github.com/${REPO}/releases/download/${VERSION}"
BIN_URL="${BASE_URL}/${ASSET}"
CHECKSUMS_ASSET="${BIN_NAME}_${VERSION}_checksums.txt"
CHECKSUMS_URL="${BASE_URL}/${CHECKSUMS_ASSET}"
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "${TMP_DIR}"' EXIT
echo "Downloading ${ASSET}..."
curl -fsSL "${BIN_URL}" -o "${TMP_DIR}/${ASSET}"
if curl -fsSL "${CHECKSUMS_URL}" -o "${TMP_DIR}/checksums.txt"; then
if command -v shasum >/dev/null 2>&1 || command -v sha256sum >/dev/null 2>&1; then
EXPECTED="$(grep -E "[ *]${ASSET}$" "${TMP_DIR}/checksums.txt" | awk '{print $1}')"
if [ -n "${EXPECTED}" ]; then
if command -v shasum >/dev/null 2>&1; then
ACTUAL="$(shasum -a 256 "${TMP_DIR}/${ASSET}" | awk '{print $1}')"
else
ACTUAL="$(sha256sum "${TMP_DIR}/${ASSET}" | awk '{print $1}')"
fi
if [ "${EXPECTED}" != "${ACTUAL}" ]; then
echo "Checksum verification failed."
exit 1
fi
echo "Checksum verified."
else
echo "Warning: Asset not found in checksums.txt. Skipping verification."
fi
else
echo "Warning: No checksum tool (shasum/sha256sum) available. Skipping verification."
fi
else
echo "Warning: Could not download checksums.txt. Skipping verification."
fi
if ! mkdir -p "${INSTALL_DIR}" 2>/dev/null; then
if command -v sudo >/dev/null 2>&1; then
sudo mkdir -p "${INSTALL_DIR}"
else
echo "Cannot create ${INSTALL_DIR}; try running with sudo or set INSTALL_DIR."
exit 1
fi
fi
if [ -w "${INSTALL_DIR}" ]; then
install -m 755 "${TMP_DIR}/${ASSET}" "${INSTALL_DIR}/${BIN_NAME}"
else
if command -v sudo >/dev/null 2>&1; then
sudo install -m 755 "${TMP_DIR}/${ASSET}" "${INSTALL_DIR}/${BIN_NAME}"
else
echo "Cannot write to ${INSTALL_DIR}; try running with sudo or set INSTALL_DIR."
exit 1
fi
fi
echo "Installed ${BIN_NAME} to ${INSTALL_DIR}/${BIN_NAME}"
echo "Run: ${BIN_NAME} --help"
if [[ ":${PATH}:" != *":${INSTALL_DIR}:"* ]]; then
echo "Note: ${INSTALL_DIR} is not in your PATH."
echo "Add it to your shell profile, e.g.:"
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
fi