2 # Sign files and upload them.
4 scriptversion
=2017-09-13.06
; # UTC
6 # Copyright (C) 2004-2017 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 2, 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 <https://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'
40 usage
="Usage: $0 [OPTION]... [CMD] FILE... [[CMD] FILE...]
42 Sign all FILES, and process them at the destinations specified with --to.
43 If CMD is not given, it defaults to uploading. See examples below.
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 --to DEST specify a destination DEST for FILES
53 (multiple --to options are allowed)
54 --user NAME sign with key NAME
55 --replace allow replacements of existing files
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 (including the constructed directive file)
59 --version output version information and exit
60 --help print this help text and exit
62 If --symlink-regex is given without EXPR, then the link target name
63 is created by replacing the version information with '-latest', e.g.:
64 foo-1.3.4.tar.gz -> foo-latest.tar.gz
66 Recognized destinations are:
67 alpha.gnu.org:DIRECTORY
68 savannah.gnu.org:DIRECTORY
69 savannah.nongnu.org:DIRECTORY
71 build directive files and upload files by FTP
72 download.gnu.org.ua:{alpha|ftp}/DIRECTORY
73 build directive files and upload files by SFTP
74 [user@]host:DIRECTORY upload files with scp
76 Options and commands are applied in order. If the file $conffile exists
77 in the current working directory, its contents are prepended to the
78 actual command line options. Use this to keep your defaults. Comments
79 (#) and empty lines in $conffile are allowed.
81 <https://www.gnu.org/prep/maintain/html_node/Automated-FTP-Uploads.html>
82 gives some further background.
85 1. Upload foobar-1.0.tar.gz to ftp.gnu.org:
86 gnupload --to ftp.gnu.org:foobar foobar-1.0.tar.gz
88 2. Upload foobar-1.0.tar.gz and foobar-1.0.tar.xz to ftp.gnu.org:
89 gnupload --to ftp.gnu.org:foobar foobar-1.0.tar.gz foobar-1.0.tar.xz
91 3. Same as above, and also create symbolic links to foobar-latest.tar.*:
92 gnupload --to ftp.gnu.org:foobar \\
94 foobar-1.0.tar.gz foobar-1.0.tar.xz
96 4. Upload foobar-0.9.90.tar.gz to two sites:
97 gnupload --to alpha.gnu.org:foobar \\
98 --to sources.redhat.com:~ftp/pub/foobar \\
101 5. Delete oopsbar-0.9.91.tar.gz and upload foobar-0.9.91.tar.gz
102 (the -- terminates the list of files to delete):
103 gnupload --to alpha.gnu.org:foobar \\
104 --to sources.redhat.com:~ftp/pub/foobar \\
105 --delete oopsbar-0.9.91.tar.gz \\
106 -- foobar-0.9.91.tar.gz
108 gnupload executes a program ncftpput to do the transfers; if you don't
109 happen to have an ncftp package installed, the ncftpput-ftp script in
110 the build-aux/ directory of the gnulib package
111 (https://savannah.gnu.org/projects/gnulib) may serve as a replacement.
113 Send patches and bug reports to <bug-gnulib@gnu.org>."
115 # Read local configuration file
116 if test -r "$conffile"; then
117 echo "$0: Reading configuration file $conffile"
118 conf
=`sed 's/#.*$//;/^$/d' "$conffile" | tr "\015$nl" ' '`
119 eval set x
"$conf \"\$@\""
123 while test -n "$1"; do
133 if test -z "$2"; then
134 echo "$0: Missing argument for --to" 1>&2
136 elif echo "$2" |
grep 'ftp-upload\.gnu\.org' >/dev
/null
; then
137 echo "$0: Use ftp.gnu.org:PKGNAME or alpha.gnu.org:PKGNAME" >&2
138 echo "$0: for the destination, not ftp-upload.gnu.org (which" >&2
139 echo "$0: is used for direct ftp uploads, not with gnupload)." >&2
140 echo "$0: See --help and its examples if need be." >&2
148 if test -z "$2"; then
149 echo "$0: Missing argument for --user" 1>&2
152 GPG
="$GPG --local-user $2"
157 collect_var
=delete_files
160 replace
="replace: true"
163 collect_var
=delete_symlinks
166 symlink_expr
=`expr "$1" : '[^=]*=\(.*\)'`
169 symlink_expr
='s|-[0-9][0-9\.]*\(-[0-9][0-9]*\)\{0,1\}\.|-latest.|'
172 collect_var
=symlink_files
178 echo "gnupload $scriptversion"
186 echo "$0: Unknown option '$1', try '$0 --help'" 1>&2
192 if test -z "$collect_var"; then
195 eval "$collect_var=\"\$$collect_var $1\""
204 echo "Running $* ..."
211 if test -z "$to"; then
212 echo "$0: Missing destination sites" >&2
216 if test -n "$symlink_files"; then
217 x
=`echo "$symlink_files" | sed 's/[^ ]//g;s/ //g'`
218 if test -n "$x"; then
219 echo "$0: Odd number of symlink arguments" >&2
225 if test -z "${symlink_files}${delete_files}${delete_symlinks}"; then
226 echo "$0: No file to upload" 1>&2
230 # Make sure all files exist. We don't want to ask
231 # for the passphrase if the script will fail.
234 if test ! -f $file; then
235 echo "$0: Cannot find '$file'" 1>&2
237 elif test -n "$symlink_expr"; then
238 linkname
=`echo $file | sed "$symlink_expr"`
239 if test -z "$linkname"; then
240 echo "$0: symlink expression produces empty results" >&2
242 elif test "$linkname" = $file; then
243 echo "$0: symlink expression does not alter file name" >&2
250 # Make sure passphrase is not exported in the environment.
252 unset passphrase_fd_0
253 GNUPGHOME
=${GNUPGHOME:-$HOME/.gnupg}
255 # Reset PATH to be sure that echo is a built-in. We will later use
256 # 'echo $passphrase' to output the passphrase, so it is important that
257 # it is a built-in (third-party programs tend to appear in 'ps'
258 # listings with their arguments...).
259 # Remember this script runs with 'set -e', so if echo is not built-in
261 if $dry_run ||
grep -q "^use-agent" $GNUPGHOME/gpg.conf
; then :; else
262 PATH
=/empty
echo -n "Enter GPG passphrase: "
267 passphrase_fd_0
="--passphrase-fd 0"
270 if test $# -ne 0; then
273 echo "Signing $file ..."
275 echo "$passphrase" |
$dbg $GPG $passphrase_fd_0 -ba -o $file.sig
$file
280 # mkdirective DESTDIR BASE FILE STMT
281 # Arguments: See upload, below
285 if test -n "$3"; then
290 cat >${2}.directive
<<EOF
293 comment: gnupload v. $scriptversion$stmt
296 echo "File ${2}.directive:"
298 echo "File ${2}.directive:" |
sed 's/./-/g'
306 echo "symlink: $1 $2"
312 # upload DEST DESTDIR BASE FILE STMT FILES
314 # DEST Destination site;
315 # DESTDIR Destination directory;
316 # BASE Base name for the directive file;
317 # FILE Name of the file to distribute (may be empty);
318 # STMT Additional statements for the directive file;
319 # FILES List of files to upload.
329 rm -f $base.directive
$base.directive.asc
332 mkdirective
"$destdir" "$base" "$file" "$stmt"
333 echo "$passphrase" |
$dbg $GPG $passphrase_fd_0 --clearsign $base.directive
334 $dbg ncftpput ftp-upload.gnu.org
/incoming
/alpha
$files $base.directive.asc
337 mkdirective
"$destdir" "$base" "$file" "$stmt"
338 echo "$passphrase" |
$dbg $GPG $passphrase_fd_0 --clearsign $base.directive
339 $dbg ncftpput ftp-upload.gnu.org
/incoming
/ftp $files $base.directive.asc
342 if test -z "$files"; then
343 echo "$0: warning: standalone directives not applicable for $dest" >&2
345 $dbg ncftpput savannah.gnu.org
/incoming
/savannah
/$destdir $files
347 savannah.nongnu.org
:*)
348 if test -z "$files"; then
349 echo "$0: warning: standalone directives not applicable for $dest" >&2
351 $dbg ncftpput savannah.nongnu.org
/incoming
/savannah
/$destdir $files
353 download.gnu.org.ua
:alpha
/*|download.gnu.org.ua
:ftp
/*)
354 destdir_p1
=`echo "$destdir" | sed 's,^[^/]*/,,'`
355 destdir_topdir
=`echo "$destdir" | sed 's,/.*,,'`
356 mkdirective
"$destdir_p1" "$base" "$file" "$stmt"
357 echo "$passphrase" |
$dbg $GPG $passphrase_fd_0 --clearsign $base.directive
358 for f
in $files $base.directive.asc
361 done |
$dbg sftp
-b - puszcza.gnu.org.ua
:/incoming
/$destdir_topdir
364 dest_host
=`echo "$dest" | sed 's,:.*,,'`
365 mkdirective
"$destdir" "$base" "$file" "$stmt"
366 echo "$passphrase" |
$dbg $GPG $passphrase_fd_0 --clearsign $base.directive
367 $dbg cp $files $base.directive.asc
$dest_host
370 if test -z "$files"; then
371 echo "$0: warning: standalone directives not applicable for $dest" >&2
373 $dbg scp
$files $dest
376 rm -f $base.directive
$base.directive.asc
380 # Process any standalone directives
382 if test -n "$symlink_files"; then
384 `mksymlink $symlink_files`"
387 for file in $delete_files
393 for file in $delete_symlinks
399 if test -n "$stmt"; then
402 destdir
=`echo $dest | sed 's/[^:]*://'`
403 upload
"$dest" "$destdir" "`hostname`-$$" "" "$stmt"
407 # Process actual uploads
412 echo "Uploading $file to $dest ..."
415 # allowing file replacement is all or nothing.
416 if test -n "$replace"; then stmt
="$stmt
420 files
="$file $file.sig"
421 destdir
=`echo $dest | sed 's/[^:]*://'`
422 if test -n "$symlink_expr"; then
423 linkname
=`echo $file | sed "$symlink_expr"`
425 symlink: $file $linkname
426 symlink: $file.sig $linkname.sig"
428 upload
"$dest" "$destdir" "$file" "$file" "$stmt" "$files"
435 # eval: (add-hook 'write-file-hooks 'time-stamp)
436 # time-stamp-start: "scriptversion="
437 # time-stamp-format: "%:y-%02m-%02d.%02H"
438 # time-stamp-time-zone: "UTC0"
439 # time-stamp-end: "; # UTC"