#!/usr/bin/env sh

exec >> /target/var/log/zooxpxeinstall.log 2>&1

echo "create luks key for encrypted partition"

# Use /target as working directory
KEY_FILE="/target/etc/cryptroot/keyfile"
CRYPT_DISK=`blkid -t TYPE="crypto_LUKS" | sed 's/:.*//g'`
PASSPHRASE="{{ cobbler_osdrive_encryption_default_password }}"

# Add luks key for encrypted partition
echo ${PASSPHRASE} | cryptsetup luksAddKey ${CRYPT_DISK} ${KEY_FILE}

# Remove default passphrase for encrypted partition -- optional
echo ${PASSPHRASE} | cryptsetup luksRemoveKey ${CRYPT_DISK}
