2026-07-19 13:55:52 +09:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
|
|
root="$(cd "$(dirname "$0")/.." && pwd)"
|
|
|
|
|
install_dir="${LAZARET_INSTALL_DIR:-$HOME/.local/bin}"
|
|
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
|
printf '%s\n' "usage: tools/install-to-host [--install-dir DIRECTORY]"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if [ "${1:-}" = "--help" ] && [ "$#" -eq 1 ]; then
|
|
|
|
|
usage
|
|
|
|
|
exit 0
|
|
|
|
|
elif [ "${1:-}" = "--install-dir" ] && [ "$#" -eq 2 ]; then
|
|
|
|
|
install_dir="$2"
|
|
|
|
|
elif [ "$#" -ne 0 ]; then
|
|
|
|
|
usage >&2
|
|
|
|
|
exit 2
|
|
|
|
|
fi
|
|
|
|
|
|
2026-07-26 18:01:03 +09:00
|
|
|
for command in cargo cmp install readelf; do
|
2026-07-19 13:55:52 +09:00
|
|
|
command -v "$command" >/dev/null 2>&1 || {
|
|
|
|
|
printf '%s\n' "install-to-host: $command is required" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
}
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
cd "$root"
|
|
|
|
|
tools/materialize-fuser
|
2026-07-26 18:01:03 +09:00
|
|
|
tools/materialize-runsc --build
|
2026-07-19 13:55:52 +09:00
|
|
|
cargo build \
|
|
|
|
|
--release \
|
|
|
|
|
--locked \
|
|
|
|
|
--package lazaret-client \
|
|
|
|
|
--package lazaret-host-coordinator \
|
|
|
|
|
--package lazaret-escalation-client \
|
|
|
|
|
--bins
|
2026-07-19 22:38:37 +09:00
|
|
|
env RUSTFLAGS="-C relocation-model=static -C link-arg=-no-pie" cargo build \
|
|
|
|
|
--release \
|
|
|
|
|
--locked \
|
|
|
|
|
--target x86_64-unknown-linux-musl \
|
|
|
|
|
--package lazaret-sandbox-init \
|
|
|
|
|
--bin lazaret-sandbox-init
|
2026-07-19 13:55:52 +09:00
|
|
|
|
|
|
|
|
target_dir="${CARGO_TARGET_DIR:-target}"
|
|
|
|
|
if [[ "$target_dir" != /* ]]; then
|
|
|
|
|
target_dir="$root/$target_dir"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
install -d -m 755 "$install_dir"
|
|
|
|
|
for executable in lazaret lazaret-host-coordinator lazaret-escalation-client; do
|
|
|
|
|
install -m 755 "$target_dir/release/$executable" "$install_dir/$executable"
|
|
|
|
|
done
|
2026-07-19 22:38:37 +09:00
|
|
|
sandbox_init="$target_dir/x86_64-unknown-linux-musl/release/lazaret-sandbox-init"
|
|
|
|
|
if readelf -l "$sandbox_init" | grep -q 'Requesting program interpreter' ||
|
|
|
|
|
! readelf -d "$sandbox_init" 2>&1 | grep -q 'There is no dynamic section'; then
|
|
|
|
|
printf '%s\n' "install-to-host: sandbox init is dynamically linked" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
install -m 755 "$sandbox_init" "$install_dir/lazaret-sandbox-init"
|
2026-07-19 13:55:52 +09:00
|
|
|
|
2026-07-29 22:20:04 +09:00
|
|
|
runsc_build_id=5b441d02d40792cfe228b294fb688a80cf6161fb6876d49ef03138618ae2562e
|
2026-07-26 18:01:03 +09:00
|
|
|
runsc_name="lazaret-runsc-$runsc_build_id"
|
|
|
|
|
runsc_source="$root/.lazaret/bin/$runsc_name"
|
|
|
|
|
runsc_destination="$install_dir/$runsc_name"
|
|
|
|
|
if [[ -e "$runsc_destination" ]]; then
|
|
|
|
|
cmp --silent "$runsc_source" "$runsc_destination" || {
|
|
|
|
|
printf '%s\n' "install-to-host: immutable runsc destination differs: $runsc_destination" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
install -m 755 "$runsc_source" "$runsc_destination"
|
|
|
|
|
fi
|
|
|
|
|
|
2026-07-19 13:55:52 +09:00
|
|
|
printf '%s\n' "Installed Lazaret in $install_dir"
|