monotone

monotone Mtn Source Tree

Root/contrib/monotone-mirror-postaction-update.sh

  • Property mtn:execute set to true
1#! /bin/sh
2#
3# Reads a simple specification in the following form:
4#
5#DIRECTORYBRANCH
6#
7# and updates each directory with the data from said branch.
8#
9# This script relies on the following environment variables:
10#
11#DATABASEpoints out what database to use as source.
12#KEYDIROPThas the form '--keydir=<KEYDIRECTORY>' it the top
13#mirror script has a keydir setting.
14#KEYIDOPThas the form '--key=<KEYID>' it the top mirror
15#script has a keyid setting.
16#
17# $1specification file name.
18#Default: /etc/monotone/update.rc
19
20if [ -z "$DATABASE" ]; then
21 echo "No database was given through the DATABASE environment variable" >&2
22 exit 1
23fi
24
25if [ -f "$DATABASE" ]; then :; else
26 echo "The database $DATABASE doesn't exist" >&2
27 echo "You have to initialise it yourself, like this:" >&2
28 echo "mtn db init -d $database" >&2
29 exit 1
30fi
31
32rc=$1
33if [ -z "$rc" ]; then
34 rc=/etc/monotone/update.rc
35fi
36
37if [ -f "$rc" ]; then :; else
38 echo "The specification file $rc doesn't exist" >&2
39 exit 1
40fi
41
42# Make sure the path to the database is absolute
43databasedir=`dirname $DATABASE`
44databasefile=`basename $DATABASE`
45databasedir=`cd $databasedir; pwd`
46database="$databasedir/$databasefile"
47
48sed -e '/^#/d' < "$rc" | while read DIRECTORY BRANCH; do
49 if [ -n "$DIRECTORY" -o -n "$BRANCH" ]; then
50if [ -z "$DIRECTORY" -o -z "$BRANCH" ]; then
51 echo "Directory or branch missing in line: $DIRECTORY $BRANCH" >&2
52 echo "Skipping..." >&2
53elif [ -d "$DIRECTORY" ]; then
54 (
55if [ -d $DIRECTORY/_MTN ]; then
56 thisbranch=
57 if [ -f $DIRECTORY/_MTN/options ]; then
58thisbranch=`grep '^ *branch ' $DIRECTORY/_MTN/options | sed -e 's/^ *branch *"//' -e 's/" *$//'`
59 fi
60 if [ "$thisbranch" = "$BRANCH" ]; then
61echo "Updating the directory $DIRECTORY" >&2
62( cd $DIRECTORY; mtn update )
63 else
64echo "The directory $DIRECTORY doesn't contain the branch $BRANCH" >&2
65echo "Skipping..." >&2
66 fi
67else
68 filesn=`ls -1 -a $DIRECTORY | egrep -v '^\.\.?$' | wc -l`
69 if [ "$filesn" -eq 0 ]; then
70echo "Extracting branch $BRANCH into empty directory $DIRECTORY" >&2
71( cd $DIRECTORY; mtn -d "$database" -b "$BRANCH" co . )
72 else
73
74echo "The directory $DIRECTORY doesn't contain the branch $BRANCH" >&2
75echo "Skipping..." >&2
76 fi
77fi
78 )
79elif [ -e "$DIRECTORY" ]; then
80 echo "There is a file $DIRECTORY, but it's not a directory" >&2
81 echo "Skipping..." >&2
82else
83 echo "Extracting branch $BRANCH into directory $DIRECTORY" >&2
84 mtn -d "$database" -b "$BRANCH" co "$DIRECTORY"
85fi
86 fi
87done

Archive Download this file

Branches

Tags

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