lesavka/scripts/install-server.sh

115 lines
3.7 KiB
Bash
Raw Normal View History

2025-06-01 13:31:22 -05:00
#!/usr/bin/env bash
2025-06-15 11:15:52 -05:00
# install-server.sh - install and setup all server related apps and environments
2025-06-01 13:31:22 -05:00
set -euo pipefail
2025-06-01 21:30:55 -05:00
ORIG_USER=${SUDO_USER:-$(id -un)}
2025-06-23 00:26:02 -05:00
echo "==> 1a. Base packages"
2025-06-01 21:30:55 -05:00
sudo pacman -Syq --needed --noconfirm git rustup protobuf gcc pipewire pipewire-pulse tailscale base-devel
if ! command -v yay >/dev/null 2>&1; then
2025-06-23 00:26:02 -05:00
echo "==> 1b. installing yay from AUR ..."
2025-06-01 21:30:55 -05:00
sudo -u "$ORIG_USER" bash -c '
cd /tmp && git clone --depth 1 https://aur.archlinux.org/yay.git &&
cd yay && makepkg -si --noconfirm'
2025-06-01 16:04:00 -05:00
fi
2025-06-01 14:18:42 -05:00
2025-06-23 00:26:02 -05:00
echo "==> 2a. GC311 kerneldriver tweaks"
cat <<'EOF' | sudo tee /etc/modprobe.d/gc311-stream.conf >/dev/null
options uvcvideo quirks=0x200 timeout=10000
EOF
echo "==> 2b. Predictable /dev names for each capture card"
2025-06-24 23:48:06 -05:00
# sudo tee /etc/udev/rules.d/85-gc311.rules >/dev/null <<'RULES'
# # RIGHT eye (video index 0)
# SUBSYSTEM=="video4linux", ATTRS{idVendor}=="07ca", ATTRS{idProduct}=="3311", \
# ATTRS{serial}=="5313550401897", ATTR{index}=="0", \
# SYMLINK+="lesavka_r_eye"
# # LEFT eye (video index 0)
# SUBSYSTEM=="video4linux", ATTRS{idVendor}=="07ca", ATTRS{idProduct}=="3311", \
# ATTRS{serial}=="1200655409098", ATTR{index}=="0", \
# SYMLINK+="lesavka_l_eye"
# RULES
2025-06-23 00:26:02 -05:00
sudo tee /etc/udev/rules.d/85-gc311.rules >/dev/null <<'RULES'
2025-06-24 23:48:06 -05:00
# LEFT eye GC311 on hubport 13
2025-06-23 00:26:02 -05:00
SUBSYSTEM=="video4linux", ATTRS{idVendor}=="07ca", ATTRS{idProduct}=="3311", \
2025-06-24 23:48:06 -05:00
ATTRS{index}=="0", ENV{ID_PATH_TAG}=="usb-platform-1a400000.xhci-usb-0_1_3_1_0", \
SYMLINK+="lesavka_l_eye"
2025-06-23 00:26:02 -05:00
2025-06-24 23:48:06 -05:00
# RIGHT eye GC311 on hubport 14
2025-06-23 00:26:02 -05:00
SUBSYSTEM=="video4linux", ATTRS{idVendor}=="07ca", ATTRS{idProduct}=="3311", \
2025-06-24 23:48:06 -05:00
ATTRS{index}=="0", ENV{ID_PATH_TAG}=="usb-platform-1a400000.xhci-usb-0_1_4_1_0", \
SYMLINK+="lesavka_r_eye"
2025-06-23 00:26:02 -05:00
RULES
sudo udevadm control --reload
sudo udevadm trigger --subsystem-match=video4linux
udevadm settle
echo "==> 3. Rust toolchain"
2025-06-01 21:30:55 -05:00
sudo rustup default stable
sudo -u "$ORIG_USER" rustup default stable
2025-06-01 13:31:22 -05:00
2025-06-23 00:26:02 -05:00
echo "==> 4a. Source checkout"
SRC_DIR=/var/src/lesavka
REPO_URL=ssh://git@scm.bstein.dev:2242/brad_stein/lesavka.git
2025-06-01 21:30:55 -05:00
if [[ ! -d $SRC_DIR ]]; then
sudo mkdir -p /var/src
sudo chown "$ORIG_USER":"$ORIG_USER" /var/src
2025-06-01 14:18:42 -05:00
fi
2025-06-01 21:30:55 -05:00
if [[ -d $SRC_DIR/.git ]]; then
sudo -u "$ORIG_USER" git -C "$SRC_DIR" pull --ff-only
2025-06-01 14:18:42 -05:00
else
2025-06-01 22:12:09 -05:00
sudo -u "$ORIG_USER" git clone "$REPO_URL" "$SRC_DIR"
2025-06-01 14:18:42 -05:00
fi
2025-06-01 13:31:22 -05:00
2025-06-23 00:26:02 -05:00
echo "==> 4b. Source build"
2025-06-16 21:47:01 -05:00
sudo -u "$ORIG_USER" bash -c "cd '$SRC_DIR/server' && cargo clean && cargo build --release"
2025-06-01 13:31:22 -05:00
2025-06-23 00:26:02 -05:00
echo "==> 5. Install binaries"
2025-06-23 21:56:11 -05:00
sudo install -Dm755 "$SRC_DIR/server/target/release/lesavka-server" /usr/local/bin/lesavka-server
2025-06-23 00:26:02 -05:00
sudo install -Dm755 "$SRC_DIR/scripts/lesavka-core.sh" /usr/local/bin/lesavka-core.sh
2025-06-01 14:18:42 -05:00
2025-06-23 00:26:02 -05:00
echo "==> 6a. Systemd units - lesavka-core"
cat <<'UNIT' | sudo tee /etc/systemd/system/lesavka-core.service >/dev/null
2025-06-01 13:31:22 -05:00
[Unit]
2025-06-23 00:26:02 -05:00
Description=lesavka USB gadget bring-up
2025-06-06 00:04:55 -05:00
After=sys-kernel-config.mount
Requires=sys-kernel-config.mount
2025-06-23 00:26:02 -05:00
2025-06-01 13:31:22 -05:00
[Service]
2025-06-01 14:18:42 -05:00
Type=oneshot
2025-06-23 00:26:02 -05:00
ExecStart=/usr/local/bin/lesavka-core.sh
2025-06-01 14:18:42 -05:00
RemainAfterExit=yes
2025-06-06 00:04:55 -05:00
CapabilityBoundingSet=CAP_SYS_ADMIN
2025-06-06 00:41:32 -05:00
MountFlags=slave
2025-06-23 00:26:02 -05:00
2025-06-01 13:31:22 -05:00
[Install]
WantedBy=multi-user.target
2025-06-01 21:30:55 -05:00
UNIT
2025-06-01 13:31:22 -05:00
2025-06-23 00:26:02 -05:00
echo "==> 6b. Systemd units - lesavka-server"
cat <<'UNIT' | sudo tee /etc/systemd/system/lesavka-server.service >/dev/null
2025-06-01 13:31:22 -05:00
[Unit]
2025-06-23 00:26:02 -05:00
Description=lesavka gRPC relay
After=network.target lesavka-core.service
2025-06-01 13:31:22 -05:00
[Service]
2025-06-23 00:26:02 -05:00
ExecStart=/usr/local/bin/lesavka-server
2025-06-01 14:18:42 -05:00
Restart=always
2025-06-23 00:26:02 -05:00
Environment="RUST_LOG=lesavka_server=trace"
2025-06-01 14:18:42 -05:00
User=root
2025-06-23 00:26:02 -05:00
2025-06-01 13:31:22 -05:00
[Install]
WantedBy=multi-user.target
2025-06-01 21:30:55 -05:00
UNIT
2025-06-01 13:31:22 -05:00
2025-06-23 00:26:02 -05:00
echo "==> 6c. Systemd units - initialization"
2025-06-01 13:31:22 -05:00
sudo systemctl daemon-reload
2025-06-23 00:26:02 -05:00
sudo systemctl enable --now lesavka-core
sudo systemctl restart lesavka-core
echo "✅ lesavka-core installed and restarted..."
2025-06-06 20:45:09 -05:00
2025-06-23 00:26:02 -05:00
sudo systemctl enable --now lesavka-server
sudo systemctl restart lesavka-server
echo "✅ lesavka-server installed and restarted..."