-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinternal_release.sh
executable file
·128 lines (104 loc) · 4.51 KB
/
internal_release.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
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
# GitHub repository information
REPO_OWNER="HexmosTech"
REPO_NAME_CORE="Lama2"
REPO_NAME_EXTENSION="Lama2Code"
# Function to get system architecture
get_architecture() {
case $(uname -m) in
i386) echo "386" ;;
i686) echo "386" ;;
x86_64) echo "amd64" ;;
arm) dpkg --print-architecture | grep -q "arm64" && echo "arm64" || echo "arm" ;;
arm64) echo "arm64" ;;
*) echo "unknown" && exit 1 ;;
esac
}
# Function to get operating system
get_os() {
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
echo "linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo "darwin"
else
echo "unsupported" && exit 1
fi
}
# Function to download and install the Lama2 binary
download_and_install_l2() {
# Fetch the latest pre-release information
echo -e "${GREEN}Fetching latest pre-release information...${NC}"
RELEASE_INFO=$(curl -s "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME_CORE/releases" | jq '[.[] | select(.prerelease == true)] | first')
if [ -z "$RELEASE_INFO" ] || [ "$RELEASE_INFO" = "null" ]; then
echo -e "${RED}No pre-release found${NC}"
exit 1
fi
# Get system information
ARCH=$(get_architecture)
OS=$(get_os)
# Extract the binary download URL
BINARY_URL=$(echo "$RELEASE_INFO" | jq -r --arg OS "$OS" --arg ARCH "$ARCH" '.assets[] | select(.name | contains($OS) and contains($ARCH) and endswith(".tar.gz")) | .browser_download_url')
TAG_NAME=$(echo "$RELEASE_INFO" | jq -r '.tag_name')
if [ -z "$BINARY_URL" ] || [ "$BINARY_URL" = "null" ]; then
echo -e "${RED}No compatible binary file found in the latest pre-release${NC}"
exit 1
fi
echo -e "${GREEN}Downloading l2 binary from $BINARY_URL${NC}"
curl -L -o /tmp/l2_latest.tar.gz "$BINARY_URL"
tar -xvzf /tmp/l2_latest.tar.gz -C /tmp
sudo rm -f /usr/local/bin/l2 /usr/bin/l2
sudo mv /tmp/l2 /usr/local/bin
sudo chmod +x /usr/local/bin/l2
}
# Function to download and install the VSIX
download_and_install_vsix() {
# Fetch the latest pre-release information
echo -e "${GREEN}Fetching latest pre-release information...${NC}"
RELEASE_INFO=$(curl -s "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME_EXTENSION/releases" | jq '[.[] | select(.prerelease == true)] | first')
if [ -z "$RELEASE_INFO" ] || [ "$RELEASE_INFO" = "null" ]; then
echo -e "${RED}No pre-release found${NC}"
exit 1
fi
# Extract the VSIX download URL and tag name
VSIX_URL=$(echo "$RELEASE_INFO" | jq -r '.assets[] | select(.name | endswith(".vsix")) | .browser_download_url')
TAG_NAME=$(echo "$RELEASE_INFO" | jq -r '.tag_name')
if [ -z "$VSIX_URL" ] || [ "$VSIX_URL" = "null" ]; then
echo -e "${RED}No VSIX file found in the latest pre-release${NC}"
exit 1
fi
echo -e "${GREEN}Downloading VSIX file from $VSIX_URL${NC}"
wget -O "/tmp/$TAG_NAME.vsix" "$VSIX_URL"
if [ $? -ne 0 ]; then
echo -e "${RED}Failed to download VSIX file${NC}"
exit 1
fi
echo -e "${GREEN}Installing VSIX in VS Code${NC}"
code --install-extension "/tmp/$TAG_NAME.vsix"
if [ $? -ne 0 ]; then
echo -e "${RED}Failed to install VSIX in VS Code${NC}"
exit 1
fi
rm "/tmp/$TAG_NAME.vsix"
echo -e "${GREEN}Successfully installed $TAG_NAME${NC}"
}
# Check if required tools are installed
command -v jq >/dev/null 2>&1 || { echo -e >&2 "${RED}This script requires jq but it's not installed. Please install it and try again.${NC}"; exit 1; }
command -v curl >/dev/null 2>&1 || { echo -e >&2 "${RED}This script requires curl but it's not installed. Please install it and try again.${NC}"; exit 1; }
command -v wget >/dev/null 2>&1 || { echo -e >&2 "${RED}This script requires wget but it's not installed. Please install it and try again.${NC}"; exit 1; }
command -v code >/dev/null 2>&1 || { echo -e >&2 "${RED}This script requires VS Code to be installed and accessible via 'code' command.${NC}"; exit 1; }
# Main execution
download_and_install_l2
if l2 --version > /dev/null 2>&1; then
echo -e "${GREEN}Successfully installed Lama2 beta version; Type 'l2 <api_file>' to invoke Lama2${NC}"
echo -e "${YELLOW}Installed version:${NC}"
l2 --version
# Download and install VSIX after successful l2 installation
download_and_install_vsix
else
echo -e "${RED}Failure in installation; please report issue at github.com/HexmosTech/Lama2${NC}"
fi