-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathinstall.sh
executable file
·116 lines (95 loc) · 2.62 KB
/
install.sh
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
#!/usr/bin/env bash
set -e
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"
VERSION=$(curl -s $LATEST_RELEASE_URL | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
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)
curl -L "$DOWNLOAD_URL" -o "${TMP_DIR}/lla"
if [ $? -ne 0 ]; then
print_error "Failed to download binary"
rm -rf "$TMP_DIR"
exit 1
fi
}
verify_checksum() {
print_step "Verifying checksum..."
CHECKSUM_URL="https://github.com/chaqchase/lla/releases/download/${VERSION}/SHA256SUMS"
curl -L "$CHECKSUM_URL" -o "${TMP_DIR}/SHA256SUMS"
cd "$TMP_DIR"
mkdir "${PLATFORM}"
cp lla "${PLATFORM}/${PLATFORM}"
if ! sha256sum -c --ignore-missing SHA256SUMS; then
print_error "Checksum verification failed"
cd - > /dev/null
rm -rf "$TMP_DIR"
exit 1
fi
cd - > /dev/null
}
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"
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