Skip to content

Instantly share code, notes, and snippets.

@simmac
Last active April 19, 2016 10:49
Show Gist options
  • Save simmac/917eb7106d9fcf08e1df2cf925afb82a to your computer and use it in GitHub Desktop.
Save simmac/917eb7106d9fcf08e1df2cf925afb82a to your computer and use it in GitHub Desktop.
Threema Backup to openMittsu contacts file

Usage: ./create_contacts.sh -i /path/to/extracted/backup/ -o /path/to/output/file.ext -n args while -n specifies the content of the name field:

  • f for first name
  • l for last name
  • n for nickname
  • i for Threema ID
  • "character" for a special character/string which acts as a delimiter between fields

You can order the fields as you like and don't have to use all fields.

For example, ./create_contacts.sh -n fl"("n") -"i would create a line like ABCDEF12 : publickey123 : John Doe ( johnny ) - ABCDEF12,

./create_contacts.sh -n lf would be ABCDEF12 : publickey123 : Doe John et cetera.

All arguments are optional, the default arguments are . for -i, contacts.txt for -o and fl"("n")" for -n.

#!/bin/bash
inputdir="."
outputfile="contacts.txt"
firstfields='print $2, ":", $3, ":"'
namefields=', $7, $8, "("$9")"'
id=', $2'
firstname=', $7'
lastname=', $8'
nickname=', $9'
while getopts ":n:i:o:" opt; do
case $opt in
n)
fieldorder="$OPTARG"
namefields=""
;;
i)
inputdir="$OPTSARG"
;;
o)
outputfile="$OPTSARG"
;;
:) ;;
esac
done
for (( i=0; i<${#fieldorder}; i++ )); do
case "${fieldorder:$i:1}" in
f)
namefields="${namefields}$firstname"
;;
l)
namefields="${namefields}$lastname"
;;
n)
namefields="${namefields}$nickname"
;;
i)
namefields="${namefields}$id"
;;
*)
field=", \"${fieldorder:$i:1}\""
namefields="${namefields}$field"
;;
esac
done
awk -F'","|^"|"$' " NR>1 { $firstfields $namefields }" $inputdir/contacts.csv > $outputfile
awk -F'","|^"|"$' ' NR>1 { gsub(";",", ",$6); print $2, ":", $3, ":", $6, ":",$4 }' $inputdir/groups.csv >> $outputfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment