liminix

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

min-copy-closure.sh (1455B)


      1 #!/usr/bin/env bash
      2 
      3 ssh_command=${SSH_COMMAND-ssh}
      4 
      5 root_prefix=/
      6 verbose=true
      7 
      8 while [[ $# -gt 0 ]]; do
      9     case $1 in
     10 	-r|--root)
     11 	    root_prefix="$2"
     12 	    shift
     13 	    shift
     14 	    ;;
     15 	-q|--quiet)
     16 	    verbose=""
     17 	    shift
     18 	    ;;
     19 	-*|--*)
     20 	    echo "Unknown option $1"
     21 	    exit 1
     22 	    ;;
     23 	*)
     24 	    if test -z "$target_host"; then
     25 		target_host="$1"
     26 	    else
     27 		paths+=("$1") # save positional arg
     28 	    fi
     29 	    shift # past argument
     30 	    ;;
     31     esac
     32 done
     33 
     34 progress() {
     35     test -n "$verbose" && echo $*
     36 }
     37 
     38 if [ -z "$target_host" ] ; then
     39     echo Usage: min-copy-closure [--root /mnt] target-host paths
     40     exit 1
     41 fi
     42 
     43 if [ -z "$IN_NIX_BUILD" ] ; then
     44     # can't run nix-store in a derivation, so we have to
     45     # skip the requisites when running tests in hydra
     46     paths=$(nix-store -q --requisites "$paths")
     47 fi
     48 needed=""
     49 
     50 coproc remote {
     51     ${ssh_command} -C -T ${target_host}
     52 }
     53 
     54 exec 10>&${remote[1]}
     55 
     56 for p in $paths; do
     57     progress  -n Checking $(basename $p) ...
     58     echo "test -e ${root_prefix}$p && echo skip || echo $p"  >&10
     59     read n <&${remote[0]}
     60     case $n in
     61 	skip)
     62 	    progress skip
     63 	    ;;
     64 	*)
     65 	    needed="${needed} $n"
     66 	    progress will copy
     67 	    ;;
     68     esac
     69 done
     70 
     71 if test -z "$needed" ; then
     72     echo Nothing to copy
     73     exit 1
     74 fi
     75 
     76 echo "cd ${root_prefix} && cpio -d -i >/dev/console"  >&10
     77 
     78 find $needed | cpio  -H newc -o  >&10
     79 
     80 # make sure the connection hasn't died
     81 echo "echo finished"  >&10
     82 read n <&${remote[0]}
     83 echo $n