chiark / gitweb /
ubuntu-daily: flip -a semantics to mean --authenticated, not --anonymous
[bin.git] / 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" 2>/dev/null || cat "$1"); do
16         IFS="$IFS_SAVE"
17         set -- $line
18         DIR="$1"
19         VERSION="$2"
20
21         echo "Updating $DIR ($VERSION) ..."
22
23         case $VERSION in
24                 bzr+ssh://*|http://*|sftp://*)
25                         if [ -d "$DIR" ]; then
26                                 if [ ! -d "$DIR/.bzr" ]; then
27                                         echo "$DIR is not a bzr checkout; cannot update" >&2
28                                         continue
29                                 elif [ -f "$DIR/.bzr/branch/bound" ]; then
30                                         bzr update "$DIR"
31                                 else
32                                         (cd "$DIR" && bzr pull "$VERSION")
33                                 fi
34                         else
35                                 case $VERSION in
36                                         bzr+ssh://*|sftp://*)
37                                                 bzr checkout "$VERSION" "$DIR"
38                                                 ;;
39                                         *)
40                                                 bzr get "$VERSION" "$DIR"
41                                                 ;;
42                                 esac
43                         fi
44                         ;;
45                 git://*|git+*://*)
46                         if [ -d "$DIR" ]; then
47                                 if [ ! -d "$DIR/.git" ]; then
48                                         echo "$DIR is not a git checkout; cannot update" >&2
49                                         continue
50                                 fi
51                                 (cd "$DIR" && git pull "$VERSION")
52                         else
53                                 git clone "$VERSION" "$DIR"
54                         fi
55                         ;;
56                 *)
57                         if [ -d "$DIR" ]; then
58                                 if [ ! -d "$DIR/{arch}" ]; then
59                                         echo "$DIR is not an arch checkout; cannot update" >&2
60                                         continue
61                                 fi
62                                 OLDVERSION="$(baz tree-version -d "$DIR")"
63                                 if [ "$VERSION" != "$OLDVERSION" ]; then
64                                         baz switch -d "$DIR" "$VERSION"
65                                 else
66                                         baz update -d "$DIR" "$VERSION"
67                                 fi
68                         else
69                                 baz get "$VERSION" "$DIR"
70                         fi
71                         ;;
72         esac
73 done