summaryrefslogtreecommitdiff
path: root/common
blob: ffc74be4fcbbc40bcb7bc1cd43e502dab0f801c6 (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
50
51
52
53
#!/hint/bash

alpine_keys=(
  'NICKNAME'
  'FN'
  'EMAIL'
  'FCC'
  'COMMENT'
)

keys=(
  'UID'
  "${alpine_keys[@]}"
  'REV'
)

find_vcfs() {
  {
    find "${git_dir}" \
      -name '.git' \
      -prune \
      , \
      -type f \
      -name '*.vcf' \
      -printf '%p\n'
    git -C "${git_dir}" archive HEAD \
    | tar -t \
    | sed '
      /\.vcf$/!d
      s@^@'"${git_dir%/}"'/@
    '
  } \
  | sort -u \
  | if [ -n "${old_uids}" ]; then
    join -1 1 -2 3 -o 2.1,2.2,2.3 -a 1 -e 1 -t ' ' - <(
      printf "${git_dir}"'/%s.vcf\n' ${old_uids} \
      | cat -n \
      | awk '{print "0 " $1 " " $2}' \
      | sort -k3,3
    ) \
    | sort -k1n,1 -k2n,2 \
    | awk '{print $3}'
  else
    cat
  fi
}

git_dir="$1"

if [ ! -d "${git_dir}" ]; then
  >&2 printf 'invalid git dir: "%s"\n' "${git_dir}"
  exit 1
fi