2023-05-06 23:47:03 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2023-05-07 23:07:35 +02:00
|
|
|
ssh_command=${SSH_COMMAND-ssh}
|
2023-12-24 00:12:40 +01:00
|
|
|
|
|
|
|
root_prefix=/
|
|
|
|
verbose=true
|
|
|
|
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
case $1 in
|
|
|
|
-r|--root)
|
|
|
|
root_prefix="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-q|--quiet)
|
|
|
|
verbose=""
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-*|--*)
|
|
|
|
echo "Unknown option $1"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if test -z "$target_host"; then
|
|
|
|
target_host="$1"
|
|
|
|
else
|
|
|
|
paths+=("$1") # save positional arg
|
|
|
|
fi
|
|
|
|
shift # past argument
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
progress() {
|
|
|
|
test -n "$verbose" && echo $*
|
|
|
|
}
|
2023-05-06 23:47:03 +02:00
|
|
|
|
2023-05-07 23:07:35 +02:00
|
|
|
if [ -z "$target_host" ] ; then
|
2023-12-24 00:12:40 +01:00
|
|
|
echo Usage: min-copy-closure [--root /mnt] target-host paths
|
2023-05-07 23:07:35 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-12-24 00:12:40 +01:00
|
|
|
if [ -z "$IN_NIX_BUILD" ] ; then
|
2023-05-07 23:07:35 +02:00
|
|
|
# can't run nix-store in a derivation, so we have to
|
|
|
|
# skip the requisites when running tests in hydra
|
2023-12-24 00:12:40 +01:00
|
|
|
paths=$(nix-store -q --requisites "$paths")
|
2023-05-07 23:07:35 +02:00
|
|
|
fi
|
2023-05-06 23:47:03 +02:00
|
|
|
needed=""
|
|
|
|
|
|
|
|
coproc remote {
|
2023-05-07 23:07:35 +02:00
|
|
|
${ssh_command} -C -T ${target_host}
|
2023-05-06 23:47:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exec 10>&${remote[1]}
|
|
|
|
|
|
|
|
for p in $paths; do
|
2023-12-24 00:12:40 +01:00
|
|
|
progress -n Checking $(basename $p) ...
|
|
|
|
echo "test -e ${root_prefix}$p && echo skip || echo $p" >&10
|
2023-05-06 23:47:03 +02:00
|
|
|
read n <&${remote[0]}
|
|
|
|
case $n in
|
|
|
|
skip)
|
2023-12-24 00:12:40 +01:00
|
|
|
progress skip
|
2023-05-06 23:47:03 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
needed="${needed} $n"
|
2023-12-24 00:12:40 +01:00
|
|
|
progress will copy
|
2023-05-06 23:47:03 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if test -z "$needed" ; then
|
|
|
|
echo Nothing to copy
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-12-24 00:12:40 +01:00
|
|
|
echo "cd ${root_prefix} && cpio -d -i >/dev/console" >&10
|
2023-05-06 23:47:03 +02:00
|
|
|
|
2023-12-24 00:12:40 +01:00
|
|
|
find $needed | cpio -H newc -o >&10
|
2023-05-06 23:47:03 +02:00
|
|
|
|
2023-12-24 00:12:40 +01:00
|
|
|
# make sure the connection hasn't died
|
|
|
|
echo "echo finished" >&10
|
2023-05-06 23:47:03 +02:00
|
|
|
read n <&${remote[0]}
|
|
|
|
echo $n
|