70 lines
2.1 KiB
Bash
Executable File
70 lines
2.1 KiB
Bash
Executable File
#!/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)}
|
||
|
||
# 1. packages (Arch)
|
||
sudo pacman -Syq --needed --noconfirm \
|
||
git rustup protobuf gcc evtest base-devel \
|
||
gstreamer gst-plugins-base gst-plugins-good gst-plugins-bad gst-plugins-ugly gst-libav \
|
||
pipewire pipewire-pulse
|
||
|
||
# 1b. yay for AUR bits (run as the invoking user, never root)
|
||
if ! command -v yay >/dev/null 2>&1; then
|
||
sudo -u "$ORIG_USER" bash -c 'cd /tmp && git clone --depth 1 https://aur.archlinux.org/yay.git &&
|
||
cd yay && makepkg -si --noconfirm'
|
||
fi
|
||
sudo -u "$ORIG_USER" yay -S --needed --noconfirm grpcurl-bin
|
||
|
||
# 1c. input access
|
||
sudo usermod -aG input "$ORIG_USER"
|
||
|
||
# 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
|
||
USER_HOME=$(getent passwd "$ORIG_USER" | cut -d: -f6)
|
||
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
|
||
|
||
# 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://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 caller’s session
|
||
sudo systemctl daemon-reload
|
||
sudo systemctl enable --now lesavka-client.service
|
||
sudo systemctl restart lesavka-client || true
|