diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2010-01-05 13:30:01 -0200 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2010-01-05 13:30:01 -0200 |
commit | fbc7b1b2c12079fbb7fd55430e8d2a29c214be81 (patch) | |
tree | 5aa6ac02ca79bba56c1a2c59e0a0b3d7eead5116 | |
parent | 1b24dedf6c343a62166661322aa092494471a830 (diff) | |
download | keyringer-fbc7b1b2c12079fbb7fd55430e8d2a29c214be81.tar.gz keyringer-fbc7b1b2c12079fbb7fd55430e8d2a29c214be81.tar.bz2 |
Checking if a folder is inside a git repository
-rwxr-xr-x | keyringer | 20 | ||||
-rw-r--r-- | lib/keyringer/functions | 25 |
2 files changed, 40 insertions, 5 deletions
@@ -21,6 +21,7 @@ function keyringer_init { BASEDIR="$3" URL="$4" + RECIPIENTS="$BASEDIR/config/recipients" # Parse if [ -z "$BASEDIR" ]; then @@ -39,10 +40,19 @@ function keyringer_init { exit 1 fi else - mkdir -p $BASEDIR/{config,keys} - echo "# Use entries in the form of 'john@doe.com XXXXXXXX" > $BASEDIR/config/recipients - echo "" >> $BASEDIR/config/recipients - chmod 600 $BASEDIR/config/recipients + if [ -e "$BASEDIR" ]; then + if [ ! -d "$BASEDIR/keys" ] || [ ! -e "$RECIPIENTS" ]; then + echo "Invalid keyring $BASEDIR: incomplete installation" + exit 1 + fi + else + mkdir -p $BASEDIR/{config,keys} + echo "# Use entries in the form of 'john@doe.com XXXXXXXX" > $RECIPIENTS + echo "" >> $RECIPIENTS + fi + + # Secure + chmod 600 $RECIPIENTS fi # Reparse basedir to force absolute folder @@ -53,7 +63,7 @@ function keyringer_init { echo "$KEYRING=\"$BASEDIR\"" >> $CONFIG # Init - if [ ! -d "BASEDIR/.git" ]; then + if ! keyringer_is_git $BASEDIR; then keyringer_exec git $BASEDIR init keyringer_exec git $BASEDIR add . keyringer_exec git $BASEDIR commit -m Importing diff --git a/lib/keyringer/functions b/lib/keyringer/functions index f0c4e0f..9c03000 100644 --- a/lib/keyringer/functions +++ b/lib/keyringer/functions @@ -3,6 +3,7 @@ # Common functions. # +# Load a parameter from config function keyringer_config { if [ -z "$CONFIG" ]; then echo "Your have to set CONFIG variable in the code" @@ -15,10 +16,12 @@ function keyringer_config { fi } +# Return the list of recipients function keyringer_recipients { grep -v '^#' $1 | grep -v '^$' | awk '{ print "-r " $2 }' | xargs } +# Check if keyringer has a given action function keyringer_has_action { if [ -z "$ACTIONS" ]; then echo "Your have to set ACTIONS variable in the code" @@ -32,6 +35,7 @@ function keyringer_has_action { fi } +# Execute an action function keyringer_exec { # Setup action="$1" @@ -44,6 +48,27 @@ function keyringer_exec { fi } +# Return a filename with correct extension function keyringer_filename { echo `dirname $1`/`basename $1 .gpg`.gpg } + +# Check if a folder is inside a git repository +function keyringer_is_git { + if [ -z "$1" ]; then + false + elif [ ! -d "$1" ]; then + false + elif [ -d "$1/.git" ]; then + true + else + cwd="`pwd`" + cd $1 && git="`git status &> /dev/null`" && cd $cwd + + if [ "$git" != "128" ]; then + true + else + false + fi + fi +} |