2 # Sign files and upload them.
4 scriptversion=2012-06-11.00; # UTC
6 # Copyright (C) 2004-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 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 <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'
40 usage="Usage: $0 [OPTION]... [CMD] FILE... [[CMD] FILE...]
42 Sign all FILES, and process them at selected destinations according to CMD.
43 <http://www.gnu.org/prep/maintain/html_node/Automated-FTP-Uploads.html>
47 --delete delete FILES from destination
48 --symlink create symbolic links
49 --rmsymlink remove symbolic links
50 -- treat the remaining arguments as files to upload
53 --help print this help text and exit
54 --to DEST specify one destination for FILES
55 (multiple --to options are allowed)
56 --user NAME sign with key NAME
57 --replace allow replacements of existing files
58 --symlink-regex[=EXPR] use sed script EXPR to compute symbolic link names
59 --dry-run do nothing, show what would have been done
60 (including the constructed directive file)
61 --version output version information and exit
63 If --symlink-regex is given without EXPR, then the link target name
64 is created by replacing the version information with '-latest', e.g.:
66 foo-1.3.4.tar.gz -> foo-latest.tar.gz
68 Recognized destinations are:
69 alpha.gnu.org:DIRECTORY
70 savannah.gnu.org:DIRECTORY
71 savannah.nongnu.org:DIRECTORY
73 build directive files and upload files by FTP
74 download.gnu.org.ua:{alpha|ftp}/DIRECTORY
75 build directive files and upload files by SFTP
76 [user@]host:DIRECTORY upload files with scp
78 Options and commands are applied in order. If the file $conffile exists
79 in the current working directory, its contents are prepended to the
80 actual command line options. Use this to keep your defaults. Comments
81 (#) and empty lines in $conffile are allowed.
84 1. Upload foobar-1.0.tar.gz to ftp.gnu.org:
85 gnupload --to ftp.gnu.org:foobar foobar-1.0.tar.gz
87 2. Upload foobar-1.0.tar.gz and foobar-1.0.tar.xz to ftp.gnu.org:
88 gnupload --to ftp.gnu.org:foobar foobar-1.0.tar.gz foobar-1.0.tar.xz
90 3. Same as above, and also create symbolic links to foobar-latest.tar.*:
91 gnupload --to ftp.gnu.org:foobar \\
93 foobar-1.0.tar.gz foobar-1.0.tar.xz
95 4. Upload foobar-0.9.90.tar.gz to two sites:
96 gnupload --to alpha.gnu.org:foobar \\
97 --to sources.redhat.com:~ftp/pub/foobar \\
100 5. Delete oopsbar-0.9.91.tar.gz and upload foobar-0.9.91.tar.gz
101 (the -- terminates the list of files to delete):
102 gnupload --to alpha.gnu.org:foobar \\
103 --to sources.redhat.com:~ftp/pub/foobar \\
104 --delete oopsbar-0.9.91.tar.gz \\
105 -- foobar-0.9.91.tar.gz
107 gnupload uses the ncftpput program to do the transfers; if you don't
108 happen to have an ncftp package installed, the ncftpput-ftp script in
109 the build-aux/ directory of the gnulib package
110 (http://savannah.gnu.org/projects/gnulib) may serve as a replacement.
112 Send patches and bug reports to <bug-gnulib@gnu.org>."
114 # Read local configuration file
115 if test -r "$conffile"; then
116 echo "$0: Reading configuration file $conffile"
117 conf=`sed 's/#.*$//;/^$/d' "$conffile" | tr "\015$nl" ' '`
118 eval set x "$conf \"\$@\""
122 while test -n "$1"; do
132 if test -z "$2"; then
133 echo "$0: Missing argument for --to" 1>&2
141 if test -z "$2"; then
142 echo "$0: Missing argument for --user" 1>&2
145 GPG="$GPG --local-user $2"
150 collect_var=delete_files
153 replace="replace: true"
156 collect_var=delete_symlinks
159 symlink_expr=`expr "$1" : '[^=]*=\(.*\)'`
162 symlink_expr='s|-[0-9][0-9\.]*\(-[0-9][0-9]*\)\{0,1\}\.|-latest.|'
165 collect_var=symlink_files
171 echo "gnupload $scriptversion"
179 echo "$0: Unknown option '$1', try '$0 --help'" 1>&2
185 if test -z "$collect_var"; then
188 eval "$collect_var=\"\$$collect_var $1\""
197 echo "Running $* ..."
204 if test -z "$to"; then
205 echo "$0: Missing destination sites" >&2
209 if test -n "$symlink_files"; then
210 x=`echo "$symlink_files" | sed 's/[^ ]//g;s/ //g'`
211 if test -n "$x"; then
212 echo "$0: Odd number of symlink arguments" >&2
218 if test -z "${symlink_files}${delete_files}${delete_symlinks}"; then
219 echo "$0: No file to upload" 1>&2
223 # Make sure all files exist. We don't want to ask
224 # for the passphrase if the script will fail.
227 if test ! -f $file; then
228 echo "$0: Cannot find '$file'" 1>&2
230 elif test -n "$symlink_expr"; then
231 linkname=`echo $file | sed "$symlink_expr"`
232 if test -z "$linkname"; then
233 echo "$0: symlink expression produces empty results" >&2
235 elif test "$linkname" = $file; then
236 echo "$0: symlink expression does not alter file name" >&2
243 # Make sure passphrase is not exported in the environment.
246 # Reset PATH to be sure that echo is a built-in. We will later use
247 # 'echo $passphrase' to output the passphrase, so it is important that
248 # it is a built-in (third-party programs tend to appear in 'ps'
249 # listings with their arguments...).
250 # Remember this script runs with 'set -e', so if echo is not built-in
252 if $dry_run; then :; else
253 PATH=/empty echo -n "Enter GPG passphrase: "
260 if test $# -ne 0; then
263 echo "Signing $file ..."
265 echo "$passphrase" | $dbg $GPG --passphrase-fd 0 -ba -o $file.sig $file
270 # mkdirective DESTDIR BASE FILE STMT
271 # Arguments: See upload, below
275 if test -n "$3"; then
280 cat >${2}.directive<<EOF
283 comment: gnupload v. $scriptversion$stmt
286 echo "File ${2}.directive:"
288 echo "File ${2}.directive:" | sed 's/./-/g'
296 echo "symlink: $1 $2"
302 # upload DEST DESTDIR BASE FILE STMT FILES
304 # DEST Destination site;
305 # DESTDIR Destination directory;
306 # BASE Base name for the directive file;
307 # FILE Name of the file to distribute (may be empty);
308 # STMT Additional statements for the directive file;
309 # FILES List of files to upload.
319 rm -f $base.directive $base.directive.asc
322 mkdirective "$destdir" "$base" "$file" "$stmt"
323 echo "$passphrase" | $dbg $GPG --passphrase-fd 0 --clearsign $base.directive
324 $dbg ncftpput ftp-upload.gnu.org /incoming/alpha $files $base.directive.asc
327 mkdirective "$destdir" "$base" "$file" "$stmt"
328 echo "$passphrase" | $dbg $GPG --passphrase-fd 0 --clearsign $base.directive
329 $dbg ncftpput ftp-upload.gnu.org /incoming/ftp $files $base.directive.asc
332 if test -z "$files"; then
333 echo "$0: warning: standalone directives not applicable for $dest" >&2
335 $dbg ncftpput savannah.gnu.org /incoming/savannah/$destdir $files
337 savannah.nongnu.org:*)
338 if test -z "$files"; then
339 echo "$0: warning: standalone directives not applicable for $dest" >&2
341 $dbg ncftpput savannah.nongnu.org /incoming/savannah/$destdir $files
343 download.gnu.org.ua:alpha/*|download.gnu.org.ua:ftp/*)
344 destdir_p1=`echo "$destdir" | sed 's,^[^/]*/,,'`
345 destdir_topdir=`echo "$destdir" | sed 's,/.*,,'`
346 mkdirective "$destdir_p1" "$base" "$file" "$stmt"
347 echo "$passphrase" | $dbg $GPG --passphrase-fd 0 --clearsign $base.directive
348 for f in $files $base.directive.asc
351 done | $dbg sftp -b - puszcza.gnu.org.ua:/incoming/$destdir_topdir
354 dest_host=`echo "$dest" | sed 's,:.*,,'`
355 mkdirective "$destdir" "$base" "$file" "$stmt"
356 echo "$passphrase" | $dbg $GPG --passphrase-fd 0 --clearsign $base.directive
357 $dbg cp $files $base.directive.asc $dest_host
360 if test -z "$files"; then
361 echo "$0: warning: standalone directives not applicable for $dest" >&2
363 $dbg scp $files $dest
366 rm -f $base.directive $base.directive.asc
370 # Process any standalone directives
372 if test -n "$symlink_files"; then
374 `mksymlink $symlink_files`"
377 for file in $delete_files
383 for file in $delete_symlinks
389 if test -n "$stmt"; then
392 destdir=`echo $dest | sed 's/[^:]*://'`
393 upload "$dest" "$destdir" "`hostname`-$$" "" "$stmt"
397 # Process actual uploads
402 echo "Uploading $file to $dest ..."
405 # allowing file replacement is all or nothing.
406 if test -n "$replace"; then stmt="$stmt
410 files="$file $file.sig"
411 destdir=`echo $dest | sed 's/[^:]*://'`
412 if test -n "$symlink_expr"; then
413 linkname=`echo $file | sed "$symlink_expr"`
415 symlink: $file $linkname
416 symlink: $file.sig $linkname.sig"
418 upload "$dest" "$destdir" "$file" "$file" "$stmt" "$files"
425 # eval: (add-hook 'write-file-hooks 'time-stamp)
426 # time-stamp-start: "scriptversion="
427 # time-stamp-format: "%:y-%02m-%02d.%02H"
428 # time-stamp-time-zone: "UTC"
429 # time-stamp-end: "; # UTC"