forked from BladeGroup/gitlab-oe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrsync-sstate
executable file
·86 lines (69 loc) · 1.76 KB
/
rsync-sstate
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
85
86
#!/bin/bash
set -e
die()
{
echo >&2 "ERROR: $*"
exit 1
}
usage()
{
cat <<EOF
Usage: $(basename $0) [options] ../sstates/"
Options:
--prune remove local shared-state files not on server (rsync --delete)
--gen <sstate-gen> sstate generation to fetch (default '$GEN')
--repo <rsync-path> source sstates repository
--help guess what
EOF
}
die_usage()
{
echo >&2 "ERROR: $*"
usage
exit 1
}
GITTOP=$(git rev-parse --show-toplevel)
[ -r "$GITTOP" ] || die "failed to locate git toplevel, cannot read '$GITTOP'"
[ -r "$GITTOP/.gitlab-ci.yml" ] || die "failed to locate git toplevel, cannot read '$GITTOP/.gitlab-ci.yml'"
# defaults before config and cli parsing
EXTRAFLAGS=()
GEN=$(grep BUILD_GEN .gitlab-ci.yml | sed 's/ *BUILD_GEN: *"\(.*\)"/\1/')
# config file
for conffile in "$GITTOP/.gitlab-oe.conf" ~/.gitlab-oe.conf; do
[ -r "$conffile" ] || continue
. "$conffile"
break # only use the first existing config
done
# comand line
while [ $# -gt 0 ]; do
case "$1" in
--gen) GEN="$2"; shift ;;
--prune) EXTRAFLAGS+=(--delete) ;;
--repo) REPO="$2"; shift ;;
--help) usage; exit 0 ;;
*) break ;;
esac
shift
done
[ $# = 1 ] || die_usage "exactly one argument expected"
DEST="$1"
[ -n "$GEN" ] || die "cannot determine sstate generation"
# core
SSTATE="${REPO}/sstate-cache-${GEN}"
BASEGEN=${GEN}
SSTATES="$SSTATE"
while true; do
case "$BASEGEN" in
*+*)
BASEGEN=${BASEGEN%+*}
BASESSTATE="${REPO}/sstate-cache-${BASEGEN}"
SSTATES="$BASESSTATE $SSTATES"
;;
*)
break
;;
esac
done
rsync --rsh "ssh -p 1023" -aHv \
"${EXTRAFLAGS[@]}" \
$SSTATES "$DEST"