diff options
author | Erich Eckner <git@eckner.net> | 2021-11-11 18:54:53 +0100 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2021-11-11 18:54:53 +0100 |
commit | c277109cfa15f4fb65636d883c0a06792b5f5da0 (patch) | |
tree | 1a96e56dc846ff3578bc0f7b6b98fee5d71df94d | |
parent | c1140e40b003d6ed6ffa7ca5d4cb699d5c8dfec6 (diff) | |
download | carddav-alpine-converter-c277109cfa15f4fb65636d883c0a06792b5f5da0.tar.xz |
carddav-to-alpine könnte schon gehen
-rwxr-xr-x | carddav-to-alpine | 77 | ||||
-rw-r--r-- | common | 15 |
2 files changed, 92 insertions, 0 deletions
diff --git a/carddav-to-alpine b/carddav-to-alpine new file mode 100755 index 0000000..1f852b9 --- /dev/null +++ b/carddav-to-alpine @@ -0,0 +1,77 @@ +#!/bin/bash + +. "${0%/*}/common" + +error=0 + +keys=( + 'UID' + 'EMAIL' + 'FN' + 'NICKNAME' + 'FCC' + 'COMMENT' + 'REV' +) + +touch "${git_dir}"'/uids' + +find "${git_dir}" \ + -name '.git' \ + -prune \ + , \ + -type f \ + -name '*.vcs' \ + -printf '%p\n' \ +| while read -r f; do + uid="${f##*/}" + uid="${uid%.vcs}" + + for key in "${keys[@]}"; do + eval 'unset _'"${key}" + done + + while read -r key value; do + eval '_'"${key}"'="${value}"' + done < <( + sed -n ' + s@\t@ @g + s@\r$@@ + /^BEGIN:VCARD$/,/END:VCARD$/ { + /^\('"$(printf '%s\\|' "${keys[@]}" | sed 's@\\|$@@')"'\):/ { + s@:@ @ + p + } + } + ' "$f" + ) + + if [ "${_UID}" != "${uid}" ]; then + >&2 printf 'uids differ: "%s" != "%s"\n' "${uid}" "${_UID}" + error=1 + continue + fi + + sed -i ' + /^'"${uid}"' /d + ' "${git_dir}"'/uids' + + printf '%s\t' \ + "${_UID}" \ + "${_NICKNAME}" \ + "${_FN}" \ + "${_EMAIL}" \ + "${_FCC}" \ + "${_COMMENT}" \ + | sed ' + s@\t@ @ + s@\t$@\n@ + ' >>"${git_dir}"'/uids' +done + +sed ' + s@^\S\+ @@ +' "${git_dir}"'/uids' \ +>"${git_dir}"'/addressbook' + +exit ${error} @@ -0,0 +1,15 @@ +#!/hint/bash + +gen_rev() { + printf 'REV:%s\n' "$( + date -u -Iseconds \ + | sed 's@+00:00$@Z@' + )" +} + +git_dir="$1" + +if [ ! -d "${git_dir}" ]; then + >&2 printf 'invalid git dir: "%s"\n' "${git_dir}" + exit 1 +fi |