#! /bin/bash -ex

# 1. reset: rm -rf tests/data/source
# 2. run generate_data.sh a
# 3. create Arq backup plan with password "test"
# 4. make an Arq backup
# 5. run generate_data.sh b
# 6. make another Arq backup
# 7. run generate_data.sh c
# 8. change encryption password to "test2"
# 9. make another Arq backup

state_a() {
  echo "==== State A"

  echo "root" > root.txt
  mkdir -p a/a1/
  echo "a" > a/a.txt
  echo "a1" > a/a1/a1.txt
  
  mkdir -p b/b1/
  echo "b" > b/b.txt
  echo "o+rwxg+x-rw" > b/b1/permissions.txt
  chmod o+rwxg+x-rw b/b1/permissions.txt

  mkdir -p c/
  dd if=/dev/zero of=c/compressible.bin bs=1024 count=1024
}

state_b() {
  echo "==== State B"

  echo "new" > b/new.txt
  echo "updated" > a/a.txt
  rm -f b/b.txt

  dd if=/dev/random of=c/random-m.bin bs=1024 count=251
}

state_c() {
  echo "==== State C"

  echo "new" > c/new.txt
}

mkdir -p tests/data/source

pushd tests/data/source

case "$1" in
    "a")
        state_a ;;

    "b")
        state_b ;;

    "c")
        state_c ;;

    *)
      exit 0 ;;
esac


