-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathinstall.sh
executable file
·85 lines (70 loc) · 2.14 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
#!/bin/bash
set -e
# Change to script directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"
# Function to check if running locally with proper module
check_local_install() {
if [ -f "go.mod" ]; then
FIRST_LINE=$(head -n 1 go.mod)
if [ "$FIRST_LINE" = "module github.com/goplus/llgo" ]; then
return 0
fi
fi
return 1
}
# Function to get latest release version
get_latest_version() {
curl --silent "https://api.github.com/repos/goplus/llgo/releases/latest" |
grep '"tag_name":' |
sed -E 's/.*"([^"]+)".*/\1/'
}
# Function to get system information
get_system_info() {
ARCH=$(uname -m)
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
case $ARCH in
x86_64) ARCH="amd64" ;;
aarch64) ARCH="arm64" ;;
esac
echo "${OS}-${ARCH}"
}
# Function to install from local source
install_local() {
echo "Installing llgo from local source..."
cd compiler
go install ./cmd/llgo
echo "Local installation complete."
echo "llgo is now available in your GOPATH."
}
# Function to install from remote release
install_remote() {
VERSION=$(get_latest_version)
VERSION_NO_V=${VERSION#v} # Remove the 'v' prefix
SYSTEM=$(get_system_info)
INSTALL_DIR="$HOME/.llgo"
DOWNLOAD_URL="https://github.com/goplus/llgo/releases/download/${VERSION}/llgo${VERSION_NO_V}.${SYSTEM}"
echo "Installing llgo ${VERSION} for ${SYSTEM}..."
# Create installation directory
mkdir -p "$INSTALL_DIR"
# Download and extract
curl -L "$DOWNLOAD_URL.tar.gz" | tar xz -C "$INSTALL_DIR"
# Handle old package structures
if [ -f "$INSTALL_DIR/llgo" ]; then
mkdir -p "$INSTALL_DIR/bin"
mv "$INSTALL_DIR/llgo" "$INSTALL_DIR/bin/"
fi
echo "Installation complete!"
echo
echo "Please add the following line to your shell configuration file (.bashrc, .zshrc, etc.):"
echo "export PATH=\$PATH:$INSTALL_DIR/bin"
echo
echo "Then restart your shell or run:"
echo "source ~/.bashrc # or source ~/.zshrc"
}
# Main installation logic
if check_local_install; then
install_local
else
install_remote
fi