#!/usr/bin/env bash # Build svc-gw natively on the development Orin, check it against the car's # glibc, and install it on an Orin as the yukart-gw service. # # usage: scripts/deploy.sh [host] (default: mikkeli-orin-nano) # env: BUILD_HOST (default: mikkeli-orin-nano-2) # # Builds what is pushed, not the working tree: the build host pulls master of # svc-gw and contracts under ~/dev/yukart/. Native on purpose: the poweroff and reboot # commands run systemctl, and std::process::Command cross-compiled against the workstation's # newer glibc links GLIBC_2.39 symbols (pidfd_spawnp) the car cannot load. set -euo pipefail HOST="${1:-mikkeli-orin-nano}" BUILD_HOST="${BUILD_HOST:-mikkeli-orin-nano-2}" cd "$(dirname "$0")/.." BIN="$(mktemp -d)/svc-gw" ssh "$BUILD_HOST" 'set -e mkdir -p ~/dev/yukart && cd ~/dev/yukart for r in svc-gw contracts; do [ -d $r ] || git clone -q http://192.168.2.199:3005/yukart/$r.git git -C $r pull -q --ff-only done cd svc-gw && ~/.cargo/bin/cargo build --release 2>&1 | tail -1 git log --oneline -1' scp -q "$BUILD_HOST:dev/yukart/svc-gw/target/release/svc-gw" "$BIN" scripts/check-glibc.sh "$BIN" # Binary lives under ~/infra per the host repo's guidelines; /usr/local/bin gets a symlink. ssh "$HOST" 'mkdir -p ~/infra/svc-gw' scp -q "$BIN" "$HOST:infra/svc-gw/svc-gw.new" scp -q deploy/yukart-gw.service "$HOST:infra/svc-gw/yukart-gw.service" scp -q deploy/50-yukart-gw-power.pkla "$HOST:infra/svc-gw/50-yukart-gw-power.pkla" ssh "$HOST" 'set -e mv ~/infra/svc-gw/svc-gw.new ~/infra/svc-gw/svc-gw sudo ln -sfn "$HOME/infra/svc-gw/svc-gw" /usr/local/bin/yukart-gw sudo install -m 0644 ~/infra/svc-gw/yukart-gw.service /etc/systemd/system/yukart-gw.service # polkit, not sudo, lets the service power the host off or reboot it (the poweroff and # reboot commands). The file was named 50-yukart-gw-poweroff.pkla before reboot joined. sudo install -m 0644 ~/infra/svc-gw/50-yukart-gw-power.pkla /etc/polkit-1/localauthority/50-local.d/50-yukart-gw-power.pkla sudo rm -f /etc/polkit-1/localauthority/50-local.d/50-yukart-gw-poweroff.pkla ~/infra/svc-gw/50-yukart-gw-poweroff.pkla sudo systemctl daemon-reload sudo systemctl enable yukart-gw.service >/dev/null sudo systemctl restart yukart-gw.service sleep 1 systemctl --no-pager --lines=5 status yukart-gw.service'