monotone

monotone Mtn Source Tree

Root/contrib/monotone-mirror.sh

  • Property mtn:execute set to true
1#! /bin/sh
2#
3# Reads a simple specification with lines describing what to do.
4# The lines may be several of the following:
5#
6#keyKEYDIR KEYID
7#
8#mirrorSERVER[OPTIONS ...] PATTERN ...
9#
10#postactionCOMMAND
11#
12# All "mirror" lines describe what to pull from what servers. Everything
13# ends up in one database.
14#
15# All "postaction" lines describe a command to be evaluated after mirroring
16# is done. When each command is evaluated, the environment variable DATABASE
17# contains the name of the database for them to use.
18#
19# All "mirror" lines are executed first, then all "postaction" lines.
20# "key" lines are always executed in place, and affect any subsequent "mirror"
21# or "postaction" line.
22#
23# $1database to use. Must be initialised beforehand or this will fail!
24#Default: /var/lib/monotone/mirror/mirror.mtn
25# $2specification file name.
26#Default: /etc/monotone/mirror.rc
27
28set -e
29
30database=$1
31if [ -z "$database" ]; then
32 database=/var/lib/monotone/mirror/mirror.mtn
33fi
34
35if [ -f "$database" ]; then :; else
36 echo "The database $database doesn't exist" >&2
37 echo "You have to initialise it yourself, like this:" >&2
38 echo "mtn db init -d $database" >&2
39 exit 1
40fi
41
42rc=$2
43if [ -z "$rc" ]; then
44 rc=/etc/monotone/mirror.rc
45fi
46
47if [ -f "$rc" ]; then :; else
48 echo "The specification file $rc doesn't exist" >&2
49 exit 1
50fi
51
52# Make sure the path to the database is absolute
53databasedir=`dirname $database`
54databasefile=`basename $database`
55databasedir=`cd $databasedir; pwd`
56database="$databasedir/$databasefile"
57
58mkdir -p $database.redo
59mkdir $database.lock1 || \
60 (echo 'Database locked by another process'; exit 1) && \
61 (
62 touch $database.keyvars
63 while [ -d $database.redo ]; do
64rmdir $database.redo
65sed -e '/^#/d' < "$rc" | while read KEYWORD ARGS; do
66 case $KEYWORD in
67key)
68 set $ARGS
69 keydir=$1
70 keyid=$2
71 keydiropt=""
72 keyidopt=""
73 if [ -n "$keydir" ]; then keydiropt="--keydir='$keydir'"; fi
74 if [ -n "$keyid" ]; then keyidopt="--key='$keyid'"; fi
75 (
76echo "keydiropt=\"$keydiropt\""
77echo "keyidopt=\"$keyidopt\""
78 ) > $database.keyvars
79 ;;
80mirror)
81 echo "$ARGS" | while read SERVER PATTERNS; do
82if [ -z "$SERVER" -o -z "$PATTERNS" ]; then
83 echo "Server or pattern missing in line: $SERVER $PATTERNS" >&2
84 echo "Skipping..." >&2
85else
86 (
87. $database.keyvars
88eval "set -x; mtn -d '$database' '$keydiropt' '$keyidopt' --ticker=dot pull $SERVER $PATTERNS"
89 )
90fi
91 done
92 esac
93done
94
95sed -e '/^#/d' < "$rc" | while read KEYWORD ARGS; do
96 case $KEYWORD in
97key)
98 set $ARGS
99 keydir=$1
100 keyid=$2
101 keydiropt=""
102 keyidopt=""
103 if [ -n "$keydir" ]; then keydiropt="--keydir='$keydir'"; fi
104 if [ -n "$keyid" ]; then keyidopt="--key='$keyid'"; fi
105 (
106echo "keydiropt=\"$keydiropt\""
107echo "keyidopt=\"$keyidopt\""
108 ) > $database.keyvars
109 ;;
110postaction)
111 if [ -z "$ARGS" ]; then
112echo "Command missing in line: $ARGS" >&2
113echo "Skipping..." >&2
114 else
115(
116 . $database.keyvars
117 DATABASE="$database" \
118KEYDIROPT="$keydiropt" KEYIDOPT="$keyidopt" \
119eval "set -x; $ARGS"
120)
121 fi
122 esac
123done
124 done
125
126 rmdir $database.lock1
127 rm $database.keyvars
128 )

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status