#!/bin/bash

#crhd=$(lsblk | grep -m1 crypt_dev | awk -F_ '{print $3}' | awk '{print $1}')
LUKS_PASSWORD="$1"

echo "Change default LUKS Password to the new one"
if [ "$LUKS_PASSWORD" ]; then
    for platte in $(blkid -t TYPE=crypto_LUKS | awk '{print $1}' | awk -F: '{print $1}'); do
	# check, if adding the new luks key is successfull
	if printf '%s\n' "86343" "$LUKS_PASSWORD" "$LUKS_PASSWORD" | /sbin/cryptsetup -q luksAddKey --force-password "$platte"; then
	    sleep 1
	    # remove the old default key
	    printf '%s\n' "86343" | /sbin/cryptsetup -q luksRemoveKey "$platte"
	    sleep 1
	else
	    echo "Fehler beim Hinzufügen des Schlüssels für $platte" >&2
	fi
    done
fi

