lesavka: honor checkout remote in installers

This commit is contained in:
Brad Stein 2026-04-16 14:29:16 -03:00
parent 16ce4cabec
commit cf8fadd368
2 changed files with 50 additions and 23 deletions

View File

@ -4,9 +4,13 @@ set -euo pipefail
ORIG_USER=${SUDO_USER:-$(id -un)}
REF=${LESAVKA_REF:-master}
REPO_URL=${LESAVKA_REPO_URL:-ssh://git@scm.bstein.dev:2242/bstein/lesavka.git}
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
SCRIPT_REPO_ROOT=$(cd -- "$SCRIPT_DIR/../.." && pwd)
DEFAULT_REPO_URL=ssh://git@scm.bstein.dev:2242/bstein/lesavka.git
REPO_URL=${LESAVKA_REPO_URL:-}
SRC=/var/src/lesavka
export TMPDIR=${TMPDIR:-/var/tmp}
USER_HOME=$(getent passwd "$ORIG_USER" | cut -d: -f6)
log() {
printf '==> %s\n' "$*"
@ -22,24 +26,33 @@ require_command() {
exit 1
}
run_as_user() {
sudo -u "$ORIG_USER" env HOME="$USER_HOME" SSH_AUTH_SOCK="${SSH_AUTH_SOCK:-}" "$@"
}
mkdir -p "$TMPDIR"
if [[ -z $REPO_URL ]] && [[ -d $SCRIPT_REPO_ROOT/.git ]]; then
REPO_URL=$(git -C "$SCRIPT_REPO_ROOT" config --get remote.origin.url || true)
fi
REPO_URL=${REPO_URL:-$DEFAULT_REPO_URL}
log "1. Installing base packages"
# Intentionally leave the host audio stack alone. Workstations often carry
# tightly versioned PipeWire packages, and Lesavka should not force an audio
# stack upgrade just to install the client.
sudo pacman -Sq --needed --noconfirm \
git rustup protobuf gcc clang evtest base-devel libpulse \
git rustup protobuf abseil-cpp gcc clang evtest base-devel libpulse \
gstreamer gst-plugins-base gst-plugins-good gst-plugins-bad gst-plugins-ugly gst-libav \
wmctrl qt6-tools wl-clipboard xclip xsel desktop-file-utils
ensure_yay() {
if command -v yay >/dev/null 2>&1; then
if sudo -u "$ORIG_USER" yay --version >/dev/null 2>&1; then
if run_as_user yay --version >/dev/null 2>&1; then
return
fi
fi
sudo -u "$ORIG_USER" env TMPDIR="$TMPDIR" bash -c 'rm -rf "$TMPDIR/yay" &&
run_as_user env TMPDIR="$TMPDIR" bash -c 'rm -rf "$TMPDIR/yay" &&
cd "$TMPDIR" && git clone --depth 1 https://aur.archlinux.org/yay.git &&
cd yay && makepkg -si --noconfirm'
}
@ -49,10 +62,10 @@ if sudo pacman -Si grpcurl >/dev/null 2>&1; then
sudo pacman -Sq --needed --noconfirm grpcurl
else
ensure_yay
if ! sudo -u "$ORIG_USER" yay -S --needed --noconfirm grpcurl-bin; then
if ! run_as_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
run_as_user yay -S --needed --noconfirm grpcurl-bin
fi
fi
@ -70,7 +83,7 @@ if ! command -v wl-paste >/dev/null 2>&1 \
echo "❌ no clipboard reader found after install (expected one of wl-clipboard/xclip/xsel)" >&2
exit 1
fi
if ! sudo -u "$ORIG_USER" pactl info >/dev/null 2>&1; then
if ! run_as_user pactl info >/dev/null 2>&1; then
echo "⚠️ pactl is installed, but no PulseAudio/PipeWire Pulse server is reachable right now."
echo " Lesavka will still install, but local speaker/mic staging may stay empty until the host audio session is up."
fi
@ -78,7 +91,7 @@ fi
# 2. Rust tool-chain for both root & user
log "2. Ensuring Rust toolchain"
sudo rustup default stable
sudo -u "$ORIG_USER" rustup default stable
run_as_user rustup default stable
# 3. clone / update into a canonical workspace checkout
log "3. Syncing source checkout for ref ${REF}"
@ -87,19 +100,19 @@ if [[ ! -d /var/src ]]; then
fi
sudo chown "$ORIG_USER":"$ORIG_USER" /var/src
if [[ -d $SRC/.git ]]; then
sudo -u "$ORIG_USER" git -C "$SRC" fetch --all --tags --prune
run_as_user git -C "$SRC" fetch --all --tags --prune
else
sudo -u "$ORIG_USER" git clone "$REPO_URL" "$SRC"
run_as_user git clone "$REPO_URL" "$SRC"
fi
if sudo -u "$ORIG_USER" git -C "$SRC" rev-parse --verify --quiet "origin/$REF" >/dev/null; then
sudo -u "$ORIG_USER" git -C "$SRC" checkout -B "$REF" "origin/$REF"
if run_as_user git -C "$SRC" rev-parse --verify --quiet "origin/$REF" >/dev/null; then
run_as_user git -C "$SRC" checkout -B "$REF" "origin/$REF"
else
sudo -u "$ORIG_USER" git -C "$SRC" checkout --force "$REF"
run_as_user git -C "$SRC" checkout --force "$REF"
fi
# 4. build
log "4. Building client release binary"
sudo -u "$ORIG_USER" env TMPDIR="$TMPDIR" bash -c "cd '$SRC/client' && cargo clean && cargo build --release"
run_as_user env TMPDIR="$TMPDIR" bash -c "cd '$SRC/client' && cargo clean && cargo build --release"
# 5. install binary
log "5. Installing launchable client binaries"

View File

@ -2,9 +2,14 @@
# scripts/install/server.sh - install and setup all server related apps and environments
set -euo pipefail
ORIG_USER=${SUDO_USER:-$(id -un)}
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
SCRIPT_REPO_ROOT=$(cd -- "$SCRIPT_DIR/../.." && pwd)
DEFAULT_REPO_URL=ssh://git@scm.bstein.dev:2242/bstein/lesavka.git
export TMPDIR=${TMPDIR:-/var/tmp}
REF=${LESAVKA_REF:-master} # fallback
REPO_URL=${LESAVKA_REPO_URL:-}
USER_HOME=$(getent passwd "$ORIG_USER" | cut -d: -f6)
udc_state() {
local udc=""
@ -25,6 +30,10 @@ is_attached_state() {
return 1
}
run_as_user() {
sudo -u "$ORIG_USER" env HOME="$USER_HOME" SSH_AUTH_SOCK="${SSH_AUTH_SOCK:-}" "$@"
}
while [[ $# -gt 0 ]]; do
case $1 in
-r|--ref) REF="$2"; shift 2 ;;
@ -36,10 +45,16 @@ done
echo "==> Using git ref: $REF"
mkdir -p "$TMPDIR"
if [[ -z $REPO_URL ]] && [[ -d $SCRIPT_REPO_ROOT/.git ]]; then
REPO_URL=$(git -C "$SCRIPT_REPO_ROOT" config --get remote.origin.url || true)
fi
REPO_URL=${REPO_URL:-$DEFAULT_REPO_URL}
echo "==> 1a. Base packages"
sudo pacman -Sq --needed --noconfirm git \
rustup \
protobuf \
abseil-cpp \
gcc \
alsa-utils \
pipewire \
@ -59,7 +74,7 @@ sudo pacman -Sq --needed --noconfirm git \
lsof
if ! command -v yay >/dev/null 2>&1; then
echo "==> 1b. installing yay from AUR ..."
sudo -u "$ORIG_USER" env TMPDIR="$TMPDIR" bash -c '
run_as_user env TMPDIR="$TMPDIR" bash -c '
rm -rf "$TMPDIR/yay" &&
cd "$TMPDIR" && git clone --depth 1 https://aur.archlinux.org/yay.git &&
cd yay && makepkg -si --noconfirm'
@ -131,25 +146,24 @@ sudo udevadm settle
echo "==> 3. Rust toolchain"
sudo rustup default stable
sudo -u "$ORIG_USER" rustup default stable
run_as_user rustup default stable
echo "==> 4a. Source checkout"
SRC_DIR=/var/src/lesavka
REPO_URL=ssh://git@scm.bstein.dev:2242/bstein/lesavka.git
if [[ ! -d $SRC_DIR ]]; then
sudo mkdir -p /var/src
sudo chown "$ORIG_USER":"$ORIG_USER" /var/src
fi
if [[ -d $SRC_DIR/.git ]]; then
sudo -u "$ORIG_USER" git -C "$SRC_DIR" fetch --all --tags --prune
run_as_user git -C "$SRC_DIR" fetch --all --tags --prune
else
sudo -u "$ORIG_USER" git clone "$REPO_URL" "$SRC_DIR"
run_as_user git clone "$REPO_URL" "$SRC_DIR"
fi
if sudo -u "$ORIG_USER" git -C "$SRC_DIR" rev-parse --verify --quiet "origin/$REF" >/dev/null; then
sudo -u "$ORIG_USER" git -C "$SRC_DIR" checkout -B "$REF" "origin/$REF"
if run_as_user git -C "$SRC_DIR" rev-parse --verify --quiet "origin/$REF" >/dev/null; then
run_as_user git -C "$SRC_DIR" checkout -B "$REF" "origin/$REF"
else
sudo -u "$ORIG_USER" git -C "$SRC_DIR" checkout --force "$REF"
run_as_user git -C "$SRC_DIR" checkout --force "$REF"
fi
echo "==> 4b. Kernel upgrade (optional)"
@ -160,7 +174,7 @@ else
fi
echo "==> 4c. Source build"
sudo -u "$ORIG_USER" env TMPDIR="$TMPDIR" bash -c "cd '$SRC_DIR/server' && cargo clean && cargo build --release --bins"
run_as_user env TMPDIR="$TMPDIR" bash -c "cd '$SRC_DIR/server' && cargo clean && cargo build --release --bins"
echo "==> 5. Install binaries"
sudo install -Dm755 "$SRC_DIR/target/release/lesavka-server" /usr/local/bin/lesavka-server