-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathinstall.sh
More file actions
121 lines (98 loc) · 3.25 KB
/
install.sh
File metadata and controls
121 lines (98 loc) · 3.25 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
#!/usr/bin/env bash
set -euo pipefail
BINARY_NAME="llogin"
REPO_OWNER="ba3a-g"
REPO_NAME="LPU-Wireless-Autologin"
GITHUB_BASE="https://github.com/${REPO_OWNER}/${REPO_NAME}"
GITHUB_API="https://git.ba3a.tech/repos/${REPO_OWNER}/${REPO_NAME}"
error() {
echo "Error: $1" >&2
exit 1
}
get_latest_version() {
local latest_version
latest_version=$(curl -fsSL "${GITHUB_API}/releases/latest" |
grep '"tag_name":' |
sed -E 's/.*"([^"]+)".*/\1/' |
sed 's/^v//')
if [ -z "$latest_version" ]; then
error "Failed to fetch latest version"
fi
echo "$latest_version"
}
VERSION="${1:-$(get_latest_version)}"
detect_platform() {
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Linux) OS="linux" ;;
Darwin) OS="macos" ;;
MINGW*|MSYS*|CYGWIN*|Windows_NT)
OS="windows"
;;
*) error "Unsupported operating system: $OS" ;;
esac
case "$ARCH" in
x86_64|amd64) ARCH="x86_64" ;;
arm64|aarch64) ARCH="aarch64" ;;
*) error "Unsupported architecture: $ARCH" ;;
esac
if [ "$OS" = "windows" ]; then
ARCH="x86_64"
fi
}
install_binary() {
local extension=""
[ "$OS" = "windows" ] && extension=".exe"
local binary_name="${BINARY_NAME}-${VERSION}-${OS}-${ARCH}${extension}"
local download_url="${GITHUB_BASE}/releases/download/v${VERSION}/${binary_name}"
local temp_dir
temp_dir="$(mktemp -d)"
local temp_file="${temp_dir}/${binary_name}"
echo "Downloading ${BINARY_NAME} v${VERSION} for ${OS}-${ARCH}..."
if ! curl -fsSL -I "$download_url" >/dev/null 2>&1; then
rm -rf "$temp_dir"
error "Release v${VERSION} not found or asset unavailable"
fi
if ! curl -fsSL "$download_url" -o "$temp_file"; then
rm -rf "$temp_dir"
error "Failed to download binary"
fi
chmod +x "$temp_file"
if [ "$OS" = "windows" ]; then
local install_dir="$HOME/bin"
mkdir -p "$install_dir"
mv "$temp_file" "$install_dir/${binary_name}"
(cd "$install_dir" && \
rm -f "${BINARY_NAME}${extension}" && \
ln -s "${binary_name}" "${BINARY_NAME}${extension}")
echo "Installed to: $install_dir/${binary_name}"
echo "Created symlink: $install_dir/${BINARY_NAME}${extension}"
echo "Make sure $install_dir is in your PATH"
else
sudo mv "$temp_file" "/usr/local/bin/${binary_name}"
sudo ln -sf "/usr/local/bin/${binary_name}" "/usr/local/bin/${BINARY_NAME}"
echo "Installed to: /usr/local/bin/${binary_name}"
echo "Created symlink: /usr/local/bin/${BINARY_NAME}"
fi
rm -rf "$temp_dir"
}
verify_installation() {
if command -v "$BINARY_NAME" >/dev/null; then
echo "✓ Installation verified: $(command -v "$BINARY_NAME")"
echo "Version: v${VERSION}"
else
error "Installation verification failed. Please check your PATH"
fi
}
main() {
echo "Installing ${BINARY_NAME} v${VERSION}..."
if ! command -v curl >/dev/null; then
error "curl is required but not installed"
fi
detect_platform
install_binary
verify_installation
echo "Installation completed successfully!"
}
main