From 8fa3ddbc6cdf5adb3414c782ff83c371b17d38d8 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sun, 5 Feb 2012 13:48:14 -0200 Subject: Fixing init command and checking for empty recipients file --- lib/keyringer/functions | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/keyringer/functions b/lib/keyringer/functions index 58f7ad1..da8be2e 100644 --- a/lib/keyringer/functions +++ b/lib/keyringer/functions @@ -95,10 +95,9 @@ function keyringer_is_git { elif [ -d "$1/.git" ]; then true else - cwd="`pwd`" - cd "$1" && git="`git status &> /dev/null`" && cd "$cwd" + ( cd "$1" && git status &> /dev/null ) - if [ "$git" != "128" ]; then + if [ "$?" != "128" ]; then true else false @@ -225,7 +224,9 @@ function keyringer_check_version { if [ ! -f "$VERSION_INFO" ]; then echo "Creating configuration version file..." echo 0 > "$VERSION_INFO" - keyringer_exec git "$BASEDIR" add config/version + if keyringer_is_git "$BASEDIR"; then + keyringer_exec git "$BASEDIR" add config/version + fi fi VERSION="`cat $VERSION_INFO`" @@ -282,6 +283,13 @@ function keyringer_action_usage { # Check recipients function keyringer_check_recipients { + # Check if recipients file is empty. + if [ "`grep -vE "^#|^$" "$RECIPIENTS" | wc -l`" == 0 ] && [ "$SUBCOMMAND" != "edit" ]; then + echo "Fatal: no recipients configured for this keyring." + echo "Please edit your recipients file first." + exit 1 + fi + # Check recipients header for updates. if grep -qe ' XXXXXXXX$' "$RECIPIENTS"; then echo "Updating recipients file..." -- cgit v1.2.3