lesavka/scripts/install-client.sh
2025-06-27 14:01:29 -05:00

55 lines
1.5 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
# install-client.sh - install and setup all client related apps and environments
set -euo pipefail
ORIG_USER=${SUDO_USER:-$(id -un)}
# 1. packages (Arch)
sudo pacman -Syq --needed --noconfirm git rustup protobuf gcc evtest gstreamer gst-plugins-base gst-plugins-good gst-plugins-bad gst-plugins-ugly gst-libav
# 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/lesavka"
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 clean && cargo build --release"
# 5. install binary
sudo install -Dm755 "$SRC/client/target/release/lesavka-client" /usr/local/bin/lesavka-client
# 6. systemd service for system scope: /etc/systemd/system/lesavka-client.service
sudo tee /etc/systemd/system/lesavka-client.service >/dev/null <<'EOF'
[Unit]
Description=Lesavka Client
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=root
Group=root
Environment=RUST_LOG=debug
Environment=LESAVKA_DEV_MODE=1
Environment=LESAVKA_SERVER_ADDR=http://64.25.10.31:50051
ExecStart=/usr/local/bin/lesavka-client
Restart=no
[Install]
WantedBy=default.target
EOF
# 7. Call the *user* instance inside the callers session
sudo systemctl daemon-reload
sudo systemctl enable --now lesavka-client.service
sudo systemctl restart lesavka-client || true