-
Notifications
You must be signed in to change notification settings - Fork 5
/
downstream.sh
executable file
·146 lines (136 loc) · 4.24 KB
/
downstream.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
# Copyright (c) 2020 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Written by Mikolaj Izdebski <mizdebsk@redhat.com>
set -eu
export LC_ALL='C.UTF-8'
git="git -c user.name=root -c user.email=root@localhost"
if [[ $# -eq 0 ]]; then
echo "$0: command must be specified as first argument" >&2
exit 1
fi
cmd="$1"
shift
if [[ $# -eq 0 ]]; then
set project/*.properties
set ${@/#project\/}
set ${@/%.properties}
fi
function sub_version()
{
eval local var=$1 val=\$$1
set ${version/\~/ }
case $val in *@@*) val=${val//@@/$2};; esac
set ${1//\./ }
set $@ $@
while :; do
case $val in *@*) val=${val/@/$1}; shift;; *) break;; esac
done
eval $var=$val
}
function clone()
{
if [[ "$type" = git ]]; then
if [[ -d "upstream/$p.git" ]]; then
$git -C "upstream/$p.git" remote set-url origin "$url"
$git -C "upstream/$p.git" fetch
else
$git clone --mirror "$url" "upstream/$p.git"
fi
elif [[ "$type" = zip ]]; then
curl -f -o "upstream/$p-$version.zip" "$url"
else
echo "$0: $p: unsupported upstream type: $type" >&2
exit 1
fi
}
function prep()
{
rm -rf "downstream/$p"
if [[ "$type" = git ]]; then
$git clone -n "upstream/$p.git" "downstream/$p"
$git -C "downstream/$p" checkout -b upstream-base "$ref"
elif [[ "$type" = zip ]]; then
$git init "downstream/$p"
unzip "upstream/$p-$version.zip" -d "downstream/$p"
dir="downstream/$p"/$(ls "downstream/$p")
if [[ -d "$dir" ]]; then
mv "$dir"/* "downstream/$p"
rmdir "$dir"
fi
$git -C "downstream/$p" add .
$git -C "downstream/$p" commit -m "Import version $version"
$git -C "downstream/$p" checkout -b upstream-base
else
echo "$0: $p: unsupported upstream type: $type" >&2
exit 1
fi
find "downstream/$p" -type f -regextype posix-egrep -regex '.*\.(class|jar|bar|war|ear|zip|gz|7z|bz2|ttf|so|dll|o|exe|dylib|jnilib)$' -delete
if [[ "$p" == bnd ]]; then
rm -r downstream/bnd/docs/
elif [[ "$p" == easymock ]]; then
rm -r downstream/easymock/website/js/vendor/
elif [[ "$p" == qdox ]]; then
rm -r downstream/qdox/bootstrap/
elif [[ "$p" == mockito ]]; then
rm -r downstream/mockito/src/javadoc/
elif [[ "$p" == jansi ]]; then
rm -r downstream/jansi/src/main/native/
elif [[ "$p" == jflex ]]; then
rm -r downstream/jflex/jflex/examples/
fi
$git -C "downstream/$p" commit --allow-empty -a -m 'Remove binary files'
$git -C "downstream/$p" checkout -b downstream upstream-base
if [[ -d patches/$p ]]; then
set patches/$p/*.patch
set ${@//patches/../../patches}
$git -C "downstream/$p" am --ignore-whitespace $@
fi
}
for p; do
if [[ ! -f project/$p.properties ]]; then
echo "$0: $p: upstream descriptor not found" >&2
exit 1
fi
unset url
unset ref
unset version
type=git
. project/$p.properties
sub_version ref
sub_version url
echo
echo =============================================
echo project: $p
echo version: $version
echo url: $url
echo ref: $ref
echo =============================================
if [[ "$cmd" = clone ]]; then
clone
elif [[ "$cmd" = prep ]]; then
prep
elif [[ "$cmd" = archive ]]; then
mkdir -p archive
rm -f archive/$p.tar archive/$p.tar.xz
$git -C "downstream/$p" archive --prefix downstream/$p/ upstream-base >archive/$p.tar
else
echo "$0: unknown command: $cmd" >&2
exit 1
fi
done
if [[ $cmd = archive ]]; then
echo archive/*.tar | xargs -n1 -P20 xz -9evT8
fi