#!/bin/bash set -e set -u usage () { cat <&2 exit 1 fi echo "Enter an existing LUKS passphrase: " >&2 read -s existing echo "Enter a new first factor passphrase: " >&2 read -s first response='' until [[ "$response" != "" ]]; do # A little side note about ykchalresp. Originally there was # more comprehensive error handling here, but it was ugly # because ykchalresp uses 1 for just about every failure # mode. The stderr was different, but capturing both stdout # and stderr is a real challenge in shell and relying on # error messages is a bad idea (tm) anyway. So now stderr # bubbles out to the user and this script loops until the # user gives up. echo "Use your Yubikey as a second factor: " >&2 if stdout=$(ykchalresp "$SLOT" "$first") ; then response="$stdout" else echo "Press enter before trying again" >&2 read -s enter fi done echo "Adding key to Luks container" >&2 # The following is based on the 'cryptsetup luksAddKey' dialog echo "$existing" echo "$response" echo "$response"