yadm/contrib/hooks/post_encrypt

58 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# yadm - Yet Another Dotfiles Manager
# Copyright (C) 2015-2019 Tim Byrne and Martin Zuther
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
YADM_DIRECTORY=$(dirname $YADM_HOOK_REPO)
YADM_CHECKSUMS=$YADM_DIRECTORY/files.checksums
# check if "shasum" exists
if command -v shasum > /dev/null; then
# check if "shasum" supports SHA-512/256 algorithm
echo -n | shasum --algorithm 512256 2>&1 1> /dev/null
if [ $? -ne 0 ]; then
echo
echo "WARNING: \"shasum\" does not support SHA-512/256. No checksums were created."
exit $YADM_HOOK_EXIT
fi
# empty checksum file
echo -n > $YADM_CHECKSUMS
# calculate checksums for encrypted files
for included in ${YADM_ENCRYPT_INCLUDE_FILES[@]}; do
shasum --algorithm 512256 $included >> $YADM_CHECKSUMS
ERROR_CODE=$?
# signal errors
if [ $ERROR_CODE -ne 0 ]; then
exit $ERROR_CODE
fi
done
echo "Wrote checksums: $YADM_CHECKSUMS (SHA-512/256)"
else
echo
echo "WARNING: command \"shasum\" not found. No checksums were created."
exit $YADM_HOOK_EXIT
fi
# return exit status of the yadm command
exit $YADM_HOOK_EXIT