From 9c9a750009897f0acab2a5320300cdcb42d62aae Mon Sep 17 00:00:00 2001 From: Martin Zuther Date: Sun, 29 Dec 2019 15:53:01 +0100 Subject: [PATCH] get rid of dependencies (pure bash) --- contrib/hooks/post_list | 34 +++++++++++++++------------------- contrib/hooks/post_status | 10 ++++++---- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/contrib/hooks/post_list b/contrib/hooks/post_list index 6e0394e..0cc65c4 100755 --- a/contrib/hooks/post_list +++ b/contrib/hooks/post_list @@ -46,28 +46,24 @@ if [ ! -f "$YADM_CHECKSUMS" ]; then exit "$YADM_HOOK_EXIT" fi -# list encrypted files; try to satisfy the "list -a" argument and -# beautify the output (requires "grep" and "sed") -if command -v grep > /dev/null && command -v sed > /dev/null; then +# list encrypted files +while IFS= read -r filename; do # remove checksums from file names - while IFS= read -r filename; do - if [ $OPTION_LIST_ALL -eq 0 ]; then - # list only files in the subdirectories below (i.e. files - # whose relative path doesn't begin with "../") - REL_PATH=$(relative_path "$PWD" "$YADM_HOOK_WORK/$filename") + filename="${filename##[a-zA-Z0-9]* }" - if ! echo "$REL_PATH" | grep '^\.\./' > /dev/null; then - echo "$REL_PATH" - fi - else - # list all files - echo "$filename" + # list only files in the subdirectories below (i.e. files + # whose relative path doesn't begin with "../") + if [ $OPTION_LIST_ALL -eq 0 ]; then + REL_PATH=$(relative_path "$PWD" "$YADM_HOOK_WORK/$filename") + + if [ "$REL_PATH" = "${REL_PATH##../}" ]; then + echo "$REL_PATH" fi - done <<< "$(sed -r 's/^\S+\s+//' "$YADM_CHECKSUMS")" -else - # just display checksum file - cat "$YADM_CHECKSUMS" -fi + # list all files + else + echo "$filename" + fi +done <<< "$(cat "$YADM_CHECKSUMS")" # return original exit status of yadm command exit "$YADM_HOOK_EXIT" diff --git a/contrib/hooks/post_status b/contrib/hooks/post_status index 1a308ef..e13b599 100755 --- a/contrib/hooks/post_status +++ b/contrib/hooks/post_status @@ -83,10 +83,12 @@ if [ $ERROR_CODE -ne 0 ]; then echo -e "\033[0;31m" while IFS= read -r line; do - # try to beautify output (requires "grep" and "sed") - if command -v grep > /dev/null && command -v sed > /dev/null; then - echo "$line" | grep -iv "\sok$" | sed 's/^/ / ; s/: FAILED$// ; /^.*WARNING:.*did NOT match$/ d' - else + # beautify output and get rid of unnecessary lines + line="${line%%*: [Oo][Kk]}" + line="${line%%: [Ff][Aa][Ii][Ll][Ee][Dd]}" + line="${line##*WARNING:*did NOT match}" + + if [ -n "$line" ]; then echo "$line" fi done <<< "$YADM_CHECKSUM_OUTPUT"