#!/usr/bin/env bash

ceph=true luks=true zfs=true

while [[ $# -gt 0 ]]; do
  case "$1" in
    "-h" | "--help")
      echo "Usage:"
      echo "$0 [-h|--help] --disk /dev/sdx --name chaos [--no-ceph] [--no-zfs]"
      exit 0
      ;;
    "--disk")
      disk=$2
      shift
      ;;
    "--name")
      name=$2
      shift
      ;;
    "--no-ceph") ceph=false;;
    "--no-luks") luks=false;;
    "--no-zfs")  zfs=false ;;
    *)
      echo "Argument $1 is not understood."
      exit 2
      ;;
  esac
  shift
done

if [[ -z ${disk:-} || -z ${name:-} ]]; then
  echo "--disk and --name must be supplied!"
  exit 1
fi

# TODO: wait for https://github.com/nix-community/disko/pull/211 to be merged
sudo nix run github:SuperSandro2000/disko/zpool-R -- --mode zap_create_mount ./disko-config.nix --debug \
  --arg disk '"'"$disk"'"' --arg name '"'"$name"'"' \
  --arg enableCeph "$ceph" --arg enableLuks "$luks" --arg enableZfs "$zfs"
