liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

min-copy-closure.sh (929B)


      1 #!/usr/bin/env bash
      2 
      3 ssh_command=${SSH_COMMAND-ssh}
      4 target_host=$1
      5 shift
      6 
      7 if [ -z "$target_host" ] ; then
      8     echo Usage: min-copy-closure target-host paths
      9     exit 1
     10 fi
     11 
     12 if [ -n "$IN_NIX_BUILD" ] ; then
     13     # can't run nix-store in a derivation, so we have to
     14     # skip the requisites when running tests in hydra
     15     paths=$@
     16 else
     17     paths=$(nix-store -q --requisites "$@")
     18 fi
     19 needed=""
     20 
     21 coproc remote {
     22     ${ssh_command} -C -T ${target_host}
     23 }
     24 
     25 exec 10>&${remote[1]}
     26 
     27 for p in $paths; do
     28     echo -n Checking $(basename $p) ...
     29     echo "test -e $p && echo skip || echo $p"  >&10
     30     read n <&${remote[0]}
     31     case $n in
     32 	skip)
     33 	    echo skip
     34 	    ;;
     35 	*)
     36 	    needed="${needed} $n"
     37 	    echo will copy
     38 	    ;;
     39     esac
     40 done
     41 
     42 if test -z "$needed" ; then
     43     echo Nothing to copy
     44     exit 1
     45 fi
     46 
     47 echo "cd / && cpio -i >/dev/console"  >&10
     48 
     49 find $needed | cpio -H newc -o  >&10
     50 
     51 echo "date"  >&10
     52 read n <&${remote[0]}
     53 echo $n