File: smd-uniform-names

package info (click to toggle)
syncmaildir 1.2.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,188 kB
  • ctags: 479
  • sloc: ansic: 6,321; sh: 1,969; makefile: 258; xml: 14
file content (99 lines) | stat: -rwxr-xr-x 2,379 bytes parent folder | download | duplicates (6)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/sh
#
# Released under the terms of GPLv3 or at your option any later version.
# No warranties.
# Copyright Enrico Tassi <gares@fettunta.org>

# the idea is:
# 0) it is the first run (no db)
# 1) we compute the local db with mddiff
# 2) we push it to the remote host via ssh
# 3) we start a special pull where smd-server uses the special db
#    and where smd-client just emits a shell script with all the renaming
# 4) we remove the remote db

set -e
#set -x

PREFIX="@PREFIX@"
if [ `echo "$PREFIX" | cut -c -1` = "@" ]; then
	SMDROOT=.
	echo "smd-uniform-names not installed, assuming smd-common is ./smd-common"
else
	SMDROOT=$PREFIX/share/syncmaildir
fi

. $SMDROOT/smd-common

init
parse_args "$@"
read_conffile
# this could be a system wide pre-hook
check_lockfile
setup_plumbing
setup_logging
setup_mailboxnames

# we move to the home, since Mail paths are relative
# to the home
cd

setup_workarea

ORIG_CHILDARGS="$CHILDSARGS"

CHILDSARGS="$ORIG_CHILDARGS --get-mddiff-cmdline"
DB=`run_local_server | sed 's?^.*--db-file \([^ ][^ ]*\) .*$?\1?'`
if [ -e "$DB" ]; then
	echo "Found db file: $DB"
	echo "This utility can be used only before any synchronization"
	echo "takes place. See the manpage for more details."
	exit 1
fi

CHILDSARGS="$ORIG_CHILDARGS --get-mddiff-cmdline --override-db ~/$RENAMEDB"
MDLINE=`run_local_server`

EXITCODE=0

gc_mktemp
TMPERR="$RC"
gc_mktemp
TMPOUT="$RC"
(cd $WORKAREA; $MDLINE) > $TMPOUT 2> $TMPERR || EXITCODE=1
grep -v '^warning.*unable to open db' $TMPERR || true
grep '^ERROR' $TMPOUT || true
if [ $EXITCODE = 1 ]; then exit $EXITCODE; fi
mv ~/$RENAMEDB.new ~/$RENAMEDB
atexit_rm ~/$RENAMEDB.mtime.new
atexit_rm ~/$RENAMEDB

CHILDSARGS="$ORIG_CHILDARGS --dump-stdin ~/$RENAMEDB"
cat ~/$RENAMEDB | run_remote_server 

($MITM $CtS > $LtS) < $CtL &
LOGGER1=$!
atexit_kill $LOGGER1

($MITM $StC > $LtC) < $StL &
LOGGER2=$!
atexit_kill $LOGGER2

($PROGRESS_REPORTER $CL) < $PRp &
REPORTER=$!
atexit_kill $REPORTER

CHILDSARGS="$ORIG_CHILDARGS --rename-only --override-db ~/$RENAMEDB"
(run_local_client < $LtC 2> $PRp) > $CtL &
CLIENT=$!
atexit_kill $CLIENT

CHILDSARGS="$ORIG_CHILDARGS --no-move --stop-after-diff --override-db ~/$RENAMEDB"
(run_remote_server < $LtS 2> $SL) > $StL  || EXITCODE=1

wait $CLIENT || EXITCODE=1 
wait $REPORTER || EXITCODE=1 

report $EXITCODE 0 smd-push smd-pull smd-server smd-client

exit $EXITCODE