2
# Sign files and upload them.
4
scriptversion=2012-01-15.15; # UTC
6
# Copyright (C) 2004-2010, 2012 Free Software Foundation, Inc.
8
# This program is free software; you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 3, or (at your option)
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
# Originally written by Alexandre Duret-Lutz <adl@gnu.org>.
22
# The master copy of this file is maintained in the gnulib Git repository.
23
# Please send bug reports and feature requests to bug-gnulib@gnu.org.
27
GPG='gpg --batch --no-tty'
39
usage="Usage: $0 [OPTION]... [CMD] FILE... [[CMD] FILE...]
41
Sign all FILES, and process them at selected destinations according to CMD.
42
<http://www.gnu.org/prep/maintain/html_node/Automated-FTP-Uploads.html>
46
--delete delete FILES from destination
47
--symlink create symbolic links
48
--rmsymlink remove symbolic links
49
-- treat the remaining arguments as files to upload
52
--help print this help text and exit
53
--to DEST specify one destination for FILES
54
(multiple --to options are allowed)
55
--user NAME sign with key NAME
56
--symlink-regex[=EXPR] use sed script EXPR to compute symbolic link names
57
--dry-run do nothing, show what would have been done
58
--version output version information and exit
60
If --symlink-regex is given without EXPR, then the link target name
61
is created by replacing the version information with '-latest', e.g.:
63
foo-1.3.4.tar.gz -> foo-latest.tar.gz
65
Recognized destinations are:
66
alpha.gnu.org:DIRECTORY
67
savannah.gnu.org:DIRECTORY
68
savannah.nongnu.org:DIRECTORY
70
build directive files and upload files by FTP
71
download.gnu.org.ua:{alpha|ftp}/DIRECTORY
72
build directive files and upload files by SFTP
73
[user@]host:DIRECTORY upload files with scp
75
Options and commands are applied in order. If the file $conffile exists
76
in the current working directory, its contents are prepended to the
77
actual command line options. Use this to keep your defaults. Comments
78
(#) and empty lines in $conffile are allowed.
81
1. Upload foobar-1.0.tar.gz to ftp.gnu.org:
82
gnupload --to ftp.gnu.org:foobar foobar-1.0.tar.gz
84
2. Upload foobar-1.0.tar.gz and foobar-1.0.tar.xz to ftp.gnu.org:
85
gnupload --to ftp.gnu.org:foobar foobar-1.0.tar.gz foobar-1.0.tar.xz
87
3. Same as above, and also create symbolic links to foobar-latest.tar.*:
88
gnupload --to ftp.gnu.org:foobar \\
90
foobar-1.0.tar.gz foobar-1.0.tar.xz
92
4. Upload foobar-0.9.90.tar.gz to two sites:
93
gnupload --to alpha.gnu.org:foobar \\
94
--to sources.redhat.com:~ftp/pub/foobar \\
97
5. Delete oopsbar-0.9.91.tar.gz and upload foobar-0.9.91.tar.gz
98
(the -- terminates the list of files to delete):
99
gnupload --to alpha.gnu.org:foobar \\
100
--to sources.redhat.com:~ftp/pub/foobar \\
101
--delete oopsbar-0.9.91.tar.gz \\
102
-- foobar-0.9.91.tar.gz
104
gnupload uses the ncftpput program to do the transfers; if you don't
105
happen to have an ncftp package installed, the ncftpput-ftp script in
106
the build-aux/ directory of the gnulib package
107
(http://savannah.gnu.org/projects/gnulib) may serve as a replacement.
109
Send patches and bug reports to <bug-gnulib@gnu.org>."
111
# Read local configuration file
112
if test -r "$conffile"; then
113
echo "$0: Reading configuration file $conffile"
114
conf=`sed 's/#.*$//;/^$/d' "$conffile" | tr "\015$nl" ' '`
115
eval set x "$conf \"\$@\""
119
while test -n "$1"; do
129
if test -z "$2"; then
130
echo "$0: Missing argument for --to" 1>&2
138
if test -z "$2"; then
139
echo "$0: Missing argument for --user" 1>&2
142
GPG="$GPG --local-user $2"
147
collect_var=delete_files
150
collect_var=delete_symlinks
153
symlink_expr=`expr "$1" : '[^=]*=\(.*\)'`
156
symlink_expr='s|-[0-9][0-9\.]*\(-[0-9][0-9]*\)\{0,1\}\.|-latest.|'
159
collect_var=symlink_files
165
echo "gnupload $scriptversion"
173
echo "$0: Unknown option '$1', try '$0 --help'" 1>&2
179
if test -z "$collect_var"; then
182
eval "$collect_var=\"\$$collect_var $1\""
191
echo "Running $* ..."
198
if test -z "$to"; then
199
echo "$0: Missing destination sites" >&2
203
if test -n "$symlink_files"; then
204
x=`echo "$symlink_files" | sed 's/[^ ]//g;s/ //g'`
205
if test -n "$x"; then
206
echo "$0: Odd number of symlink arguments" >&2
212
if test -z "${symlink_files}${delete_files}${delete_symlinks}"; then
213
echo "$0: No file to upload" 1>&2
217
# Make sure all files exist. We don't want to ask
218
# for the passphrase if the script will fail.
221
if test ! -f $file; then
222
echo "$0: Cannot find '$file'" 1>&2
224
elif test -n "$symlink_expr"; then
225
linkname=`echo $file | sed "$symlink_expr"`
226
if test -z "$linkname"; then
227
echo "$0: symlink expression produces empty results" >&2
229
elif test "$linkname" = $file; then
230
echo "$0: symlink expression does not alter file name" >&2
237
# Make sure passphrase is not exported in the environment.
240
# Reset PATH to be sure that echo is a built-in. We will later use
241
# 'echo $passphrase' to output the passphrase, so it is important that
242
# it is a built-in (third-party programs tend to appear in 'ps'
243
# listings with their arguments...).
244
# Remember this script runs with 'set -e', so if echo is not built-in
246
PATH=/empty echo -n "Enter GPG passphrase: "
252
if test $# -ne 0; then
255
echo "Signing $file ..."
257
echo "$passphrase" | $dbg $GPG --passphrase-fd 0 -ba -o $file.sig $file
262
# mkdirective DESTDIR BASE FILE STMT
263
# Arguments: See upload, below
267
if test -n "$3"; then
272
cat >${2}.directive<<EOF
275
comment: gnupload v. $scriptversion$stmt
278
echo "File ${2}.directive:"
280
echo "File ${2}.directive:" | sed 's/./-/g'
288
echo "symlink: $1 $2"
294
# upload DEST DESTDIR BASE FILE STMT FILES
296
# DEST Destination site;
297
# DESTDIR Destination directory;
298
# BASE Base name for the directive file;
299
# FILE Name of the file to distribute (may be empty);
300
# STMT Additional statements for the directive file;
301
# FILES List of files to upload.
311
rm -f $base.directive $base.directive.asc
314
mkdirective "$destdir" "$base" "$file" "$stmt"
315
echo "$passphrase" | $dbg $GPG --passphrase-fd 0 --clearsign $base.directive
316
$dbg ncftpput ftp-upload.gnu.org /incoming/alpha $files $base.directive.asc
319
mkdirective "$destdir" "$base" "$file" "$stmt"
320
echo "$passphrase" | $dbg $GPG --passphrase-fd 0 --clearsign $base.directive
321
$dbg ncftpput ftp-upload.gnu.org /incoming/ftp $files $base.directive.asc
324
if test -z "$files"; then
325
echo "$0: warning: standalone directives not applicable for $dest" >&2
327
$dbg ncftpput savannah.gnu.org /incoming/savannah/$destdir $files
329
savannah.nongnu.org:*)
330
if test -z "$files"; then
331
echo "$0: warning: standalone directives not applicable for $dest" >&2
333
$dbg ncftpput savannah.nongnu.org /incoming/savannah/$destdir $files
335
download.gnu.org.ua:alpha/*|download.gnu.org.ua:ftp/*)
336
destdir_p1=`echo "$destdir" | sed 's,^[^/]*/,,'`
337
destdir_topdir=`echo "$destdir" | sed 's,/.*,,'`
338
mkdirective "$destdir_p1" "$base" "$file" "$stmt"
339
echo "$passphrase" | $dbg $GPG --passphrase-fd 0 --clearsign $base.directive
340
for f in $files $base.directive.asc
343
done | $dbg sftp -b - puszcza.gnu.org.ua:/incoming/$destdir_topdir
346
dest_host=`echo "$dest" | sed 's,:.*,,'`
347
mkdirective "$destdir" "$base" "$file" "$stmt"
348
echo "$passphrase" | $dbg $GPG --passphrase-fd 0 --clearsign $base.directive
349
$dbg cp $files $base.directive.asc $dest_host
352
if test -z "$files"; then
353
echo "$0: warning: standalone directives not applicable for $dest" >&2
355
$dbg scp $files $dest
358
rm -f $base.directive $base.directive.asc
362
# Process any standalone directives
364
if test -n "$symlink_files"; then
366
`mksymlink $symlink_files`"
369
for file in $delete_files
375
for file in $delete_symlinks
381
if test -n "$stmt"; then
384
destdir=`echo $dest | sed 's/[^:]*://'`
385
upload "$dest" "$destdir" "`hostname`-$$" "" "$stmt"
389
# Process actual uploads
394
echo "Uploading $file to $dest ..."
396
files="$file $file.sig"
397
destdir=`echo $dest | sed 's/[^:]*://'`
398
if test -n "$symlink_expr"; then
399
linkname=`echo $file | sed "$symlink_expr"`
401
symlink: $file $linkname
402
symlink: $file.sig $linkname.sig"
404
upload "$dest" "$destdir" "$file" "$file" "$stmt" "$files"
411
# eval: (add-hook 'write-file-hooks 'time-stamp)
412
# time-stamp-start: "scriptversion="
413
# time-stamp-format: "%:y-%02m-%02d.%02H"
414
# time-stamp-time-zone: "UTC"
415
# time-stamp-end: "; # UTC"