I am trying to script the integrity check of a VeraCrypt volume.
#! /bin/sh
red=$'\e[1;31m'
end=$'\e[0m'
set -e
printf "Please enter password: "
read -s p
if [ -f "/Volumes/Samsung BAR/bar.hmac" ]; then
printf "\n%s" "Checking integrity..."
if [ "$(openssl dgst -sha512 -hmac "$p" "/Volumes/Samsung BAR/bar")" != "$(<"/Volumes/Samsung BAR/bar.hmac")" ]; then
printf "\n%s" "${red}Check failed${end}"
exit 1
fi
fi
printf "\n%s\n" "Unlocking VeraCrypt volume..."
veracrypt --text --non-interactive --mount --pim 0 --keyfiles "" --protect-hidden no --password "$p" "/Volumes/Samsung BAR/bar" /Volumes/Backup
declare -a files=(
"/Users/sunknudsen/.gnupg"
"/Users/sunknudsen/.ssh"
"/Users/sunknudsen/Library/Keychains"
)
for file in "${files[@]}"; do
rsync -axRS --delete "$file" /Volumes/Backup
done
open /Volumes/Backup
printf "${red}Inspect backup and press enter${end}"
read -r answer
veracrypt --text --dismount "/Volumes/Samsung BAR/bar"
echo "Saving HMAC..."
openssl dgst -sha512 -hmac "$p" "/Volumes/Samsung BAR/bar" > "/Volumes/Samsung BAR/bar.hmac"
echo "Done"
Security warning: Using read -s p
is vulnerable to process listing leaks so I need to find another way to feed the password to both openssl and veracrypt.