aboutsummaryrefslogtreecommitdiff
path: root/lib/keyringer/functions
blob: f0c4e0fdb9742810e66ff8c13303fcf1ecbec874 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
#
# Common functions.
#

function keyringer_config {
  if [ -z "$CONFIG" ]; then
    echo "Your have to set CONFIG variable in the code"
    exit 1
  elif [ -e "$CONFIG" ]; then
    grep -e "^$1=" $CONFIG | tail -n 1 | cut -d = -f 2 | sed -e 's/"//g' -e "s/'//g" | sed -e 's/ *#.*$//'
  else
    echo "Config file not found: $CONFIG"
    exit 1
  fi
}

function keyringer_recipients {
  grep -v '^#' $1 | grep -v '^$' | awk '{ print "-r " $2 }' | xargs
}

function keyringer_has_action {
 if [ -z "$ACTIONS" ]; then
   echo "Your have to set ACTIONS variable in the code"
   exit 1
 fi

 if [ -e "$ACTIONS/$1" ]; then
   true
 else
   false
 fi
}

function keyringer_exec {
  # Setup
  action="$1"
  basedir="$2"
  shift 2
  
  # Dispatch
  if keyringer_has_action $action; then
    $ACTIONS/$action $basedir $*
  fi
}

function keyringer_filename {
  echo `dirname $1`/`basename $1 .gpg`.gpg
}