-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·216 lines (184 loc) · 5.92 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·216 lines (184 loc) · 5.92 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/bash
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
REPO="aldevv/katac"
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
echo -e "${BLUE}Installing katac...${NC}"
# Detect OS
detect_os() {
case "$(uname -s)" in
Linux*) echo "linux";;
Darwin*) echo "darwin";;
MINGW*|MSYS*|CYGWIN*) echo "windows";;
*) echo "unknown";;
esac
}
# Detect architecture
detect_arch() {
case "$(uname -m)" in
x86_64|amd64) echo "x86_64";;
aarch64|arm64) echo "aarch64";;
armv7l) echo "armv7";;
i686|i386) echo "i686";;
*) echo "unknown";;
esac
}
# Detect libc on Linux. Alpine and other musl-based distros need the musl
# binary, otherwise the dynamic loader fails to find glibc at runtime.
detect_libc() {
if [ -e /lib/ld-musl-x86_64.so.1 ] || [ -e /lib/ld-musl-aarch64.so.1 ]; then
echo "musl"
elif ldd /bin/sh 2>&1 | grep -qi musl; then
echo "musl"
else
echo "gnu"
fi
}
# Get the target triple based on OS and architecture
get_target() {
local os=$1
local arch=$2
case "$os-$arch" in
linux-x86_64)
if [ "$(detect_libc)" = "musl" ]; then
echo "x86_64-unknown-linux-musl"
else
echo "x86_64-unknown-linux-gnu"
fi
;;
linux-aarch64) echo "aarch64-unknown-linux-gnu";;
linux-armv7) echo "armv7-unknown-linux-gnueabihf";;
darwin-x86_64) echo "x86_64-apple-darwin";;
darwin-aarch64) echo "aarch64-apple-darwin";;
windows-x86_64) echo "x86_64-pc-windows-msvc";;
windows-i686) echo "i686-pc-windows-msvc";;
windows-aarch64) echo "aarch64-pc-windows-msvc";;
*) echo "unknown";;
esac
}
# Get the latest release version from GitHub
get_latest_version() {
curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" \
| grep '"tag_name":' \
| sed -E 's/.*"([^"]+)".*/\1/' \
|| echo ""
}
# Download and install binary from GitHub releases
install_from_binary() {
local os=$(detect_os)
local arch=$(detect_arch)
local target=$(get_target "$os" "$arch")
if [ "$os" = "unknown" ] || [ "$arch" = "unknown" ] || [ "$target" = "unknown" ]; then
echo -e "${YELLOW}⚠ Could not detect system type (OS: $os, Arch: $arch)${NC}"
return 1
fi
echo -e "${BLUE}Detected: $os ($arch)${NC}"
echo -e "${BLUE}Target: $target${NC}"
# Get latest version
echo -e "${BLUE}Fetching latest release...${NC}"
local version=$(get_latest_version)
if [ -z "$version" ]; then
echo -e "${YELLOW}⚠ Could not fetch latest release version${NC}"
return 1
fi
echo -e "${GREEN}Latest version: $version${NC}"
# Construct download URL
local ext="tar.gz"
if [ "$os" = "windows" ]; then
ext="zip"
fi
local filename="katac-${target}.${ext}"
local url="https://github.com/$REPO/releases/download/$version/$filename"
echo -e "${BLUE}Downloading from: $url${NC}"
# Create temp directory
local tmp_dir=$(mktemp -d)
trap "rm -rf $tmp_dir" EXIT
# Download
if ! curl -fsSL "$url" -o "$tmp_dir/$filename"; then
echo -e "${YELLOW}⚠ Failed to download binary${NC}"
return 1
fi
# Extract
echo -e "${BLUE}Extracting...${NC}"
cd "$tmp_dir"
if [ "$ext" = "zip" ]; then
if command -v unzip &> /dev/null; then
unzip -q "$filename"
else
echo -e "${RED}✗ unzip not found${NC}"
return 1
fi
else
tar xzf "$filename"
fi
# Find the binary
local binary="katac"
if [ "$os" = "windows" ]; then
binary="katac.exe"
fi
if [ ! -f "$binary" ]; then
echo -e "${RED}✗ Binary not found in archive${NC}"
return 1
fi
# Make executable
chmod +x "$binary"
# Install
echo -e "${BLUE}Installing to $INSTALL_DIR...${NC}"
mkdir -p "$INSTALL_DIR"
if mv "$binary" "$INSTALL_DIR/"; then
echo -e "${GREEN}✓ katac installed successfully to $INSTALL_DIR/$binary${NC}"
return 0
else
echo -e "${RED}✗ Failed to install binary${NC}"
return 1
fi
}
# Fallback: Install from source using cargo
install_from_source() {
echo -e "${BLUE}Installing from source using cargo...${NC}"
if ! command -v cargo &> /dev/null; then
echo -e "${RED}✗ Cargo not found.${NC}"
echo -e "${YELLOW}Please install Rust from: https://rustup.rs${NC}"
exit 1
fi
cargo install --git "https://github.com/$REPO"
echo -e "${GREEN}✓ katac installed successfully!${NC}"
echo -e "${BLUE}Cargo installs binaries to ~/.cargo/bin — make sure it's on your PATH.${NC}"
}
# Check if we should use binary installation
USE_BINARY=1
if [ "$1" = "--source" ]; then
USE_BINARY=0
echo -e "${YELLOW}Building from source (--source flag)${NC}"
fi
# Try binary installation first, fall back to source
if [ $USE_BINARY -eq 1 ]; then
if install_from_binary; then
echo ""
echo -e "${GREEN}Installation complete!${NC}"
echo -e "${BLUE}Make sure $INSTALL_DIR is in your PATH${NC}"
echo ""
echo -e "Add this to your shell config (~/.bashrc, ~/.zshrc, etc.):"
echo -e "${YELLOW} export PATH=\"\$PATH:$INSTALL_DIR\"${NC}"
echo ""
echo -e "Verify with '${GREEN}katac --version${NC}'"
echo -e "Run '${GREEN}katac --help${NC}' to get started"
exit 0
else
echo ""
echo -e "${YELLOW}Binary installation failed, falling back to building from source...${NC}"
echo ""
install_from_source
fi
else
install_from_source
fi
echo ""
echo -e "${GREEN}Installation complete!${NC}"
echo -e "Verify with '${GREEN}katac --version${NC}'"
echo -e "Run '${GREEN}katac --help${NC}' to get started"