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
|
#!/usr/bin/env bash
#
# update.sh - script to check for updates and perform them (on the PKGBUILDs)
#
# Copyright 2018 Einhard Leichtfuß
#
# This file is part of aur-fd-scripts
#
# aur-fd-scripts is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# aur-fd-scripts is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with aur-fd-scripts. If not, see <https://www.gnu.org/licenses/>.
#
# usage: $0 dir type [--nopull] [-u xyz-uvw|-ua|-uaf]
# $1 base directory: string
# $2 type: (src|bin|svn)
# $4 option: --nopull {can be omitted}
# ${4,5} update force mode: (-u lang1-lang2|-ua|-uaf) {can be omitted}
# -u x: Update x, even if it appears up to date.
# -ua: Update all that are out of date.
# -uaf: Update all, even if they appear up to date.
script_path="$(realpath "$0")"
script_dir="${script_path%/*}"
. "${script_dir}/basic.sh"
## Some configuration.
# Long names table.
typeset -A long
long[fra]=French
long[deu]=German
long[eng]=English
long[spa]=Spanish
# Contributors for some specific PKGBUILDs (indexed by $lang$ext).
typeset -A contrs
contrs[deu-eng-bin]=\
'# Contributor: akane <grangerspit@gmail.com> <xmpp:heiß@neko.im>'$'\n'
contrs[eng-deu-bin]=\
'# Contributor: akane <grangerspit@gmail.com> <xmpp:heiß@neko.im>'$'\n'
contrs[fra-eng-bin]=\
'# Contributor: Benjamin Vanderford <hazor_at_swrpg_dot_info>'$'\n'
contrs[eng-fra-bin]=\
'# Contributor: Benjamin Vanderford <hazor_at_swrpg_dot_info>'$'\n'
# Licenses (indexed by $lang)
typeset -A licenses
for lang in ${vcs_langs[@]}
do
licenses[$lang]="'GPL'"
done
for lang in ${wikdict_langs[@]}
do
licenses[$lang]="'CCPL:by-sa' 'FDL'"
done
# prepare() functions (indexed by $lang$ext).
typeset -A prepare
# Does not work for deu-fra-bin, since the index file must stay in sync.
prepare[deu-fra]=\
'prepare()
{
cd $_lang
sed -Ei \
-e '"'"'s/(10)(10)(100\>)(\s+\(10)(Googol.*(1|Eins) mit einem Googol Nullen)/\1^(\2^\3)\4^\5/'"'"' \
-e '"'"'s/(10)([1-9][0-9]*)(.*(1|Eins) mit \2 Nullen)/\1\^\2\3/'"'"' \
-e '"'"'s/(die Zahl 10)(60)/\1^\2/'"'"' \
${_lang}.tei
}
'
## End configuration
function main
{
if [ "$#" -lt 2 ]
then
echo "Usage: $0 <base_dir> <type> [--nopull] [-u <xy>-<zw>|-ua|-uaf]" >&2
exit 1
else
cd "$1" || exit 1
fi
type="$2"
if [ "$3" = "--nopull" ]
then
nopull=true
shift 3
else
nopull=false
shift 2
fi
init
if [[ "$type" == src ]]
then
handle_all src '' src "$@"
elif [[ "$type" == bin ]]
then
handle_all bin -bin dictd "$@"
elif [[ "$type" == svn ]]
then
handle_all_vcs svn -svn "$@"
else
echo "Type $type not supported." >&2
exit 1
fi
}
# Update PKGBUILD and .SRCINFO
#
# requires: $lang, $ext, $type, $ver, $convver to be set;
# $PWD == <base directory>/<type>/<lang>
#
function update
{
echo "Updating ${lang}${ext} (${pkgver} -> ${convver})..."
lang_a="${long[${lang%-*}]}"
lang_b="${long[${lang#*-}]}"
input "${script_dir}/${type}/sample.PKGBUILD"
replace '%LANG%' "$lang"
replace '%LANG_A%' "$lang_a"
replace '%LANG_B%' "$lang_b"
replace '%VER%' "$convver"
replace '%LICENSES%' "${licenses[$lang]}"
replace '%CHECKSUM%' "$checksum"
replace_line '%CONTRS%' "${contrs[${lang}${ext}]}" normal
if [[ "$ver" == "$convver" ]]
then
delete_line '^_pkgver=\$\{pkgver\/\/_\/-\}$'
replace '_pkgver' 'pkgver'
fi
replace_line '%PREPARE%' "${prepare[${lang}${ext}]}" rm-plus-one
write PKGBUILD
makepkg --printsrcinfo > .SRCINFO
}
# Check for updates for src / bin packages and optionally update them.
#
# $1 type: (src|bin)
# $2 suffix: (|-bin)
# $3 platform: (src|dictd)
# ${@:4} args: $@
#
# requires: $PWD == <base directory>
#
function handle_all
{
type="$1"
ext="$2"
platform="$3"
shift 3
curl -sO https://freedict.org/freedict-database.json || exit 1
cd "$type" || exit 1
for lang in ${langs[@]}
do
cd $lang || exit 1
$nopull || git pull -q
pkgver="$(sed -En 's/\s*pkgver\s*=\s*(.+)\s*/\1/p' .SRCINFO)"
data="$(jq -r ".[] | select(.name == \"${lang}\") | .releases[] | select(.platform==\"$platform\")" ../../freedict-database.json)"
ver="$(jq -r '.version' <<< "$data")"
url="$(jq -r '.URL' <<< "$data")"
checksum="$(jq -r '.checksum' <<< "$data")"
convver="${ver//-/_}"
if [[ "$pkgver" != "$convver" ]]
then
echo "${lang}${ext} requires update (${pkgver} -> ${convver})."
ureq=true
else
ureq=false
fi
if [[ "$url" != "https://download.freedict.org/dictionaries/${lang}/${ver}/freedict-${lang}-${ver}.${platform}.tar.xz" ]]
then
echo "${lang}${ext} URL changed (${url})."
else
if [[ "$1" == "-u" && "$2" == "$lang" ]] \
|| ([[ "$1" == "-ua" ]] && $ureq) \
|| [[ "$1" == "-uaf" ]]
then
update
fi
fi
cd ..
done
cd ..
}
# Check for updates for VCS (svn) packages and optionally update them.
#
# $1 type: (svn)
# $2 suffix: (-svn)
# ${@:3} args: $@
#
# requires: $PWD == <base directory>
#
function handle_all_vcs
{
type="$1"
ext="$2"
shift 2
cd "$type" || exit 1
for lang in ${vcs_langs[@]}
do
cd $lang || exit 1
$nopull || git pull -q
pkgver="$(sed -En 's/\s*pkgver\s*=\s*(.+)\s*/\1/p' .SRCINFO)"
makepkg --nobuild --nodeps > /dev/null 2>&1
ver="$(makepkg --printsrcinfo \
| sed -En 's/\s*pkgver\s*=\s*(.+)\s*/\1/p')"
convver="$ver"
if [[ "$1" == "-u" && "$2" == "$lang" ]] || [[ "$1" == "-uaf" ]]
then
update
fi
cd ..
done
cd ..
}
main "$@"
|