-
Notifications
You must be signed in to change notification settings - Fork 21
/
update-templates
executable file
·288 lines (248 loc) · 7.97 KB
/
update-templates
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/usr/bin/bash
#
# Update a plugin with new shipdriver templates.
#
# usage: ./update-templates [-t] [treeish]
#
# Merge changes from upstream shipdriver repo into
# current branch.
#
# See UPDATE-TEMPLATES.md for more info
function usage() {
cat << EOT
Usage:
update-templates [-T] <treeish>
update-templates [-h |-l]
Parameters:
treeish:
A shipdriver tag or branch.
Recommended usage is using the latest stable (non-beta) tag
Options:
-l List available shipdriver tags
-h Print this message and exit
-T Test mode, do not auto-update
Examples:
update-templates -l -- List available tags
update-templates sd3.0.2 -- Update from sd3.0.2 tag
update-templates shipdriver/v3.0 -- Update from v3.0 release branch
update-templates shipdriver/master -- Update from development branch
EOT
}
function list_sd_tags() {
# List all tags in shipdriver remote with a 'sd' prefix
git ls-remote --tags shipdriver \
| sed -n -e '/{}/d' -e 's|.*tags/||' -e '/^sd/p'
}
function init_shipdriver_remote() {
# Set up the shipdriver remote
if git ls-remote --exit-code shipdriver &>/dev/null; then
git remote remove shipdriver
echo "Removing existing shipdriver remote."
fi
echo "Adding new shipdriver remote"
git remote add shipdriver https://github.com/Rasbats/shipdriver_pi.git
# Fetch all available shipdriver sd* tags
for t in $(list_sd_tags); do
git fetch -q shipdriver refs/tags/$t:refs/tags/$t --no-tags
done
}
function update_dir() {
# Update directory $1 from shipdriver treeish $2
local d=$1
local treeish=$2
echo "Updating $d"
if [ -d $d ]; then git rm -rf $d/*; fi
git checkout $treeish $d
git add $d
git diff-index --quiet --cached HEAD -- || {
git commit -m "Templates: Updating $d"
}
}
# Exec on tmpfile to avoid file lock when updating script on Windows.
# The directory /c exists on git bash on Windows, and hopefully only there.
if [[ -d /c && "$0" =~ .*update-templates ]]; then
tmpfile=$(mktemp)
cp $0 $tmpfile
exec $tmpfile $@
fi
# Handle options and parameters
usage="Usage: $0 [-t] [-T] [treeish]"
merge_opt=""
while getopts "Thl" opt; do
case "${opt}" in
T) test_mode=true
;;
h) usage; exit 0
;;
l) do_list_tags="true"
;;
*) usage >&2; exit 1
;;
esac
done
shift $((OPTIND-1))
if [ -n "$do_list_tags" ]; then
if [ -z "$test_mode" ]; then init_shipdriver_remote; fi
list_sd_tags
exit 0
fi
if [ -z "$1" ]; then
usage >&2
exit 1
fi
test -z "$test_mode" || set -x
source_treeish=$1
# Refuse to run unless the index is clean:
clean=$(git status --porcelain)
if [ -n "$clean" ]; then
echo "Please commit or stash pending changes. Aborting."
exit 1
fi
# Set up a generic sed -i command for MacOS and Linux/GNU (#505).
case $OSTYPE in
darwin*) SED_I="sed -i.bak"
;;
*) SED_I="sed -i"
;;
esac
if [ -z "$test_mode" ]; then
init_shipdriver_remote
echo "Checking for updates of updates-templates script"
if ! git diff --quiet HEAD $source_treeish -- update-templates; then
git checkout $source_treeish update-templates
cat << EOT
update-templates script is updated to latest version. Please commit
changes and re-run script.
EOT
exit 0
fi
fi
git rev-parse --verify -q $source_treeish || {
echo "Unknown tag or branch $source_treeish -- giving up."
exit 1
}
# Updating standard directories
for dir in cmake ci scripts buildwin; do
update_dir $dir $source_treeish
done
# If Plugin.cmake exists we should also update CMakeLists.txt
if [ -f Plugin.cmake ]; then CMakeLists=CMakeLists.txt; fi
echo "Templates: Updating other files"
for f in \
appveyor.yml \
Changelog.md \
.circleci \
.clang-format \
.cmake-format.yaml \
.gitattributes \
.gitignore \
INSTALL.md \
plugin.xml.in \
.travis.yml \
update-templates \
UPDATE_TEMPLATES.md \
$CMakeLists
do
if test -d $f; then git rm -rf $f; fi
git checkout $source_treeish $f
git add $f || git add --renormalize $f
done
git commit -m "Templates: Updating other files"
# Handle opencpn-libs submodule
test -d opencpn-libs || \
git submodule add https://github.com/opencpn/opencpn-libs.git opencpn-libs
git submodule update --remote --merge opencpn-libs
git add opencpn-libs
git diff-index --quiet --cached HEAD -- || {
echo "Updating opencpn-libs submodule"
git commit -m "opencpn-libs: Update to latest version."
}
sed -i 's|leamas/opencpn-libs|opencpn/opencpn-libs|g' \
.git/modules/opencpn-libs/config || :
# Update flatpak runtime version as required:
$SED_I \
-e '/sdk: org.freedesktop.Sdk/s/20.08/22.08/' \
-e '/^runtime-version:/s/:.*/: stable/' \
flatpak/org.opencpn.OpenCPN.Plugin.*.yaml
git add flatpak
git diff-index --quiet --cached HEAD -- || {
echo "Updating Updating flatpak runtime version to 22.08"
git commit -m "opencpn-libs: Update to latest version."
}
# Check for files/dirs which are private, but should be copied on first run.
for f in \
config.h.in \
build-deps \
build-conf.rc \
libs \
build-deps/macos-cache-stamp \
build-deps/0001-matrix.h-Patch-attributes-handling-wxwidgets-22790.patch \
UPDATE_PLUGIN_API.md
do
if test -e $f; then continue; fi
git checkout $source_treeish $f
done
git diff-index --quiet --cached HEAD -- || {
echo "Adding initial versions of private data"
git commit -m "Adding initial versions of private data"
}
# Update wxwidgets deps in build-deps/control to handle wxwidgets 3.2
wxtemp=$(mktemp)
cat >$wxtemp << EOF
base-files (>=11) | libwxgtk3.0-dev,
base-files (>=11) | libwxgtk3.0-0v5 | libwxgtk3.0-0,
base-files (>=10) | libwxgtk-webview3.0-dev,
base-files (<< 10) | libwxgtk3.2-dev | libwxgtk3.0-gtk3-dev,
base-files (<< 10) | libwxgtk-webview3.2-dev | libwxgtk-webview3.0-gtk3-dev,
EOF
grep -q "libwxgtk3.2" build-deps/control || {
$SED_I -e '/libwxgtk/s/^.*$/LIBWXGTK/' \
-e '1,/LIBWXGTK/s/LIBWXGTK/WX_DEPS/' \
-e "/WX_DEPS/r$wxtemp" \
-e '/WX_DEPS/d' -e '/LIBWXGTK/d' \
-e '/Build-Depends/,/python/s/^$/FOO/' -e '/^FOO/d' \
build-deps/control
}
rm -f $wxtemp
git diff --quiet build-deps/control || {
echo "Updating wxwidgets dependencies in build-deps/control"
git add build-deps/control
git commit -m "build-deps/control: Updating wxwidgets dependencies"
}
if [ -e update-ignored ]; then
echo "Revert changes in blacklisted files."
for f in $(cat update-ignored); do
git checkout HEAD $f
done
fi
for f in buildosx buildwin/NSIS* libs/AndroidLibs.cmake mingw .drone.yml; do
if test -e $f; then git rm -rf $f; fi
done
git diff-index --quiet --cached HEAD -- || {
echo "Removing unused files"
git commit -am "Templates: Removing obsoleted and unused files."
}
if [ -f cmake/TemplateVersion ]; then
our_manifest=$(echo flatpak/org.opencpn.OpenCPN.Plugin.*.yaml)
echo "Append shipdriver flatpak manifest's log of changes to $our_manifest"
prev_commit=$(sed -n '/commit:/s/.*: *//p' cmake/TemplateVersion)
src_manifest=flatpak/org.opencpn.OpenCPN.Plugin.shipdriver.yaml
git checkout $source_treeish $src_manifest
git diff $prev_commit $src_manifest | sed 's/^/# /' \
>> $our_manifest
git rm -f $src_manifest
fi
echo "Create or update cmake/TemplateVersion"
echo "# Created by update-templates" > cmake/TemplateVersion
echo "date: $(date -u +'%Y-%m-%d %H:%M UTC')" >> cmake/TemplateVersion
commit=$(git rev-parse --short $source_treeish)
echo "commit: $commit" >> cmake/TemplateVersion
tags=$(git tag --contains $commit)
echo "tags: $tags" >> cmake/TemplateVersion
git add cmake/TemplateVersion
git commit -m "cmake: Update TemplateVersion to $commit"
cat << EOF
Shipdriver templates has been updated. Please review Changelog.md for info
about changes in last release.
See UPDATE_TEMPLATES.md for more info.
EOF