lesavka/scripts/install-server.sh

65 lines
2.0 KiB
Bash
Raw Normal View History

2025-06-01 13:31:22 -05:00
#!/usr/bin/env bash
set -euo pipefail
2025-06-01 21:30:55 -05:00
ORIG_USER=${SUDO_USER:-$(id -un)}
# 1. base packages (Arch + yay if missing)
sudo pacman -Syq --needed --noconfirm git rustup protobuf gcc pipewire pipewire-pulse tailscale base-devel
if ! command -v yay >/dev/null 2>&1; then
echo "→ installing yay from AUR ..."
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-01 21:30:55 -05:00
# 2. Rust tool-chain for both accounts
sudo rustup default stable
sudo -u "$ORIG_USER" rustup default stable
2025-06-01 13:31:22 -05:00
2025-06-01 21:30:55 -05:00
# 3. writable build tree under /var/src (create once, chown to user)
SRC_DIR=/var/src/navka
2025-06-01 22:12:09 -05:00
REPO_URL=ssh://git@scm.bstein.dev:2242/brad_stein/navka.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-01 21:30:55 -05:00
# 4. build (as the normal user avoids root-owned Cargo.lock)
sudo -u "$ORIG_USER" bash -c "cd '$SRC_DIR/server' && cargo build --release"
2025-06-01 13:31:22 -05:00
2025-06-01 21:30:55 -05:00
# 5. install payload
sudo install -Dm755 "$SRC_DIR/server/target/release/navka-server" /usr/local/bin/navka-server
2025-06-01 22:12:09 -05:00
sudo install -Dm755 "$SRC_DIR/scripts/navka-core.sh" /usr/local/bin/navka-core.sh
2025-06-01 14:18:42 -05:00
2025-06-01 21:30:55 -05:00
# 6. systemd units
cat <<'UNIT' | sudo tee /etc/systemd/system/navka-core.service >/dev/null
2025-06-01 13:31:22 -05:00
[Unit]
2025-06-01 21:30:55 -05:00
Description=Navka USB gadget bring-up
2025-06-01 13:31:22 -05:00
[Service]
2025-06-01 14:18:42 -05:00
Type=oneshot
2025-06-01 21:30:55 -05:00
ExecStart=/usr/local/bin/navka-core.sh
2025-06-01 14:18:42 -05:00
RemainAfterExit=yes
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-01 21:30:55 -05:00
cat <<'UNIT' | sudo tee /etc/systemd/system/navka-server.service >/dev/null
2025-06-01 13:31:22 -05:00
[Unit]
2025-06-01 21:30:55 -05:00
Description=Navka gRPC relay
After=network.target navka-core.service
2025-06-01 13:31:22 -05:00
[Service]
2025-06-01 14:18:42 -05:00
ExecStart=/usr/local/bin/navka-server
Restart=always
User=root
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
sudo systemctl daemon-reload
2025-06-01 21:30:55 -05:00
sudo systemctl enable --now navka-core.service navka-server.service
echo "✅ navka-server installed and running."