-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdownstream.sh
More file actions
executable file
·204 lines (188 loc) · 5.93 KB
/
downstream.sh
File metadata and controls
executable file
·204 lines (188 loc) · 5.93 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/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"
commit=$($git -C "downstream/$p" rev-parse upstream-base)
date=$($git -C "downstream/$p" cat-file commit $commit | sed -n '/^author /s/.* \([0-9][0-9]* [+-][0-9][0-9]*$\)/\1/;T;p;q')
elif [[ "$type" = zip ]]; then
date="100000000 +0000"
$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 --date "$date" -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 --date "$date" --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
}
function archive()
{
mkdir -p archive
rm -f archive/$p.tar archive/$p.tar.zst
commit=$($git -C "downstream/$p" rev-parse upstream-base)
date=$($git -C "downstream/$p" cat-file commit $commit | sed -n '/^author /s/.* \([0-9][0-9]* [+-][0-9][0-9]*$\)/\1/;T;p;q')
tree=$($git -C "downstream/$p" cat-file commit $commit | sed -n 's/^tree //;T;p;q')
$git -C "downstream/$p" archive --prefix downstream/$p/ --mtime "$date" "$tree" >archive/$p.tar
zstd --rm -T8 -12 archive/$p.tar
}
function save_patches()
{
rm -rf patches/$p
mkdir patches/$p
git -C downstream/$p format-patch -o ../../patches/$p upstream-base
rmdir patches/$p 2>/dev/null || :
}
function bundled_provides()
{
echo "bundled(${rpm_name:-$p}) = ${rpm_version}"
}
function source_list()
{
echo "Source: $p.tar.zst"
}
function source_manifest()
{
(cd ./archive && sha512sum --tag $p.tar.zst)
}
function prep_from_archive()
{
echo === $p >&2
rm -rf downstream/$p
tar -xf archive/$p.tar.zst
if [[ -d patches/$p ]]; then
for patch in patches/$p/*; do
(cd ./downstream/$p && patch -l -p1) <$patch
done
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
unset rpm_name
type=git
. project/$p.properties
sub_version ref
sub_version url
rpm_version=${version//-/.}
if [[ "$cmd" = clone ]] || [[ "$cmd" = prep ]]; then
echo >&2
echo "=============================================" >&2
echo "project: $p" >&2
echo "version: $version" >&2
echo "url: $url" >&2
echo "ref: $ref" >&2
echo "=============================================" >&2
fi
if [[ "$cmd" = clone ]]; then
clone
elif [[ "$cmd" = prep ]]; then
prep
elif [[ "$cmd" = archive ]]; then
archive
elif [[ "$cmd" = save-patches ]]; then
save_patches
elif [[ "$cmd" = bundled-provides ]]; then
bundled_provides
elif [[ "$cmd" = source-list ]]; then
source_list
elif [[ "$cmd" = source-manifest ]]; then
source_manifest
elif [[ "$cmd" = prep-from-archive ]]; then
prep_from_archive
else
echo "$0: unknown command: $cmd" >&2
exit 1
fi
done