-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate-version.sh
executable file
·194 lines (172 loc) · 7.09 KB
/
update-version.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
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
#!/bin/bash
set -eo pipefail
script_args=()
force=false
private_mirror=false
while [ $OPTIND -le "$#" ]
do
if getopts fp option
then
case $option
in
f) force=true;;
p) private_mirror=true;;
esac
else
script_args+=("${!OPTIND}")
((OPTIND++))
fi
done
if ((${#script_args[@]} < 1)); then
echo "Usage: $0 [-f] [-p] BETTERBIRD_VERSION [BETTERBIRD_COMMIT]"
echo ""
echo "Example: $0 102.2.2-bb16"
echo " $0 102 4d587481bc7dbca1ffc99cce319f84425fab7852"
echo ""
echo "Options:"
echo " -f : Skip the check that the version given as script input and the version specified in the appdata.xml agree."
echo " -p : Replace upstream mirror of source tar.xz by private mirror."
exit 1
fi
BETTERBIRD_VERSION="${script_args[0]}" # Betterbird version. Can either be a tag or a major version number. If it's a tag, the commit is identified automatically. In case only the major version number is given, a commit must be specified by passing its hash as 2nd argument.
BETTERBIRD_COMMIT="${script_args[1]}"
BETTERBIRD_REPO="https://github.com/Betterbird/thunderbird-patches"
PACKAGE=thunderbird
PLATFORM=linux-x86_64
SOURCES_FILE="$PACKAGE-sources.json"
APPDATA_FILE="thunderbird-patches/metadata/eu.betterbird.Betterbird.128.appdata.xml"
MANIFEST_FILE="eu.betterbird.Betterbird.yml"
DIST_FILE="distribution.ini"
BUILD_DATE_FILE=".build-date"
KNOWN_TAGS_FILE=".known-tags"
# determine if the source revision was specified as a tag or as a commit hash
[[ "x$BETTERBIRD_COMMIT" != "x" ]] && source_spec=commit || source_spec=tag
echo ""
[[ "$source_spec" == "tag" ]] && echo -n "Updating to TAG $BETTERBIRD_VERSION"
[[ "$source_spec" == "commit" ]] && echo -n "Updating to COMMIT $BETTERBIRD_COMMIT"
echo " using Betterbird patches for Thunderbird ${BETTERBIRD_VERSION%%.*}"
echo ""
# clone Betterbird repo
if [ -d thunderbird-patches ]
then
cd thunderbird-patches
git reset --hard HEAD
git fetch
else
git clone -n $BETTERBIRD_REPO thunderbird-patches
cd thunderbird-patches
fi
if [[ "$source_spec" == "tag" ]]
then
betterbird_commit=$(git rev-list -1 $BETTERBIRD_VERSION)
else
betterbird_commit=$(git rev-list -1 $BETTERBIRD_COMMIT)
fi
git checkout $betterbird_commit
cd ..
if [[ "$source_spec" == "tag" ]] && ! $force
then
# check if version from appdata.xml agrees with tag
betterbird_version_appdata=$(cat $APPDATA_FILE | grep '<release version=' | sed -r 's@^\s+<release version="(([^"])+)(" date=")([^"]+)(">)$@\1@')
if [[ $BETTERBIRD_VERSION != $betterbird_version_appdata* ]]
then
echo "Betterbird version given on command line ($BETTERBIRD_VERSION) and version according to $APPDATA_FILE ($betterbird_version_appdata) don't agree. Stopping."
echo "Hint: This check can be skipped by passing the -f flag."
exit 1
fi
fi
# save current date
TZ='Europe/Berlin' date '+%Y%m%d%H%M%S' > $BUILD_DATE_FILE
# get base URL for sources from appdata.xml
source_archive=$(cat $APPDATA_FILE | sed -rz 's@.+<artifact type="source">\s*<location>([^<]+)<\/location>.+@\1@')
base_url="${source_archive%/source/*}"
# write new sources file
echo '[' >"$SOURCES_FILE"
# read files from SHA256SUMS file
while read -r line; do
checksum="${line%% *}"
path="${line#* }"
# store source archive entry for later, because it should be the last element
# in the json array
if [[ $path =~ ^source/ ]]; then
source_archive=' {
"type": "archive",
"url": "'"$base_url"'/'"$path"'",
"sha256": "'"$checksum"'"
}'
# add locale to sources file
else
# strip directories and .xpi extension
locale="${path##*/}"
locale="${locale%.*}"
# include langpack only if there is a Betterbird patch for it
if [[ -f "thunderbird-patches/${BETTERBIRD_VERSION%%.*}/scripts/$locale.cmd" ]]
then
cat >>"$SOURCES_FILE" <<EOT
{
"type": "file",
"url": "$base_url/$path",
"sha256": "$checksum",
"dest": "langpacks/",
"dest-filename": "langpack-$locale@$PACKAGE.mozilla.org.xpi"
},
EOT
fi
fi
done < <(curl -Ss "$base_url/SHA256SUMS" | grep "^\S\+ \(source\|$PLATFORM/xpi\)/")
# add source archive entry to sources file
echo -e "$source_archive\n]" >>"$SOURCES_FILE"
# update betterbird release tag and commit in manifest
yq -i '(.modules[] | select(.name=="betterbird") | .sources[] | select(.dest=="thunderbird-patches") | .commit) = "'$betterbird_commit'"' $MANIFEST_FILE
if [[ "$source_spec" == "tag" ]]
then
yq -i '(.modules[] | select(.name=="betterbird") | .sources[] | select(.dest=="thunderbird-patches") | .tag) = "'$BETTERBIRD_VERSION'"' $MANIFEST_FILE
elif [[ "$source_spec" == "commit" ]]
then
yq -i 'del((.modules[] | select(.name=="betterbird") | .sources[] | select(.dest=="thunderbird-patches") | .tag))' $MANIFEST_FILE
fi
# update version in distribution.ini
sed -i 's/version=.*$/version='"$(git rev-parse --short $betterbird_commit)"'/' "$DIST_FILE"
# add external patches to sources file
# patch series for main repo
tmpfile="tmp.json"
while read -r line; do
url=$(echo $line | sed -r 's/(.*) # (http.*\/rev\/[0-9a-f]+).*/\2/' | sed -e 's/\/rev\//\/raw-rev\//')
name=$(echo $line | sed -r 's/(.*) # (.*)/\1/')
wget $url --max-redirect=20 -O $name
sha256=$(sha256sum "$name" | cut -f1 -d' ')
jq --arg url $url --arg name $name --arg sha256 $sha256 \
'. += [{"type":"file","url":$url,"sha256":$sha256,"dest":"patches/","dest-filename":$name}]' \
$SOURCES_FILE > $tmpfile
mv $tmpfile $SOURCES_FILE
rm -f $name
done < <(grep -E "^[^#].* # " thunderbird-patches/$(echo $BETTERBIRD_VERSION | cut -f1 -d'.')/series-moz)
# patch series for comm repo
while read -r line; do
url=$(echo $line | sed -r 's/(.*) # (http.*\/rev\/[0-9a-f]+).*/\2/' | sed -e 's/\/rev\//\/raw-rev\//')
name=$(echo $line | sed -r 's/(.*) # (.*)/\1/')
wget $url --max-redirect=20 -O $name
sha256=$(sha256sum "$name" | cut -f1 -d' ')
jq --arg url $url --arg name $name --arg sha256 $sha256 \
'. += [{"type":"file","url":$url,"sha256":$sha256,"dest":"patches/","dest-filename":$name}]' \
$SOURCES_FILE > $tmpfile
mv $tmpfile $SOURCES_FILE
rm -f $name
done < <(grep -E "^[^#].* # " thunderbird-patches/$(echo $BETTERBIRD_VERSION | cut -f1 -d'.')/series)
# add tag to .known-tags if it has not been added yet
if [[ "$source_spec" == "tag" ]] && ! grep -Fxq "$BETTERBIRD_VERSION" "$KNOWN_TAGS_FILE"
then
echo "$BETTERBIRD_VERSION" >> "$KNOWN_TAGS_FILE"
sort -o "$KNOWN_TAGS_FILE" "$KNOWN_TAGS_FILE"
fi
# download source tar to private mirror and replace download URLs
if $private_mirror
then
ssh srv5dl curl -C - --retry 5 --retry-all-errors -O --output-dir /srv/containers/dl $(cat thunderbird-sources.json | grep -Eo 'https://.*.source.tar.xz')
sed -E 's#https:\/\/archive\.mozilla\.org\/.*\/([^\/]+)\.source\.tar\.xz#https://dl.mfs.name/\1.source.tar.xz#' -i thunderbird-sources.json
fi
cat <<EOT
The files were successfully updated to Betterbird $BETTERBIRD_VERSION.
You can commit the result by executing the following command:
git commit --message='Update to $BETTERBIRD_VERSION' -- '$SOURCES_FILE' '$MANIFEST_FILE' '$DIST_FILE' '$BUILD_DATE_FILE' '$KNOWN_TAGS_FILE'
EOT