-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·104 lines (88 loc) · 2.65 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
#!/bin/bash
set -e
# Function to output error messages
error() {
echo "Error: $1" >&2
exit 1
}
# Function to detect OS and architecture
detect_platform() {
local os arch
# Detect OS
case "$(uname -s)" in
Linux*) os="linux";;
Darwin*) os="darwin";;
MINGW*|MSYS*|CYGWIN*) os="windows";;
*) error "Unsupported operating system: $(uname -s)";;
esac
# Detect architecture
case "$(uname -m)" in
x86_64|amd64) arch="amd64";;
arm64|aarch64) arch="arm64";;
i386|i686) arch="386";;
*) error "Unsupported architecture: $(uname -m)";;
esac
echo "${os}_${arch}"
}
# Function to download and install
install_glearn() {
local platform="$1"
local repo="nothr/glearn-notifier"
local tmp_dir
tmp_dir=$(mktemp -d)
echo "Detecting latest version..."
# Get the latest release URL
if ! command -v curl &> /dev/null; then
error "curl is required but not installed"
fi
if [ "$platform" = "windows_amd64" ] || [ "$platform" = "windows_386" ]; then
ext="zip"
else
ext="tar.gz"
fi
echo "Downloading latest release for $platform..."
release_url=$(curl -s "https://api.github.com/repos/$repo/releases/latest" | \
grep "browser_download_url.*${platform}.${ext}" | \
cut -d '"' -f 4)
if [ -z "$release_url" ]; then
error "Could not find release for platform: $platform"
fi
# Download the release
echo "Downloading from $release_url..."
curl -L "$release_url" -o "$tmp_dir/glearn-notifier.$ext"
# Extract the archive
echo "Extracting archive..."
cd "$tmp_dir"
case "$ext" in
"tar.gz")
tar xzf "glearn-notifier.$ext"
;;
"zip")
if ! command -v unzip &> /dev/null; then
error "unzip is required but not installed"
fi
unzip "glearn-notifier.$ext"
;;
esac
# Install the binary
if [ "$platform" = "windows_amd64" ] || [ "$platform" = "windows_386" ]; then
echo "Binary extracted to $tmp_dir/glearn-notifier.exe"
echo "Please move it to a directory in your PATH"
else
echo "Installing to /usr/local/bin/glearn-notifier..."
sudo mv glearn-notifier /usr/local/bin/
sudo chmod +x /usr/local/bin/glearn-notifier
fi
# Cleanup
cd - > /dev/null
rm -rf "$tmp_dir"
echo "Installation completed successfully!"
}
# Main script
main() {
echo "Detecting platform..."
platform=$(detect_platform)
echo "Detected platform: $platform"
install_glearn "$platform"
}
main