summaryrefslogtreecommitdiff
path: root/rep-update
blob: e66baf517751ec44974f07e2ec26b2e87a1c97c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#! /usr/bin/env bash

# Update (or create) bpkg packages.manifest files in repository.
#
# Usage: update [-t <toolchain>] [-e <subdir>] <dir> [<bpkg-options>]
#
# This script runs the rep-create command for every first-level subdirectory
# of <dir> that doesn't start with '.' and contains the repositories.manifest
# file, unless <dir> itself contains repositories.manifest.
#
# -e <subdir>
#    Exclude the specified sub-directory. Currently only one directory can
#    be excluded.
#
# -t <toolchain>
#    Specify the build2 toolchain install/stage directory. The script will
#    use <toolchain>/bin/bpkd instead of just bpkg.
#

trap 'exit 1' ERR
set -o errtrace # Trap in functions.

function info () { echo "$*" 1>&2; }
function error () { info "$*"; exit 1; }

dir=
toolchain=
exclude=

while [ $# -gt 0 ]; do
  case $1 in
    -e)
      shift
      exclude=${1%/}
      shift
      ;;
    -t)
      shift
      toolchain=${1%/}
      shift
      ;;
    *)
      dir=${1%/}
      shift
      break
      ;;
  esac
done

if [ -z "$dir" ]; then
  error "usage: $0 [-t <toolchain>] <dir> [<bpkg-options>]"
fi

if [ -z "$toolchain" ]; then
  bpkg="bpkg"
else
  bpkg="$toolchain/bin/bpkg"
  if [ ! -x $bpkg ]; then
    error "$bpkg does not exist or is not executable"
  fi
fi

if [ -f "$dir/repositories.manifest" ]; then
  sub=$dir
else
  sub=`find $dir -mindepth 1 -maxdepth 1 -type d -name '[^.]*'`

  if [ -z "$sub" ]; then
    error "no repositories.manifest file or subdirectories in $dir/"
  fi
fi

for d in $sub; do
  if [ `basename $d` = "$exclude" ]; then
    echo "skipping excluded $d/" 1>&2
    continue
  fi

  if [ -f "$d/repositories.manifest" ]; then
    $bpkg rep-create "$@" $d
  else
    echo "no repositories.manifest file in $d/, skipping" 1>&2
  fi
done