lesavka/scripts/install-client.sh

56 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# 1) Install system dependencies (Arch Linux)
sudo pacman -S --needed --noconfirm git rustup protobuf gcc evtest
# 2) Ensure Rust toolchain is present
rustup toolchain install stable
# 3) Determine repo URL from the current directory
# We assume this script lives under <repo-root>/scripts/install-client.sh
REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)"
REPO_URL="$(git -C "$REPO_DIR" config --get remote.origin.url)"
if [ -z "$REPO_URL" ]; then
echo "Error: could not read git remote.origin.url from $REPO_DIR"
exit 1
fi
# 4) Where to clone/build if not already present
WORK="$HOME/.local/src/navka"
if [ ! -d "$WORK" ]; then
git clone "$REPO_URL" "$WORK"
else
pushd "$WORK" >/dev/null
git fetch --all
git reset --hard origin/$(git -C "$WORK" rev-parse --abbrev-ref HEAD)
popd >/dev/null
fi
# 5) Build the client
cd "$WORK"
cargo build --release --manifest-path client/Cargo.toml
# 6) Install the client binary
install -Dm755 client/target/release/navka-client ~/.local/bin/navka-client
# 7) Create and enable a user-level systemd service
mkdir -p ~/.config/systemd/user
cat > ~/.config/systemd/user/navka-client.service <<'EOF'
[Unit]
Description=Navka Client (keyboard/mouse → navka-server)
After=network.target
[Service]
ExecStart=%h/.local/bin/navka-client
Restart=on-failure
[Install]
WantedBy=default.target
EOF
systemctl --user daemon-reload
systemctl --user enable --now navka-client.service
echo "navka-client installed and running."