1
0
mirror of https://github.com/TheLocehiliosan/yadm synced 2026-03-02 03:49:29 +00:00

get rid of echo

This commit is contained in:
Martin Zuther
2019-12-30 00:43:24 +01:00
parent 499837bd80
commit 0009bb350b
3 changed files with 28 additions and 29 deletions

View File

@@ -31,21 +31,21 @@ IFS="$OLD_IFS"
function get_checksum_command {
# check if "shasum" exists and supports the algorithm (which is
# tested by sending an empty string to "shasum")
if command -v "shasum" > /dev/null && echo -n | shasum --algorithm "256" &> /dev/null; then
echo "shasum --algorithm 256"
if command -v "shasum" > /dev/null && printf "" | shasum --algorithm "256" &> /dev/null; then
printf "shasum --algorithm 256"
# check if "sha256sum" exists
elif command -v "sha256sum" > /dev/null; then
echo "sha256sum"
printf "sha256sum"
# check if "gsha256sum" exists
elif command -v "gsha256sum" > /dev/null; then
echo "gsha256sum"
printf "gsha256sum"
else
# display warning in bright yellow
echo -e "\033[1;33m" >&2
echo -n "WARNING: \"shasum\", \"sha256sum\" and \"gsha256sum\" not found. $WARNING_MESSAGE." >&2
printf "\033[1;33m" >&2
printf "\nWARNING: \"shasum\", \"sha256sum\" and \"gsha256sum\" not found. %s\n" "$WARNING_MESSAGE." >&2
# reset output color
echo -e "\033[0m" >&2
printf "\033[0m" >&2
# signal error
return 1
@@ -75,11 +75,10 @@ ERROR_CODE=$?
# handle mismatched checksums and errors
if (($ERROR_CODE)); then
echo
echo "Some SHA-256 sums do not match (or an error occurred):"
printf "\nSome SHA-256 sums do not match (or an error occurred):\n\n"
# display differing files and errors (highlighted in red)
echo -e "\033[0;31m"
printf "\033[0;31m"
while IFS= read -r line; do
# beautify output and get rid of unnecessary lines
@@ -88,14 +87,14 @@ if (($ERROR_CODE)); then
line="${line##*WARNING:*did NOT match}"
if [ -n "$line" ]; then
echo "$line"
printf "%s\n" "$line"
fi
done <<< "$YADM_CHECKSUM_OUTPUT"
# reset output color
echo -e "\033[0m"
printf "\033[0m"
# display advice for differing files and signal error
echo "Consider running either \"yadm encrypt\" or \"yadm decrypt\"."
printf "\nConsider running either \"yadm encrypt\" or \"yadm decrypt\".\n"
exit $ERROR_CODE
fi