-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·183 lines (158 loc) · 5.08 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·183 lines (158 loc) · 5.08 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env sh
# covecto installer — https://github.com/codecoradev/covecto
# Usage: curl -fsSL https://codecora.dev/covecto/install | sh
set -e
REPO="codecoradev/covecto"
BINARY_NAME="covecto"
INSTALL_DIR="${COVECTO_INSTALL_DIR:-$HOME/.local/bin}"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
info() {
printf "${GREEN}[INFO]${NC} %s\n" "$1"
}
warn() {
printf "${YELLOW}[WARN]${NC} %s\n" "$1"
}
error() {
printf "${RED}[ERROR]${NC} %s\n" "$1"
exit 1
}
# Detect OS
detect_os() {
case "$(uname -s)" in
Linux*) OS="linux";;
Darwin*) OS="darwin";;
*) error "Unsupported operating system: $(uname -s)";;
esac
}
# Detect architecture
detect_arch() {
case "$(uname -m)" in
x86_64|amd64) ARCH="x86_64";;
arm64|aarch64) ARCH="aarch64";;
*) error "Unsupported architecture: $(uname -m)";;
esac
}
# Get latest release version
get_latest_version() {
VERSION=$(curl -sI "https://github.com/${REPO}/releases/latest" \
| grep -i '^location:' \
| sed -E 's|.*/tag/([^[:space:]]+).*|\1|' \
| tr -d '\r')
if [ -z "$VERSION" ]; then
warn "Redirect lookup failed, falling back to GitHub API..."
VERSION=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name":' \
| sed -E 's/.*"([^"]+)".*/\1/')
fi
if [ -z "$VERSION" ]; then
error "Failed to get latest version. Set COVECTO_VERSION=vX.Y.Z to pin a version."
fi
}
# Build target triple
get_target() {
case "$OS" in
linux)
case "$ARCH" in
x86_64) TARGET="x86_64-unknown-linux-gnu";;
aarch64) TARGET="aarch64-unknown-linux-gnu";;
esac
;;
darwin)
if [ "$ARCH" != "aarch64" ]; then
warn "No pre-built binary for x86_64 macOS. Install via cargo:"
warn " cargo install --path crates/covecto-cli"
exit 0
fi
TARGET="aarch64-apple-darwin"
;;
esac
}
# Download and install
install() {
info "Detected: $OS $ARCH"
info "Target: $TARGET"
info "Version: $VERSION"
ARCHIVE_NAME="${BINARY_NAME}-${TARGET}-${VERSION}.tar.gz"
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${VERSION}/${ARCHIVE_NAME}"
TEMP_DIR=$(mktemp -d)
ARCHIVE="${TEMP_DIR}/${ARCHIVE_NAME}"
CHECKSUMS_URL="https://github.com/${REPO}/releases/download/${VERSION}/checksums-sha256.txt"
CHECKSUM_FILE="${TEMP_DIR}/checksums-sha256.txt"
info "Downloading from: $DOWNLOAD_URL"
if ! curl -fsSL "$DOWNLOAD_URL" -o "$ARCHIVE"; then
error "Failed to download ${ARCHIVE_NAME}"
fi
# Verify SHA256 checksum
info "Downloading checksums..."
if curl -fsSL "$CHECKSUMS_URL" -o "$CHECKSUM_FILE"; then
info "Verifying SHA256 checksum..."
EXPECTED=$(grep -F "$ARCHIVE_NAME" "$CHECKSUM_FILE" | awk '{print $1}')
if [ -n "$EXPECTED" ]; then
ACTUAL=$(sha256sum "$ARCHIVE" | awk '{print $1}')
if [ "$ACTUAL" != "$EXPECTED" ]; then
error "Checksum mismatch! Expected: ${EXPECTED}, got: ${ACTUAL}"
fi
info "Checksum verified: $EXPECTED"
else
warn "Checksum for ${ARCHIVE_NAME} not found — skipping verification"
fi
else
warn "Failed to download checksums — skipping verification"
fi
# Verify archive integrity (CWE-22)
info "Verifying archive integrity..."
if tar -tzf "$ARCHIVE" | grep -qE '^/|(^|/)\.\.(/|$)'; then
error "Archive contains unsafe paths — refusing to extract"
fi
info "Extracting..."
tar -xzf "$ARCHIVE" -C "$TEMP_DIR"
mkdir -p "$INSTALL_DIR"
mv "${TEMP_DIR}/${BINARY_NAME}" "${INSTALL_DIR}/"
chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
rm -rf "$TEMP_DIR"
info "Successfully installed ${BINARY_NAME} to ${INSTALL_DIR}/${BINARY_NAME}"
}
# Verify
verify() {
if command -v "$BINARY_NAME" >/dev/null 2>&1; then
INSTALLED_VERSION=$("$BINARY_NAME" --version 2>/dev/null || echo "unknown")
info "Verification: $INSTALLED_VERSION"
else
warn "Binary installed but not in PATH. Add to your shell profile:"
case "${SHELL:-}" in
*/zsh)
warn ' echo '\''export PATH="$HOME/.local/bin:$PATH"'\'' >> ~/.zshrc'
;;
*/bash)
warn ' echo '\''export PATH="$HOME/.local/bin:$PATH"'\'' >> ~/.bashrc'
;;
*/fish)
warn ' fish_add_path ~/.local/bin'
;;
*)
warn ' export PATH="$HOME/.local/bin:$PATH"'
;;
esac
fi
}
main() {
info "Installing ${BINARY_NAME}..."
detect_os
detect_arch
get_target
if [ -n "$COVECTO_VERSION" ]; then
VERSION="$COVECTO_VERSION"
info "Using pinned version: $VERSION"
else
get_latest_version
fi
install
verify
echo ""
info "Done! Run '${BINARY_NAME} --help' to get started."
}
main