-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
169 lines (140 loc) · 4.75 KB
/
install.sh
File metadata and controls
169 lines (140 loc) · 4.75 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash
set -euo pipefail
REPO="DennySORA/httpulse"
BINARY_NAME="httpulse"
DEFAULT_INSTALL_DIR="$HOME/.local/bin"
INSTALL_DIR="${INSTALL_DIR:-$DEFAULT_INSTALL_DIR}"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
info() { echo -e "${BLUE}[INFO]${NC} $1"; }
success() { echo -e "${GREEN}[OK]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
error() { echo -e "${RED}[ERROR]${NC} $1" >&2; exit 1; }
# Detect OS
detect_os() {
case "$(uname -s)" in
Linux*) echo "linux" ;;
Darwin*) echo "darwin" ;;
*) error "Unsupported OS: $(uname -s)" ;;
esac
}
# Detect architecture
detect_arch() {
case "$(uname -m)" in
x86_64|amd64) echo "x86_64" ;;
aarch64|arm64) echo "aarch64" ;;
*) error "Unsupported architecture: $(uname -m)" ;;
esac
}
# Get target triple
get_target() {
local os="$1"
local arch="$2"
case "${os}-${arch}" in
linux-x86_64) echo "x86_64-unknown-linux-musl" ;;
linux-aarch64) echo "aarch64-unknown-linux-musl" ;;
darwin-x86_64) echo "x86_64-apple-darwin" ;;
darwin-aarch64) echo "aarch64-apple-darwin" ;;
*) error "Unsupported platform: ${os}-${arch}" ;;
esac
}
# Get latest release version
get_latest_version() {
local url="https://api.github.com/repos/${REPO}/releases/latest"
if command -v curl &> /dev/null; then
curl -fsSL "$url" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/'
elif command -v wget &> /dev/null; then
wget -qO- "$url" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/'
else
error "curl or wget is required"
fi
}
# Download file
download() {
local url="$1"
local output="$2"
info "Downloading from: $url"
if command -v curl &> /dev/null; then
curl -fsSL "$url" -o "$output"
elif command -v wget &> /dev/null; then
wget -q "$url" -O "$output"
else
error "curl or wget is required"
fi
}
main() {
echo ""
echo -e "${BLUE}╔════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║${NC} ${GREEN}httpulse${NC} Installer ${BLUE}║${NC}"
echo -e "${BLUE}╚════════════════════════════════════════╝${NC}"
echo ""
# Detect platform
local os=$(detect_os)
local arch=$(detect_arch)
local target=$(get_target "$os" "$arch")
info "Detected platform: ${os}/${arch}"
info "Target: ${target}"
# Get version
local version="${VERSION:-}"
if [[ -z "$version" ]]; then
info "Fetching latest version..."
version=$(get_latest_version)
fi
if [[ -z "$version" ]]; then
error "Failed to determine version. Set VERSION env var or check network."
fi
info "Version: ${version}"
# Build download URL
local filename="${BINARY_NAME}-${target}.tar.gz"
local url="https://github.com/${REPO}/releases/download/${version}/${filename}"
# Create temp directory
local tmpdir=$(mktemp -d)
trap "rm -rf $tmpdir" EXIT
# Download
download "$url" "${tmpdir}/${filename}"
# Extract
info "Extracting..."
tar -xzf "${tmpdir}/${filename}" -C "$tmpdir"
# Install
info "Installing to ${INSTALL_DIR}..."
# Create install directory if it doesn't exist
if [[ ! -d "$INSTALL_DIR" ]]; then
info "Creating directory ${INSTALL_DIR}..."
mkdir -p "$INSTALL_DIR"
fi
if [[ -w "$INSTALL_DIR" ]]; then
mv "${tmpdir}/${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}"
chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
else
warn "Need sudo to install to ${INSTALL_DIR}"
sudo mv "${tmpdir}/${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}"
sudo chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
fi
success "Successfully installed ${BINARY_NAME} ${version}"
echo ""
# Check if INSTALL_DIR is in PATH
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
warn "${INSTALL_DIR} is not in your PATH"
echo ""
info "Add it to your shell config:"
echo ""
echo " # For bash (~/.bashrc or ~/.bash_profile):"
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
echo ""
echo " # For zsh (~/.zshrc):"
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
echo ""
echo " # For fish (~/.config/fish/config.fish):"
echo " fish_add_path \$HOME/.local/bin"
echo ""
info "Then restart your shell or run: source ~/.zshrc (or your shell config)"
else
info "Run '${BINARY_NAME} --help' to get started"
fi
echo ""
}
main "$@"