-
Notifications
You must be signed in to change notification settings - Fork 194
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·85 lines (70 loc) · 1.89 KB
/
install.sh
File metadata and controls
executable file
·85 lines (70 loc) · 1.89 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
#!/usr/bin/env sh
set -eu
REPO="prometheus-lua/Prometheus"
INSTALL_BASE="${PROMETHEUS_LUA_HOME:-$HOME/.local/share/prometheus-lua}"
BIN_DIR="${PROMETHEUS_LUA_BIN:-$HOME/.local/bin}"
need_cmd() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "Missing required command: $1" >&2
exit 1
fi
}
fetch() {
url="$1"
out="$2"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$url" -o "$out"
return
fi
if command -v wget >/dev/null 2>&1; then
wget -qO "$out" "$url"
return
fi
echo "Neither curl nor wget is installed." >&2
exit 1
}
need_cmd tar
need_cmd uname
need_cmd mktemp
need_cmd grep
need_cmd sed
OS_NAME="$(uname -s)"
case "$OS_NAME" in
Linux) OS="linux" ;;
Darwin) OS="macos" ;;
*)
echo "Unsupported operating system: $OS_NAME" >&2
exit 1
;;
esac
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT INT TERM
LATEST_JSON="$TMP_DIR/latest.json"
fetch "https://api.github.com/repos/$REPO/releases/latest" "$LATEST_JSON"
TAG="$(grep '"tag_name":' "$LATEST_JSON" | sed -E 's/.*"([^"]+)".*/\1/' | head -n1)"
if [ -z "$TAG" ]; then
echo "Failed to resolve latest release tag." >&2
exit 1
fi
ASSET="prometheus-lua-$TAG-$OS.tar.gz"
ASSET_URL="https://github.com/$REPO/releases/download/$TAG/$ASSET"
ARCHIVE_PATH="$TMP_DIR/$ASSET"
fetch "$ASSET_URL" "$ARCHIVE_PATH"
mkdir -p "$INSTALL_BASE" "$BIN_DIR"
tar -xzf "$ARCHIVE_PATH" -C "$INSTALL_BASE"
TARGET_DIR="$INSTALL_BASE/prometheus-lua-$TAG-$OS"
if [ ! -d "$TARGET_DIR" ]; then
echo "Unexpected archive layout; missing $TARGET_DIR" >&2
exit 1
fi
ln -sfn "$TARGET_DIR/prometheus-lua" "$BIN_DIR/prometheus-lua"
chmod +x "$TARGET_DIR/prometheus-lua"
printf 'Installed prometheus-lua %s to %s\n' "$TAG" "$TARGET_DIR"
printf 'Linked command: %s/prometheus-lua\n' "$BIN_DIR"
case ":$PATH:" in
*":$BIN_DIR:"*)
;;
*)
printf 'Add %s to PATH, e.g.: export PATH="%s:$PATH"\n' "$BIN_DIR" "$BIN_DIR"
;;
esac