-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchive-lib.sh
executable file
·368 lines (299 loc) · 6.61 KB
/
archive-lib.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
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
#!/bin/bash
#
# Copyright © 2003-2007 Guillem Jover <[email protected]>
# Copyright © 2015 Matthias Blümel <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# Requires: procmail (formail)
#
# Sanitize environment
unset LANG
unset LC_ALL
# Import configuration
. archive.conf
# Canonicalize directories
accepted_dir=$queue_dir/accepted
unchecked_dir=$queue_dir/unchecked
byhand_dir=$queue_dir/byhand
######
# file input functions
fetch_field ()
{
local field=$1
formail -z -x$field:
}
fetch_source_name ()
{
fetch_field Source | cut -d' ' -f1
}
fetch_files ()
{
formail -xFiles: | cut -d' ' -f6
}
fetch_md5sums ()
{
formail -xFiles: | cut -d' ' -f2,6 | sed -e 's/ / /'
}
fetch_secure_files ()
{
local files=`fetch_files`
for file in $files; do
echo $(basename "`readlink -f $file`")
done
}
fetch_single_arch ()
{
local arches=`fetch_field "Architecture"`
echo $(filter_real_arches $arches)
}
filter_real_arches ()
{
local arches=$@
local real_arches=$(echo $arches | sed -re 's/(source|all) ?//g')
echo $real_arches
}
get_archive_arches ()
{
local arches
for suite in $suite_list; do
arches="$arches $(get_suite_arches $suite)"
done
arches="$(echo $arches | tr ' ' '\n' | sort -u)"
echo $(filter_real_arches $arches)
}
get_pool_dirs ()
{
if [ "$multipool" = "yes" ]; then
local pool_dirs
for arch in $(get_archive_arches); do
pool_dirs="$pool_dirs $pool_dir-$arch"
done
echo "$pool_dirs"
else
echo "$pool_dir/"
fi
}
get_pool_dir_arch ()
{
local arch=$1
if [ "$multipool" = "yes" ]; then
echo "$pool_dir-$arch/"
else
echo "$pool_dir/"
fi
}
get_suite_arches ()
{
local suite=$(canonic_suite $1)
eval echo \$arch_list_$suite
}
get_suite_sections ()
{
echo $section_list
}
valid_arch ()
{
local v_suite=$1
local v_arch=$2
for arch in $(get_suite_arches $v_suite) all; do
if [ "$arch" = "$v_arch" ]; then
return 0
fi
done
return 1
}
get_suite_codename()
{
local suite=$1
for s_alias in $suite_alias; do
s_codename=${s_alias%%:*}
s_suite=${s_alias##*:}
if [ "$suite" = $s_suite ]; then
echo $s_codename
return 0
fi
done
echo $suite
}
canonic_suite()
{
local code_name=$1
for s_alias in $suite_alias; do
s_code_name=${s_alias%%:*}
s_suite=${s_alias##*:}
if [ "$code_name" = $s_code_name ]; then
echo $s_suite
return 0
fi
done
echo $code_name
}
poolize_hash_name()
{
echo $1 | sed -e 's/^\(\(lib\)\?.\).*$/\1/'
}
poolize_package_name_relative()
{
local name=$1
local section=$2
local package=`echo $name | cut -d_ -f1`
local hash_dir=`poolize_hash_name $package`
local dest_dir=$section/$hash_dir/$package/
echo $dest_dir
}
poolize_package_name()
{
echo $pool_dir/$(poolize_package_name_relative $1 $2)
}
poolize_arch_name_relative()
{
local package=$1
local section=$2
local arch=$3
local hash_dir=`poolize_hash_name $package`
echo $section/$hash_dir/$package/
}
poolize_arch_name()
{
local dest_dir_relative=$(poolize_arch_name_relative $1 $2 $3)
if [ "$multipool" = "yes" ]; then
local dest_dir=$pool_dir-$arch/$dest_dir_relative
else
local dest_dir=$pool_dir/$dest_dir_relative
fi
echo $dest_dir
}
# .changes management functions
changes_canonic ()
{
section=$1
while read f_changes; do
archive=`changes_strip < $f_changes`
package=`echo "$archive" | fetch_source_name`
version=`echo "$archive" | fetch_field "Version"`
suite=`echo "$archive" | fetch_field "Distribution"`
arches=`echo "$archive" | fetch_field "Architecture"`
for arch in $(filter_real_arches $arches) all; do
printf "%s %s %s %s %s %s\n" $package $suite $section $arch $version $f_changes
done
done
}
changes_obsolete ()
{
# FIXME: Should implement suite stacks for obsoleting purposes.
# (unstable + unreleased) < experimental
# Should remove the hardcoded experimental check.
while read package suite arch version path; do
if [ "$package" = "$g_package" ] &&
[ "$arch" = "$g_arch" ]; then
if dpkg --compare-versions $g_version lt $version; then
if [ "$g_suite" = "experimental" -o "$suite" != "experimental" ]; then
printf "%s %s %s %s %s\n" $g_package $g_suite $g_arch $g_version $g_path
fi
else
if [ "$suite" = "experimental" -o "$g_suite" != "experimental" ]; then
printf "%s %s %s %s %s\n" $package $suite $arch $version $path
fi
fi
fi
g_package=$package
g_version=$version
g_suite=$suite
g_arch=$arch
g_path=$path
done
}
changes_strip ()
{
awk '
BEGIN { block = 0; contents = 0 }
/^-----BEGIN PGP SIGNATURE/ { exit }
block && contents { print }
/^-----BEGIN PGP SIGNED/ { block = 1 }
block && /^ *$/ { contents = 1 }
'
}
archive_move ()
{
local mode=$1
local fetch_files='fetch_files'
if [ $mode = "secure" ]; then
fetch_files='fetch_secure_files'
shift
fi
local archive_file=$1
local section=$(basename $(dirname $archive_file))
local dest_dir=$2
local files=`$fetch_files < $archive_file`
if mv $files "$dest_dir"; then
return 0
else
return 1
fi
}
files_owner_perms ()
{
local files=$@
chown -f $archive_owner:$archive_group $files
chmod $archive_perms $files
}
dirs_owner_perms ()
{
local dirs=$@
chown -f $archive_owner:$archive_group $dirs
chmod $archive_perms_dir $dirs
}
time_full ()
{
date -Iseconds | tr 'T' ' '
}
echo_time ()
{
echo "`time_full` $@"
}
logpipe()
{
local name=$1
local log_monthly_dir=$log_dir/`date +%Y`/`date +%m`
local logfile=$log_monthly_dir/$name-`date -I`.log
mkdir -p $log_monthly_dir
dirs_owner_perms $log_monthly_dir
tee -a $logfile
}
log()
{
local name=$1
shift
echo -e "$@" | logpipe "$name"
}
msg_queue ()
{
local subject=$1
local recipient=$2
(
cat
echo "$subject"
echo
) | logpipe queue
if [ "$MAIL_REPORT" = "yes" ]; then
(
cat
echo
echo "-- "
echo "Archive Maintainer ($archive_maint)"
) | mail -s "$subject" "$recipient"
fi
}