Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ jobs:
uses: dtolnay/rust-toolchain@stable

- name: Build
run: cargo build --release -p usehid-core
run: cargo build --release -p usehid

- name: Build CLI
run: cargo build --release -p usehid-cli

- name: Test
run: cargo test -p usehid-core
run: cargo test -p usehid

build-python:
name: Build Python wheels
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,4 @@ jobs:
uses: softprops/action-gh-release@v2
with:
files: release/*

78 changes: 78 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/sh
set -eu

REPO="jiusanzhou/usehid"
BINARY="usehid"
INSTALL_DIR="${USEHID_INSTALL_DIR:-/usr/local/bin}"

get_arch() {
arch=$(uname -m)
case "$arch" in
x86_64|amd64) echo "x86_64" ;;
arm64|aarch64) echo "arm64" ;;
*) echo "Unsupported architecture: $arch" >&2; exit 1 ;;
esac
}

get_os() {
os=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$os" in
linux) echo "linux" ;;
darwin) echo "macos" ;;
*) echo "Unsupported OS: $os" >&2; exit 1 ;;
esac
}

get_latest_version() {
if command -v curl > /dev/null 2>&1; then
curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name"' | sed -E 's/.*"v([^"]+)".*/\1/'
elif command -v wget > /dev/null 2>&1; then
wget -qO- "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name"' | sed -E 's/.*"v([^"]+)".*/\1/'
else
echo "curl or wget is required" >&2; exit 1
fi
}

download() {
url="$1"
output="$2"
if command -v curl > /dev/null 2>&1; then
curl -fsSL "$url" -o "$output"
elif command -v wget > /dev/null 2>&1; then
wget -qO "$output" "$url"
fi
}

main() {
os=$(get_os)
arch=$(get_arch)
version="${USEHID_VERSION:-$(get_latest_version)}"

if [ -z "$version" ]; then
echo "Failed to determine latest version" >&2
exit 1
fi

artifact="${BINARY}-${os}-${arch}"
url="https://github.com/${REPO}/releases/download/v${version}/${artifact}"

echo "Installing usehid v${version} (${os}/${arch})..."

tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT

download "$url" "$tmpdir/$BINARY"
chmod +x "$tmpdir/$BINARY"

if [ -w "$INSTALL_DIR" ]; then
mv "$tmpdir/$BINARY" "$INSTALL_DIR/$BINARY"
else
echo "Need sudo to install to $INSTALL_DIR"
sudo mv "$tmpdir/$BINARY" "$INSTALL_DIR/$BINARY"
fi

echo "Installed usehid to $INSTALL_DIR/$BINARY"
echo "Run 'usehid --help' to get started"
}

main
Loading