-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·142 lines (118 loc) · 3.64 KB
/
install.sh
File metadata and controls
executable file
·142 lines (118 loc) · 3.64 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
#!/usr/bin/env bash
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m'
print_step() {
echo -e "${BLUE}==>${NC} $1"
}
print_success() {
echo -e "${GREEN}==>${NC} $1"
}
print_error() {
echo -e "${RED}==>${NC} $1"
}
detect_platform() {
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Linux) OS="linux" ;;
Darwin) OS="macos" ;;
*)
print_error "Unsupported operating system: $OS"
exit 1
;;
esac
case "$ARCH" in
x86_64) ARCH="amd64" ;;
aarch64) ARCH="arm64" ;;
arm64) ARCH="arm64" ;;
i386) ARCH="i686" ;;
i686) ARCH="i686" ;;
*)
print_error "Unsupported architecture: $ARCH"
exit 1
;;
esac
PLATFORM="lla-${OS}-${ARCH}"
}
get_latest_version() {
LATEST_RELEASE_URL="https://api.github.com/repos/chaqchase/lla/releases/latest"
local json
json="$(curl -fsSL "$LATEST_RELEASE_URL")"
VERSION="$(
printf '%s\n' "$json" \
| grep -m 1 '"tag_name":' \
| sed -E 's/.*"tag_name":[[:space:]]*"([^"]+)".*/\1/' \
|| true
)"
if [ -z "$VERSION" ]; then
print_error "Failed to fetch latest version"
exit 1
fi
}
download_binary() {
print_step "Downloading lla ${VERSION} for ${OS}-${ARCH}..."
DOWNLOAD_URL="https://github.com/chaqchase/lla/releases/download/${VERSION}/${PLATFORM}"
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT
if ! curl -fsSL "$DOWNLOAD_URL" -o "${TMP_DIR}/lla"; then
print_error "Failed to download binary"
exit 1
fi
}
verify_checksum() {
print_step "Verifying checksum..."
CHECKSUM_URL="https://github.com/chaqchase/lla/releases/download/${VERSION}/SHA256SUMS"
if ! curl -fsSL "$CHECKSUM_URL" -o "${TMP_DIR}/SHA256SUMS"; then
print_error "Failed to download checksum manifest (SHA256SUMS)"
exit 1
fi
expected_line="$(grep -E "[[:space:]]${PLATFORM}$" "${TMP_DIR}/SHA256SUMS" | head -n 1 || true)"
expected="$(printf '%s' "$expected_line" | awk '{print $1}' || true)"
expected="${expected##*:}"
if [ -z "$expected" ]; then
print_error "No checksum entry found for ${PLATFORM} in SHA256SUMS"
exit 1
fi
if command -v sha256sum >/dev/null 2>&1; then
actual="$(sha256sum "${TMP_DIR}/lla" | awk '{print $1}')"
elif command -v shasum >/dev/null 2>&1; then
actual="$(shasum -a 256 "${TMP_DIR}/lla" | awk '{print $1}')"
else
print_error "Neither sha256sum nor shasum is available for checksum verification"
exit 1
fi
actual_lc="$(printf '%s' "$actual" | tr '[:upper:]' '[:lower:]')"
expected_lc="$(printf '%s' "$expected" | tr '[:upper:]' '[:lower:]')"
if [ "$actual_lc" != "$expected_lc" ]; then
print_error "Checksum verification failed"
print_error "Expected: ${expected}"
print_error "Actual: ${actual}"
exit 1
fi
}
install_binary() {
print_step "Installing lla to /usr/local/bin..."
sudo mkdir -p /usr/local/bin
sudo chmod +x "${TMP_DIR}/lla"
sudo mv "${TMP_DIR}/lla" /usr/local/bin/
rm -rf "$TMP_DIR"
trap - EXIT
print_success "lla ${VERSION} has been installed successfully!"
print_success "Run 'lla init' to create your configuration file"
}
main() {
print_step "Installing lla..."
if ! command -v curl >/dev/null 2>&1; then
print_error "curl is required but not installed"
exit 1
fi
detect_platform
get_latest_version
download_binary
verify_checksum
install_binary
}
main