51 lines
1.9 KiB
Shell
51 lines
1.9 KiB
Shell
|
|
#!/usr/bin/env bash
|
||
|
|
# Builds Halkyon Learn's agent on this machine and copies it to its user on
|
||
|
|
# the host it runs on (Halkyon's ADR 0044, D52), which has no Dart SDK:
|
||
|
|
#
|
||
|
|
# apps/learn/halkyon_learn_agent/tool/install.sh <ssh target>
|
||
|
|
#
|
||
|
|
# e.g. `claude@halkyon-li-host`. Each build goes into a folder of its own,
|
||
|
|
# ~/.local/lib/halkyon-agent/<commit>, `current` pointing to it and
|
||
|
|
# ~/.local/bin/halkyon-agent to its executable, so an agent still running
|
||
|
|
# keeps its files; the build before stays, the older ones go.
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
target=${1:?"usage: $0 <ssh target>"}
|
||
|
|
package=$(cd "$(dirname "$0")/.." && pwd)
|
||
|
|
|
||
|
|
# `dart build cli` builds for this machine alone.
|
||
|
|
remote_arch=$(ssh "$target" uname -m)
|
||
|
|
if [[ $remote_arch != "$(uname -m)" ]]; then
|
||
|
|
echo "The host is $remote_arch, this machine $(uname -m): build on one like it." >&2
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
version=$(git -C "$package" rev-parse --short=12 HEAD)
|
||
|
|
if [[ -n $(git -C "$package" status --porcelain -- . ../halkyon_learn_core ../../../packages) ]]; then
|
||
|
|
version="$version-dirty-$(date +%Y%m%d%H%M%S)"
|
||
|
|
fi
|
||
|
|
|
||
|
|
build=$(mktemp -d)
|
||
|
|
trap 'rm -rf "$build"' EXIT
|
||
|
|
(cd "$package" && dart build cli -o "$build")
|
||
|
|
|
||
|
|
# tar rather than rsync, which the host may lack; for its user alone.
|
||
|
|
tar -C "$build/bundle" -cz . | ssh "$target" "
|
||
|
|
set -eu
|
||
|
|
umask 077
|
||
|
|
lib=\$HOME/.local/lib/halkyon-agent
|
||
|
|
mkdir -p \"\$lib/$version\" \"\$HOME/.local/bin\"
|
||
|
|
tar -C \"\$lib/$version\" -xz
|
||
|
|
previous=\$(readlink \"\$lib/current\" || true)
|
||
|
|
ln -sfn '$version' \"\$lib/current\"
|
||
|
|
ln -sfn \"\$lib/current/bin/halkyon_agent\" \"\$HOME/.local/bin/halkyon-agent\"
|
||
|
|
for old in \"\$lib\"/*/; do
|
||
|
|
old=\$(basename \"\$old\")
|
||
|
|
# current/ is a link to a build, never one itself.
|
||
|
|
if [ ! -L \"\$lib/\$old\" ] && [ \"\$old\" != '$version' ] && [ \"\$old\" != \"\$previous\" ]; then
|
||
|
|
rm -rf \"\$lib/\$old\"
|
||
|
|
fi
|
||
|
|
done
|
||
|
|
\"\$HOME/.local/bin/halkyon-agent\" --help > /dev/null
|
||
|
|
"
|
||
|
|
echo "Installed $version on $target: ~/.local/bin/halkyon-agent." >&2
|