nix-config/disko/format-disk.sh

56 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
useConfig=false config='""' ceph=true luks=true zfs=true
cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null || exit 1
while [[ $# -gt 0 ]]; do
case "$1" in
"-h" | "--help")
echo "Usage:"
echo "$0 [-h|--help] --name chaos [--config [hosts/\$name/default.nix]] [--disk /dev/sdx] [--no-ceph] [--no-luks] [--no-zfs]"
echo
echo "If only --config is supplied, the script tries to guess the nix file to import from --name."
echo "Note: --config is none working"
exit 0
;;
"--name")
name=$2
shift
;;
"--config")
useConfig=true
if [[ $2 =~ ^-- ]]; then
config=$2
shift
else
config=../hosts/$name/default.nix
fi
shift
;;
"--disk")
disk=$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 ${name:-} && (-n ${config:-} || -n ${disk:-}) ]]; then
echo $name $config $disk
# echo "--name and either config or disk must be supplied!"
echo "--name and disk 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 useConfig "$useConfig" --arg config "$config" \
--arg enableCeph "$ceph" --arg enableLuks "$luks" --arg enableZfs "$zfs"