forked from sclorg/container-common-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-generated.sh
executable file
·71 lines (54 loc) · 1.32 KB
/
update-generated.sh
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
#!/bin/bash
set -ex
shopt -s extglob
COMMIT=$(git rev-parse HEAD)
# import generated content from this git reference ..
SOURCE_BRANCH=${1:-$COMMIT}
# into this git branch
GENERATED_BRANCH=${2:-generated}
git clean -f -d
# switch to generated branch for working env; and switch back later
git checkout "$GENERATED_BRANCH"
git submodule update
# Clean everything in generated branch.
rm -rf -- *
srcdir=srcdir
cleanup ()
{
exit_status=$?
rm -rf "$srcdir"
# switch back to initial ranch
git checkout "$SOURCE_BRANCH"
git submodule update
return $exit_status
}
trap cleanup EXIT
(
# Copy the actual repo into $srcdir, and generate there
mkdir "$srcdir"
cd "$srcdir"
git clone .. .
git checkout "$SOURCE_BRANCH"
git submodule update --init
make generate-all
)
# copy the relevant (generated) content from $srcdir
versions=$(sed -n 's/^VERSIONS[[:space:]]*=//p' "$srcdir"/Makefile)
for i in $versions; do
cp -r "$srcdir/$i" .
done
# source directory is not needed anymore
rm -rf "$srcdir"
git add $versions
# Add deleted files to the index as well
(
IFS=$'\n'
for i in $(git ls-files --deleted) ;do
git add --all "$i"
done
)
if ! git diff --cached --exit-code --quiet ; then
git commit -m "auto-sync: master commit $COMMIT"
else
echo "Nothing changed"
fi