added linger

This commit is contained in:
Brad Stein 2025-06-01 21:58:47 -05:00
parent 18b0d23e47
commit f5b2a4b813

View File

@ -1,45 +1,39 @@
#!/usr/bin/env bash
set -euo pipefail
# 1) Install system dependencies (Arch Linux)
sudo pacman -S --needed --noconfirm git rustup protobuf gcc evtest
USER=${SUDO_USER:-$(id -un)}
# 2) Ensure Rust toolchain is present
rustup toolchain install stable
# 1. packages (Arch)
sudo pacman -Syq --needed --noconfirm git rustup protobuf gcc evtest
# 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
# 2. Rust tool-chain for both root & user
sudo rustup default stable
sudo -u "$USER" rustup default stable
# 4) Where to clone/build if not already present
WORK="$HOME/.local/src/navka"
if [ ! -d "$WORK" ]; then
git clone "$REPO_URL" "$WORK"
# 3. clone / update into a user-writable dir
SRC="$HOME/.local/src/navka"
if [[ -d $SRC/.git ]]; then
sudo -u "$USER" git -C "$SRC" pull --ff-only
else
pushd "$WORK" >/dev/null
git fetch --all
git reset --hard origin/$(git -C "$WORK" rev-parse --abbrev-ref HEAD)
popd >/dev/null
sudo -u "$USER" git clone "$PWD" "$SRC"
fi
# 5) Build the client
cd "$WORK"
cargo build --release --manifest-path client/Cargo.toml
# 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) Install the client binary
install -Dm755 client/target/release/navka-client ~/.local/bin/navka-client
install -Dm755 client/target/release/navka-client "$HOME/.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'
# 7) 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.target
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=%h/.local/bin/navka-client
@ -49,7 +43,9 @@ Restart=on-failure
WantedBy=default.target
EOF
systemctl --user daemon-reload
systemctl --user enable --now navka-client.service
# 8) (Optional) keep running when no session is active
loginctl enable-linger "$USER"
echo "navka-client installed and running."
# 9) Enable + start as *you*, not root
sudo -u "$USER" systemctl --user daemon-reload
sudo -u "$USER" systemctl --user enable --now navka-client.service