get rid of echo

pull/188/head
Martin Zuther 4 years ago
parent 499837bd80
commit 0009bb350b
No known key found for this signature in database
GPG Key ID: 47D3346D758A37D8

@ -31,21 +31,21 @@ IFS="$OLD_IFS"
function get_checksum_command { function get_checksum_command {
# check if "shasum" exists and supports the algorithm (which is # check if "shasum" exists and supports the algorithm (which is
# tested by sending an empty string to "shasum") # tested by sending an empty string to "shasum")
if command -v "shasum" > /dev/null && echo -n | shasum --algorithm "256" &> /dev/null; then if command -v "shasum" > /dev/null && printf "" | shasum --algorithm "256" &> /dev/null; then
echo "shasum --algorithm 256" printf "shasum --algorithm 256"
# check if "sha256sum" exists # check if "sha256sum" exists
elif command -v "sha256sum" > /dev/null; then elif command -v "sha256sum" > /dev/null; then
echo "sha256sum" printf "sha256sum"
# check if "gsha256sum" exists # check if "gsha256sum" exists
elif command -v "gsha256sum" > /dev/null; then elif command -v "gsha256sum" > /dev/null; then
echo "gsha256sum" printf "gsha256sum"
else else
# display warning in bright yellow # display warning in bright yellow
echo -e "\033[1;33m" >&2 printf "\033[1;33m" >&2
echo -n "WARNING: \"shasum\", \"sha256sum\" and \"gsha256sum\" not found. $WARNING_MESSAGE." >&2 printf "\nWARNING: \"shasum\", \"sha256sum\" and \"gsha256sum\" not found. %s\n" "$WARNING_MESSAGE." >&2
# reset output color # reset output color
echo -e "\033[0m" >&2 printf "\033[0m" >&2
# signal error # signal error
return 1 return 1
@ -63,28 +63,28 @@ if (($?)); then
fi fi
# empty (or create) checksum file # empty (or create) checksum file
echo -n > "$YADM_CHECKSUMS" true > "$YADM_CHECKSUMS"
# calculate checksums for encrypted files # calculate checksums for encrypted files
for included in "${YADM_ENCRYPT_INCLUDE_FILES[@]}"; do for included in "${YADM_ENCRYPT_INCLUDE_FILES[@]}"; do
# highlight any errors in red # highlight any errors in red
echo -en "\033[0;31m" printf "\033[0;31m"
# calculate checksums # calculate checksums
$CHECKSUM_COMMAND "$included" >> "$YADM_CHECKSUMS" $CHECKSUM_COMMAND "$included" >> "$YADM_CHECKSUMS"
ERROR_CODE=$? ERROR_CODE=$?
# reset output color # reset output color
echo -ne "\033[0m" printf "\033[0m"
# handle errors # handle errors
if (($ERROR_CODE)); then if (($ERROR_CODE)); then
# display warning in bright yellow # display warning in bright yellow
echo -e "\033[1;33m" >&2 printf "\033[1;33m" >&2
echo -n "WARNING: an error occurred. Please inspect the checksum file." >&2 printf "\nWARNING: an error occurred. Please inspect the checksum file.\n" >&2
# reset output color # reset output color
echo -e "\033[0m" >&2 printf "\033[0m" >&2
# exit and signal error # exit and signal error
exit $ERROR_CODE exit $ERROR_CODE
@ -92,5 +92,5 @@ for included in "${YADM_ENCRYPT_INCLUDE_FILES[@]}"; do
done done
# announce success and return original exit status of yadm command # announce success and return original exit status of yadm command
echo "Wrote SHA-256 checksums: $YADM_CHECKSUMS" printf "Wrote SHA-256 checksums: %s\n" "$YADM_CHECKSUMS"
exit "$YADM_HOOK_EXIT" exit "$YADM_HOOK_EXIT"

@ -57,11 +57,11 @@ while IFS= read -r filename; do
REL_PATH=$(relative_path "$PWD" "$YADM_HOOK_WORK/$filename") REL_PATH=$(relative_path "$PWD" "$YADM_HOOK_WORK/$filename")
if [ "$REL_PATH" = "${REL_PATH##../}" ]; then if [ "$REL_PATH" = "${REL_PATH##../}" ]; then
echo "$REL_PATH" printf "%s\n" "$REL_PATH"
fi fi
# list all files # list all files
else else
echo "$filename" printf "%s\n" "$filename"
fi fi
done < "$YADM_CHECKSUMS" done < "$YADM_CHECKSUMS"

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

Loading…
Cancel
Save