chiark / gitweb /
support bzr
[bin.git] / baz-update-config
1 #! /bin/sh
2 set -e
3
4 CONFIG="$1"
5 if [ -z "$CONFIG" ]; then
6         echo "Usage: $0 CONFIG" >&2
7         exit 1
8 fi
9
10 NEWLINE='
11 '
12
13 IFS_SAVE="$IFS"
14 IFS="$NEWLINE"
15 for line in $(baz cat-config "$1"); do
16         IFS="$IFS_SAVE"
17         set -- $line
18         DIR="$1"
19         VERSION="$2"
20
21         case $VERSION in
22                 http://*)
23                         if [ -d "$DIR" ]; then
24                                 if [ ! -d "$DIR/.bzr" ]; then
25                                         echo "$DIR is not a bzr checkout; cannot update" >&2
26                                         continue
27                                 fi
28                                 (cd "$DIR" && bzr pull "$VERSION")
29                         else
30                                 bzr get "$VERSION" "$DIR"
31                         fi
32                         ;;
33                 *)
34                         if [ -d "$DIR" ]; then
35                                 if [ ! -d "$DIR/{arch}" ]; then
36                                         echo "$DIR is not an arch checkout; cannot update" >&2
37                                         continue
38                                 fi
39                                 OLDVERSION="$(baz tree-version -d "$DIR")"
40                                 if [ "$VERSION" != "$OLDVERSION" ]; then
41                                         baz switch -d "$DIR" "$VERSION"
42                                 else
43                                         baz update -d "$DIR" "$VERSION"
44                                 fi
45                         else
46                                 baz get "$VERSION" "$DIR"
47                         fi
48                         ;;
49         esac
50 done