chriswarbo-net: d5ae1b133d344a2ec29eeb8620921e6cf958157b

     1: #!/usr/bin/env bash
     2: set -e
     3: 
     4: # Send the blocks of an IPFS path to a remote system via SSH
     5: 
     6: OBJECT="$1"
     7: REMOTE="$2"
     8: 
     9: function objectRefs() {
    10:     RESOLVED=$(ipfs resolve "$OBJECT")
    11:     while [[ "x$RESOLVED" != "x$(ipfs resolve "$RESOLVED")" ]]
    12:     do
    13:         RESOLVED=$(ipfs resolve "$RESOLVED")
    14:     done
    15: 
    16:     # In case there's a /ipfs/... we only keep what's after the last / (if any)
    17:     echo "$RESOLVED" | grep -o '[^/][^/]*$'
    18: 
    19:     ipfs refs -r "$OBJECT"
    20: }
    21: 
    22: echo "Diffing required/existing references" 1>&2
    23: BLOCKS=$(diff --new-line-format="" --unchanged-line-format="" \
    24:               <(objectRefs | grep '^.' | sort -u) \
    25:               <(ssh "$REMOTE" ipfs refs local | grep '^.' | sort -u)) || true
    26: 
    27: TOTAL=$(echo "$BLOCKS" | wc -l)
    28: 
    29: function dumpBlocks() {
    30:     while read -r REF
    31:     do
    32:         [[ -n "$REF" ]] || continue
    33:         ipfs block get "$REF" | base64 -w 0
    34:         echo ""
    35:     done < <(echo "$BLOCKS")
    36: }
    37: 
    38: dumpBlocks | ssh -C "$REMOTE" \
    39:   "TOTAL=$TOTAL"'
    40:    while read -r L
    41:    do
    42:      echo "$TOTAL" 1>&2
    43:      TOTAL=$(( TOTAL - 1 ))
    44: 
    45:      [[ -n "$L" ]] || continue
    46:      echo "$L" | base64 -d | ipfs block put > /dev/null
    47:    done'

Generated by git2html.