chiark / gitweb /
superseded by moreutils
[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" 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                                 fi
30                                 (cd "$DIR" && bzr pull "$VERSION")
31                         else
32                                 bzr get "$VERSION" "$DIR"
33                         fi
34                         ;;
35                 *)
36                         if [ -d "$DIR" ]; then
37                                 if [ ! -d "$DIR/{arch}" ]; then
38                                         echo "$DIR is not an arch checkout; cannot update" >&2
39                                         continue
40                                 fi
41                                 OLDVERSION="$(baz tree-version -d "$DIR")"
42                                 if [ "$VERSION" != "$OLDVERSION" ]; then
43                                         baz switch -d "$DIR" "$VERSION"
44                                 else
45                                         baz update -d "$DIR" "$VERSION"
46                                 fi
47                         else
48                                 baz get "$VERSION" "$DIR"
49                         fi
50                         ;;
51         esac
52 done