2 # fixscript will replace this line with code to load innshellvars
4 # @(#) $Id: actmerge.in 2674 1999-11-15 06:28:29Z rra $
5 # @(#) Under RCS control in /usr/local/news/src/inn/local/RCS/actmerge.sh,v
7 # actmerge - merge two active files
10 # actmerge [-s] ign1 ign2 host1 host2
12 # -s - write status on stderr even if no fatal error
13 # ign1 - ignore file for host1
14 # ign2 - ignore file for host2
15 # host1 - 1st active file or host
16 # host2 - 2nd active file or host
18 # The merge of two active files are sent to stdout. The status is
21 # By: Landon Curt Noll chongo@toad.com (chongo was here /\../\)
23 # Copyright (c) Landon Curt Noll, 1996.
24 # All rights reserved.
26 # Permission to use and modify is hereby granted so long as this
27 # notice remains. Use at your own risk. No warranty is implied.
33 LOCK=${LOCKS}/LOCK.actmerge
34 # where actsync is located
35 ACTSYNC=${PATHBIN}/actsync
36 # exit value of actsync if unable to get an active file
38 # args used by actsync a fetch of an active file
39 FETCH="-b 0 -d 0 -g 0 -o aK -p 0 -q 12 -s 0 -t 0 -v 2"
40 # args used to merge two active files
41 MERGE="-b 0 -d 0 -g 0 -m -o aK -p 0 -q 12 -s 0 -t 0 -v 3"
48 if [ X"-s" = X"$1" ]; then
54 echo "usage: $0 ign1 ign2 host1 host2" 1>&2
58 if [ ! -s "$ign1" ]; then
59 echo "$0: host1 ignore file not found or empty: $ign1" 1>&2
63 if [ ! -s "$ign2" ]; then
64 echo "$0: host2 ignore file not found or empty: $ign2" 1>&2
73 trap 'rm -f ${LOCK}; exit 1' 0 1 2 3 15
74 shlock -p $$ -f ${LOCK} || {
75 echo "$0: Locked by `cat ${LOCK}`" 1>&2
81 tmp="$TMPDIR/.merge$$"
82 act1="$TMPDIR/.act1$$"
83 act2="$TMPDIR/.act2$$"
84 trap "rm -f $tmp ${LOCK} $act1 $act2; exit" 0 1 2 3 15
95 # try to fetch the first active file
97 echo "=-= fetching $host1" >>$tmp
98 eval "$ACTSYNC -i $ign1 $FETCH /dev/null $host1 > $act1 2>>$tmp"
100 if [ "$status" -ne 0 ]; then
102 # We failed on our first try, so we will trice knock 3 times after
105 for loop in 1 2 3; do
111 eval "$ACTSYNC -i $ign1 $FETCH /dev/null $host1 > $act1 2>>$tmp"
113 if [ "$status" -eq "$NOSYNC" ]; then
118 eval "$ACTSYNC -i $ign1 $FETCH /dev/null $host1 > $act1 2>>$tmp"
120 if [ "$status" -eq "$NOSYNC" ]; then
125 eval "$ACTSYNC -i $ign1 $FETCH /dev/null $host1 > $act1 2>>$tmp"
127 if [ "$status" -eq "$NOSYNC" ]; then
134 if [ "$status" -ne 0 ]; then
135 echo "=-= `date` merge $host1 $host2 exit $status" 1>&2
136 sed -e 's/^/ /' < "$tmp" 1>&2
140 if [ ! -s "$act1" ]; then
141 echo "$0: host1 active file not found or empty: $act1" 1>&2
145 # try to fetch the second active file
147 echo "=-= fetching $host2" >>$tmp
148 eval "$ACTSYNC -i $ign2 $FETCH /dev/null $host2 > $act2 2>>$tmp"
150 if [ "$status" -ne 0 ]; then
152 # We failed on our first try, so we will trice knock 3 times after
155 for loop in 1 2 3; do
161 eval "$ACTSYNC -i $ign2 $FETCH /dev/null $host2 > $act2 2>>$tmp"
163 if [ "$status" -eq "$NOSYNC" ]; then
168 eval "$ACTSYNC -i $ign2 $FETCH /dev/null $host2 > $act2 2>>$tmp"
170 if [ "$status" -eq "$NOSYNC" ]; then
175 eval "$ACTSYNC -i $ign2 $FETCH /dev/null $host2 > $act2 2>>$tmp"
177 if [ "$status" -eq "$NOSYNC" ]; then
184 if [ "$status" -ne 0 ]; then
185 echo "=-= `date` merge $host1 $host2 exit $status" 1>&2
186 sed -e 's/^/ /' < "$tmp" 1>&2
190 if [ ! -s "$act2" ]; then
191 echo "$0: host2 active file not found or empty: $act2" 1>&2
195 # merge the 2 active files to stdout
197 echo "=-= merging $host1 and $host2" >>$tmp
198 eval "$ACTSYNC $MERGE $act1 $act2" 2>>$tmp
200 if [ "$status" -ne 0 ]; then
201 echo "=-= `date` merge $host1 $host2 exit $status" 1>&2
202 sed -e 's/^/ /' < "$tmp" 1>&2
206 # if not -q, send status to stderr
208 if [ -z "$QUIET" ]; then
209 echo "=-= `date` merge $host1 $host2 successful" 1>&2
210 sed -e 's/^/ /' < "$tmp" 1>&2