lesavka/scripts/install-client.sh
2025-06-02 20:18:19 -05:00

49 lines
1.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
set -euo pipefail
ORIG_USER=${SUDO_USER:-$(id -un)}
# 1. packages (Arch)
sudo pacman -Syq --needed --noconfirm git rustup protobuf gcc evtest
# 2. Rust tool-chain for both root & user
sudo rustup default stable
sudo -u "$ORIG_USER" rustup default stable
# 3. clone / update into a user-writable dir
SRC="$HOME/.local/src/navka"
if [[ -d $SRC/.git ]]; then
sudo -u "$ORIG_USER" git -C "$SRC" pull --ff-only
else
sudo -u "$ORIG_USER" git clone "$PWD" "$SRC"
fi
# 4. build
sudo -u "$ORIG_USER" bash -c "cd '$SRC/client' && cargo build --release"
# 5. install binary
install -Dm755 "$SRC/client/target/release/navka-client" "$HOME/.local/bin/navka-client"
# 6) Create the user service file
mkdir -p "$HOME/.config/systemd/user"
cat >"$HOME/.config/systemd/user/navka-client.service" <<'EOF'
[Unit]
Description=Navka Client (keyboard/mouse → navka-server)
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=%h/.local/bin/navka-client
Restart=on-failure
[Install]
WantedBy=default.target
EOF
# 7) (Optional) keep running when no session is active
loginctl enable-linger "$ORIG_USER"
# 8) Call the *user* instance inside the callers session
sudo -iu "$ORIG_USER" systemctl --user daemon-reload
sudo -iu "$ORIG_USER" systemctl --user enable --now navka-client.service