# # # add_file "contrib/monotone-mirror-postaction-update.sh" # content [ef56317b5f2fee18598e4105a670e5b5a463fde7] # # add_file "contrib/monotone-mirror.sh" # content [1047394294627625df2a9f940ff5f463ad26e425] # # patch "ChangeLog" # from [aaec1c0854f450a2eeee418a0048b36531db2b12] # to [c2ff09ff01cd71d2b7d0b8a5a75833a273bb4708] # # patch "contrib/README" # from [03b97be886f1ea1dce0689113b1364406a87c9ad] # to [58cb523ad71039ff8f4affd7da9e365cfbd82c11] # # set "contrib/monotone-mirror-postaction-update.sh" # attr "mtn:execute" # value "true" # # set "contrib/monotone-mirror.sh" # attr "mtn:execute" # value "true" # ============================================================ --- contrib/monotone-mirror-postaction-update.sh ef56317b5f2fee18598e4105a670e5b5a463fde7 +++ contrib/monotone-mirror-postaction-update.sh ef56317b5f2fee18598e4105a670e5b5a463fde7 @@ -0,0 +1,70 @@ +#! /bin/sh +# +# Reads a simple specification in the following form: +# +# DIRECTORY BRANCH +# +# and updates each directory with the data from said branch. +# +# This script relies on the environment DATABASE to point out what database +# to use as source. +# +# $1 specification file name. +# Default: /etc/monotone/update.rc + +if [ -z "$DATABASE" ]; then + echo "No database was given through the DATABASE environment variable" >&2 + exit 1 +fi + +if [ -f "$DATABASE" ]; then :; else + echo "The database $DATABASE doesn't exist" >&2 + echo "You have to initialise it yourself, like this:" >&2 + echo " mtn db init -d $database" >&2 + exit 1 +fi + +rc=$1 +if [ -z "$rc" ]; then + rc=/etc/monotone/update.rc +fi + +if [ -f "$rc" ]; then :; else + echo "The specification file $rc doesn't exist" >&2 + exit 1 +fi + +# Make sure the path to the database is absolute +databasedir=`dirname $DATABASE` +databasefile=`basename $DATABASE` +databasedir=`cd $databasedir; pwd` +database="$databasedir/$databasefile" + +cat "$rc" | while read DIRECTORY BRANCH; do + if [ -n "$DIRECTORY" -o -n "$BRANCH" ]; then + if [ -z "$DIRECTORY" -o -z "$BRANCH" ]; then + echo "Directory or branch missing in line: $DIRECTORY $BRANCH" >&2 + echo "Skipping..." >&2 + elif [ -d "$DIRECTORY" ]; then + ( + cd $DIRECTORY + thisbranch= + if [ -f _MTN/options ]; then + thisbranch=`grep '^ *branch ' _MTN/options | sed -e 's/^ *branch *"//' -e 's/" *$//'` + fi + if [ "$thisbranch" = "$BRANCH" ]; then + mtn update + else + echo "The directory $DIRECTORY doesn't contain the branch $BRANCH" >&2 + echo "Skipping..." >&2 + fi + ) + elif [ -e "$DIRECTORY" ]; then + echo "There is a file $DIRECTORY, but it's not a directory" >&2 + echo "Skipping..." >&2 + else + echo "Extracting branch $BRANCH into directory $DIRECTORY" >&2 + mtn -d "$database" -b "$BRANCH" co "$DIRECTORY" + fi + fi +done ============================================================ --- contrib/monotone-mirror.sh 1047394294627625df2a9f940ff5f463ad26e425 +++ contrib/monotone-mirror.sh 1047394294627625df2a9f940ff5f463ad26e425 @@ -0,0 +1,80 @@ +#! /bin/sh +# +# Reads a simple specification with lines describing what to do. +# The lines may be several of the following: +# +# mirror SERVER [OPTIONS ...] PATTERN ... +# +# postaction COMMAND +# +# All "mirror" lines describe what to pull from what servers. Everything +# ends up in one database. +# +# All "postaction" lines describe a command to be evaluated after mirroring +# is done. When each command is evaluated, the environment variable DATABASE +# contains the name of the database for them to use. +# +# All "mirror" lines are executed first, then all "postaction" lines. +# +# $1 database to use. Must be initialised beforehand or this will fail! +# Default: /var/lib/monotone/mirror/mirror.mtn +# $2 specification file name. +# Default: /etc/monotone/mirror.rc + +set -e + +database=$1 +if [ -z "$database" ]; then + database=/var/lib/monotone/mirror/mirror.mtn +fi + +if [ -f "$database" ]; then :; else + echo "The database $database doesn't exist" >&2 + echo "You have to initialise it yourself, like this:" >&2 + echo " mtn db init -d $database" >&2 + exit 1 +fi + +rc=$2 +if [ -z "$rc" ]; then + rc=/etc/monotone/mirror.rc +fi + +if [ -f "$rc" ]; then :; else + echo "The specification file $rc doesn't exist" >&2 + exit 1 +fi + +# Make sure the path to the database is absolute +databasedir=`dirname $database` +databasefile=`basename $database` +databasedir=`cd $databasedir; pwd` +database="$databasedir/$databasefile" + +mkdir $database.lock1 || \ + (echo 'Database locked by another process'; exit 1) && \ + ( + cat "$rc" | while read KEYWORD SERVER PATTERNS; do + if [ "$KEYWORD" = "mirror" ]; then + if [ -z "$SERVER" -o -z "$PATTERNS" ]; then + echo "Server or pattern missing in line: $SERVER $PATTERNS" >&2 + echo "Skipping..." >&2 + else + ( eval "set -x; mtn -d '$database' --ticker=dot pull $SERVER $PATTERNS" ) + fi + fi + done + + cat "$rc" | while read KEYWORD COMMAND; do + if [ "$KEYWORD" = "postaction" ]; then + if [ -z "$COMMAND" ]; then + echo "Command missing in line: $COMMAND" >&2 + echo "Skipping..." >&2 + else + ( DATABASE="$database" eval "set -x; $COMMAND" ) + fi + fi + done + + rmdir $database.lock1 +) ============================================================ --- ChangeLog aaec1c0854f450a2eeee418a0048b36531db2b12 +++ ChangeLog c2ff09ff01cd71d2b7d0b8a5a75833a273bb4708 @@ -1,3 +1,10 @@ +2006-12-28 Richard Levitte + + * contrib/monotone-mirror.sh: Mirroring script. + * contrib/monotone-mirror-postaction-update.sh: Postaction script + that goes with contrib/monotone-mirror.sh. + * contrib/README: Describe them. + 2006-12-28 Derek Scherger * tests/checkout_clobbers_workspace/__driver__.lua: new test to ============================================================ --- contrib/README 03b97be886f1ea1dce0689113b1364406a87c9ad +++ contrib/README 58cb523ad71039ff8f4affd7da9e365cfbd82c11 @@ -41,3 +41,11 @@ licenses. a directory pointed at by $MTN_LUAHOOKSDIR. Hooks are commonly added using the function add_hook(). There is simple documentation at the top of ext_hooks.lua.in. + + -- monotone-mirror.sh: script to mirror another (remote) database and to + perform actions after mirroring, all according to a specification file. + monotone-mirror-postaction-update.sh: a post action script that updates + directories after a database has been mirrored according to a + specification file. + Both files has comments in the beginning, explaining how the specification + files should be written.