backup-enc-recv 1.08 KB
Newer Older
1 2 3 4 5 6
#!/bin/bash

source "$(dirname $0)/backup_config.sh" || exit 1

available_local () {
  # TODO escape
7 8 9 10 11 12
  find $FS_DIR/$BACK_DIR -type d -printf "%P\n" | sed "s/\($PATTERN\)$/\1/; t; d" | sort
}

can_delete () {
  USED=$(find $FS_DIR/$BACK_DIR -lname "*/$1" -name "parent" -printf "%P\n" | sed "s/\/parent//")
  echo "Used by $USED"
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
}

not_implemented () {
  echo "Not implemented"
  exit 1
}

if [ "$1" = "available" ]; then
  available_local
elif [ "$1" = "candidates" ]; then
  echo "Common candidates:"
  available_common
elif [ "$1" = "fullsend" ]; then
  not_implemented
elif [ "$1" = "incsend" ]; then
  not_implemented
elif [ "$1" = "receive" ]; then
  if [ -z "$2" ]; then
    echo "No image name ! Abort";
    exit 1
  fi
  path="$FS_DIR/$BACK_DIR/$2"
  mkdir "$path"
  if [ -n "$3" ]; then
    parent_path="$FS_DIR/$BACK_DIR/$3"
    if [ ! -d "$parent_path" ]; then
        echo "Parent missing ! Abort";
        exit 2
    fi
    ln -s "../$2" "$parent_path/$2"
    ln -s "../$3" "$path/parent"
  fi
  # Actual receive
  cat > $path/gpg
47 48
elif [ "$1" = "can_delete" ]; then
  can_delete $2
49 50
fi