lesavka/scripts/install/client.sh

114 lines
3.4 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
# scripts/install/client.sh - install and setup all client related apps and environments
set -euo pipefail
ORIG_USER=${SUDO_USER:-$(id -un)}
SCRIPT_DIR=$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd)
REPO_ROOT=$(git -C "$SCRIPT_DIR/.." rev-parse --show-toplevel 2>/dev/null || true)
log() {
printf '==> %s\n' "$*"
}
log "1. Installing base packages"
sudo pacman -Syq --needed --noconfirm \
git rustup protobuf gcc clang evtest base-devel \
gstreamer gst-plugins-base gst-plugins-good gst-plugins-bad gst-plugins-ugly gst-libav \
pipewire pipewire-pulse \
wmctrl qt6-tools wl-clipboard xclip xsel
ensure_yay() {
if command -v yay >/dev/null 2>&1; then
if sudo -u "$ORIG_USER" yay --version >/dev/null 2>&1; then
return
fi
fi
sudo -u "$ORIG_USER" bash -c 'rm -rf /tmp/yay &&
cd /tmp && git clone --depth 1 https://aur.archlinux.org/yay.git &&
cd yay && makepkg -si --noconfirm'
}
log "1b. Installing grpcurl"
if sudo pacman -Si grpcurl >/dev/null 2>&1; then
sudo pacman -Syq --needed --noconfirm grpcurl
else
ensure_yay
if ! sudo -u "$ORIG_USER" yay -S --needed --noconfirm grpcurl-bin; then
log "grpcurl AUR install failed once, rebuilding yay and retrying"
ensure_yay
sudo -u "$ORIG_USER" yay -S --needed --noconfirm grpcurl-bin
fi
fi
# 1c. input access
log "1c. Ensuring input group access for $ORIG_USER"
sudo usermod -aG input "$ORIG_USER"
# 2. Rust tool-chain for both root & user
log "2. Ensuring Rust toolchain"
sudo rustup default stable
sudo -u "$ORIG_USER" rustup default stable
# 3. clone / update into a user-writable dir (or use local repo if present)
USER_HOME=$(getent passwd "$ORIG_USER" | cut -d: -f6)
if [[ -n ${REPO_ROOT:-} && -d $REPO_ROOT/.git ]]; then
SRC="$REPO_ROOT"
echo "==> 3. Using local repo at $SRC"
else
SRC="$USER_HOME/.local/src/lesavka"
sudo -u "$ORIG_USER" mkdir -p "$(dirname "$SRC")"
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
fi
# 4. build
log "4. Building client release binary"
sudo -u "$ORIG_USER" bash -c "cd '$SRC/client' && cargo clean && cargo build --release"
# 5. install binary
log "5. Installing /usr/local/bin/lesavka-client"
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://38.28.125.112:50051
ExecStart=/usr/local/bin/lesavka-client
Restart=no
[Install]
WantedBy=default.target
EOF
# 7. Call the *user* instance inside the callers session
log "7. Reloading/starting service"
sudo systemctl daemon-reload
sudo systemctl enable --now lesavka-client.service
sudo systemctl restart lesavka-client || true
echo
echo "✅ lesavka-client install complete"
echo " Binary: /usr/local/bin/lesavka-client"
echo " Build source: $SRC/client/target/release/lesavka-client"
echo " Service: systemctl status lesavka-client --no-pager"
echo
echo "Fish quick start:"
echo " set -gx LESAVKA_SERVER_ADDR http://<server-ip>:50051"
echo " set -gx LESAVKA_VIDEO_MAX_KBIT 4000"
echo " /usr/local/bin/lesavka-client"