-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeagleim-move-history.sh
executable file
·60 lines (48 loc) · 1.37 KB
/
beagleim-move-history.sh
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
54
55
56
57
58
59
60
#!/bin/sh
set -e -u
# only use system utilities
_PATH=$(command -p getconf PATH) \
&& test -n "${_PATH}" \
&& PATH=${_PATH}
unset -v _PATH
db=~/Library/Containers/org.tigase.messenger.BeagleIM/Data/Library/Application\ Support/BeagleIM/beagleim.sqlite
test -f "${db}" || {
echo 'are you really using Beagle IM?' >&2
exit 1
}
test $# -eq 2 || {
printf 'usage: %s [old jid] [new jid]\n' "$0" >&2
exit 1
}
! pgrep -i BeagleIM | grep -q . || {
printf 'please close BeagleIM first.\n' >&2
exit 1
}
old_account=${1:?}
new_account=${2:?}
tmp_db=$(mktemp "${db}.XXXXXX")
sqlite3 "${db}" ".backup '${tmp_db}'"
for tc in \
chat_markers:jid \
chat_markers:sender_jid \
omemo_sessions:name
do
sqlite3 "${tmp_db}" "UPDATE ${tc%%:*} SET ${tc#*:} = '${new_account}' WHERE account = '${old_account}' AND ${tc#*:} = '${old_account}';"
done
for tbl in \
chat_history \
chat_markers \
omemo_identities \
omemo_pre_keys \
omemo_sessions \
omemo_signed_pre_keys \
roster_items
do
sqlite3 "${tmp_db}" "UPDATE ${tbl} SET account = '${new_account}' WHERE account = '${old_account}';"
done
mv -n -v "${db}" "${db}.bak"
test -f "${db}-shm" && mv -n -v "${db}-shm" "${db}.bak-shm"
test -f "${db}-wal" && mv -n -v "${db}-wal" "${db}.bak-wal"
mv -n -v "${tmp_db}" "${db}"
test -f "${tmp_db}-shm" && mv -n -v "${tmp_db}-shm" "${db}-shm"
test -f "${tmp_db}-wal" && mv -n -v "${tmp_db}-wal" "${db}-wal"