aboutsummaryrefslogtreecommitdiff
path: root/bundles/create-bundle
blob: 67055bb1a01bc666243b3b814fa829539fae6d19 (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
#!/bin/bash
# Copyright (C) 2013 Linaro
#
# This is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Linaro Image Tools.  If not, see <http://www.gnu.org/licenses/>.

# BASE: Top-level base of git repo tree, for convenience
BASE=/srv/repositories
# SUBTREES: We allow to create bundles only for repos in specific subtree(s),
# just list them space-saparated in SUBTREES below. For example, to add
# `/srv/repositories/foo/bar', just add `$BASE/foo/bar':
# SUBTREE="$BASE/lava $BASE/foo/bar"
# EXCLUDE: grep pattern of repository paths to exclude
EXCLUDE=""
# BRANCHES: Which branches to put into bundle. If you want to use
# wildcards, these must be full refs paths (e.g. refs/heads/*)
BRANCHES="master"

HOSTTYPE=$(cat /etc/linaro/hosttype)
if [ "$HOSTTYPE" = "git-main" ]; then
    SUBTREES="$BASE/lava $BASE/tools"
elif [ "$HOSTTYPE" = "git-android" ]; then
    SUBTREES="$BASE"
    EXCLUDE="repo\.git"
    BRANCHES="refs/heads/master refs/heads/linaro*"
else
    echo "Unknown hosttype. Make sure /etc/linaro/hosttype is set up."
    exit 1
fi

if [ $(id -u -n) = "root" ]; then
    echo "This script must not be run as 'root' user"
    exit 1
fi

DRYRUN=0
if [ "$1" == "--dry-run" ]; then
    DRYRUN=1
fi

function create_bundle() {
    if echo "$BRANCHES" | grep -q '\*'; then
        BRANCHES=$(ls $BRANCHES 2>/dev/null)
    fi

    git bundle create clone.bundle.tmp $BRANCHES || echo "Error creating bundle for $PWD"
    mv clone.bundle.tmp clone.bundle
}

for repo_path in $SUBTREES
do
    for repository in $(find -H $repo_path -type d -name "*.git" -prune)
    do
        if [ -n "$EXCLUDE" ] && echo $repository | grep -q $EXCLUDE; then
            echo Skipping $repository
            continue
        fi
        if [ $DRYRUN -eq 1 ]; then
            echo $repository
        else
            (cd $repository; create_bundle)
        fi
    done
done