61 lines
1.8 KiB
Shell
Executable file
61 lines
1.8 KiB
Shell
Executable file
#!/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
|
|
|
|
for command in cargo install readelf; do
|
|
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
|
|
cargo build \
|
|
--release \
|
|
--locked \
|
|
--package lazaret-client \
|
|
--package lazaret-host-coordinator \
|
|
--package lazaret-escalation-client \
|
|
--bins
|
|
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
|
|
|
|
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
|
|
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"
|
|
|
|
printf '%s\n' "Installed Lazaret in $install_dir"
|