Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
90 lines (78 loc) Β· 2.53 KB
/
Copy pathinstall.sh
File metadata and controls
90 lines (78 loc) Β· 2.53 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
#!/bin/bash
set -e
# Function to detect the OS
detect_os() {
case "$(uname -s)" in
Linux*) echo "linux";;
Darwin*) echo "macOS";;
CYGWIN*|MINGW*) echo "windows";;
*) echo "unknown";;
esac
}
# Function to get the latest release version
get_latest_version() {
curl --silent "https://api.github.com/repos/wadmit/era/releases/latest" |
grep '"tag_name":' |
sed -E 's/.*"([^"]+)".*/\1/' |
sed 's/v//'
}
# Function to download and install the binary
install_binary() {
local os=$1
local release_version=$(get_latest_version)
local file_name
local download_url
local binary_path
local extracted_file_name
case "$os" in
linux)
file_name="era_linux_v${release_version}.tar.gz"
binary_path="/usr/local/bin/era"
extracted_file_name="era_linux_v${release_version}"
;;
macOS)
file_name="era_macOS_v${release_version}.tar.gz"
binary_path="/usr/local/bin/era"
extracted_file_name="era_macOS_v${release_version}"
;;
windows)
file_name="era_windows_v${release_version}.zip"
binary_path="$USERPROFILE\\AppData\\Local\\era\\era.exe"
extracted_file_name="era_windows_v${release_version}.exe"
;;
*)
echo "Unsupported OS"
exit 1
;;
esac
download_url="https://github.com/wadmit/era/releases/download/v${release_version}/${file_name}"
# Download the binary
echo "Downloading $file_name from $download_url..."
curl -Lo "$file_name" "$download_url"
# Verify the file format and extract
echo "Verifying and installing..."
if [ "$os" = "windows" ]; then
# For Windows, extract using PowerShell
powershell -Command "Expand-Archive -Path $file_name -DestinationPath $USERPROFILE\\AppData\\Local\\era"
mv "$USERPROFILE\\AppData\\Local\\era\\build\\$extracted_file_name" "$binary_path"
# Update PATH environment variable
echo "Updating PATH environment variable..."
powershell -Command "[System.Environment]::SetEnvironmentVariable('PATH', '$env:PATH;$USERPROFILE\\AppData\\Local\\era', [System.EnvironmentVariableTarget]::User)"
else
# For Linux and macOS
if file "$file_name" | grep -q "gzip compressed data"; then
tar -xzf "$file_name"
chmod +x "$extracted_file_name"
sudo mv "$extracted_file_name" "$binary_path"
else
echo "Error: The downloaded file is not in gzip format."
exit 1
fi
fi
# Clean up
rm "$file_name"
echo "ERA version $release_version installed successfully."
}
# Main script execution for OS
os=$(detect_os)
install_binary "$os"