#! /bin/sh
set -ex

dkl=target/debug/dkl

test=${1:-dynlay}

export RUST_LOG=debug

case $test in
  apply-config)
    $dkl apply-config -P tmp/test-system -F '*.crt'
    ;;

  logger)
    $dkl logger --log-path tmp/log --with-prefix -- bash -c 'echo stdout; echo 1>&2 stderr'

    tree tmp/log
    cat tmp/log/bash.log
    ;;

  log-ls)
    $dkl log --log-path tmp/log bash ls -l
    ;;
  log-cat)
    $dkl log --log-path tmp/log bash cat 20250720_12 20301231_23
    ;;
  log-clean)
    $dkl log --log-path tmp/log bash ls -l
    $dkl log --log-path tmp/log bash cleanup 0
    ;;

  dynlay)
    mkdir -p tmp/system
    $dkl dynlay --layers-dir tmp/dynlay --chroot tmp/system kubernetes v1.33.3_containerd.2.0.5
    ;;

  *) echo 1>&2 "unknown test: $test"; exit 1 ;;
esac

