* lib/gnupload: Provide also a simple example.
[automake/plouj.git] / lib / gnupload
blobb90e3ae231224e37ca8fac88162995a9edf846f7
1 #!/bin/sh
2 # Sign files and upload them.
4 scriptversion=2008-04-02.19
6 # Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation
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)
11 # any later version.
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>.
23 set -e
25 GPG='gpg --batch --no-tty'
26 to=
28 usage="Usage: $0 [OPTIONS]... FILES...
30 Sign all FILES, and upload them to selected destinations, according to
31 <http://www.gnu.org/prep/maintain/html_node/Automated-FTP-Uploads.html>.
33 Options:
34 --help print this help text and exit
35 --to DEST specify one destination for FILES
36 (multiple --to options are allowed)
37 --user NAME sign with key NAME
38 --version output version information and exit
40 Recognized destinations are:
41 alpha.gnu.org:DIRECTORY
42 savannah.gnu.org:DIRECTORY
43 savannah.nongnu.org:DIRECTORY
44 ftp.gnu.org:DIRECTORY
45 build directive files and upload files by FTP
46 [user@]host:DIRECTORY upload files with scp
48 Simple single-target single-file examples:
49 gnupload --to alpha.gnu.org:automake automake-1.8.2b.tar.gz
50 gnupload --to ftp.gnu.org:automake automake-1.8.3.tar.gz
52 Multiple-target multiple-file example:
53 gnupload --to sources.redhat.com:~ftp/pub/automake \\
54 --to alpha.gnu.org:automake \\
55 automake-1.8.2b.tar.gz automake-1.8.2b.tar.bz2
57 Report bugs to <bug-automake@gnu.org>.
58 Send patches to <automake-patches@gnu.org>."
60 while test -n "$1"; do
61 case $1 in
62 --help)
63 echo "$usage"
64 exit $?
66 --to)
67 if test -z "$2"; then
68 echo "$0: Missing argument for --to" 1>&2
69 exit 1
70 else
71 to="$to $2"
72 shift 2
75 --user)
76 if test -z "$2"; then
77 echo "$0: Missing argument for --user" 1>&2
78 exit 1
79 else
80 GPG="$GPG --local-user $2"
81 shift 2
84 --version)
85 echo "gnupload $scriptversion"
86 exit $?
88 -*)
89 echo "$0: Unknown option \`$1', try \`$0 --help'" 1>&2
90 exit 1
93 break
95 esac
96 done
98 if test $# = 0; then
99 echo "$0: No file to upload" 1>&2
100 exit 1
101 else
105 # Make sure all files exist. We don't want to ask
106 # for the passphrase if the script will fail.
107 for file
109 if test ! -f $file; then
110 echo "$0: Cannot find \`$file'" 1>&2
111 exit 1
112 else
115 done
117 # Make sure passphrase is not exported in the environment.
118 unset passphrase
120 # Reset PATH to be sure that echo is a built-in. We will later use
121 # `echo $passphrase' to output the passphrase, so it is important that
122 # it is a built-in (third-party programs tend to appear in `ps'
123 # listings with their arguments...).
124 # Remember this script runs with `set -e', so if echo is not built-in
125 # it will exit now.
126 PATH=/empty echo -n "Enter GPG passphrase: "
127 stty -echo
128 read -r passphrase
129 stty echo
130 echo
132 for file
134 echo "Signing $file..."
135 rm -f $file.sig
136 echo $passphrase | $GPG --passphrase-fd 0 -ba -o $file.sig $file
137 done
139 for dest in $to
141 for file
143 echo "Uploading $file to $dest..."
144 files="$file $file.sig"
145 destdir=`echo $dest | sed 's/[^:]*://'`
146 case $dest in
147 alpha.gnu.org:*)
148 rm -f $file.directive $file.directive.asc
149 cat >$file.directive<<EOF
150 version: 1.1
151 directory: $destdir
152 filename: `basename -- "$file"`
154 echo "$passphrase" | $GPG --passphrase-fd 0 --clearsign $file.directive
155 ncftpput ftp-upload.gnu.org /incoming/alpha $files $file.directive.asc
156 rm -f $file.directive $file.directive.asc
158 ftp.gnu.org:*)
159 rm -f $file.directive $file.directive.asc
160 cat >$file.directive<<EOF
161 version: 1.1
162 directory: $destdir
163 filename: `basename -- "$file"`
165 echo "$passphrase" | $GPG --passphrase-fd 0 --clearsign $file.directive
166 ncftpput ftp-upload.gnu.org /incoming/ftp $files $file.directive.asc
167 rm -f $file.directive $file.directive.asc
169 savannah.gnu.org:*)
170 ncftpput savannah.gnu.org /incoming/savannah/$destdir $files
172 savannah.nongnu.org:*)
173 ncftpput savannah.nongnu.org /incoming/savannah/$destdir $files
176 scp $files $dest
178 esac
179 done
180 done
182 # Local variables:
183 # eval: (add-hook 'write-file-hooks 'time-stamp)
184 # time-stamp-start: "scriptversion="
185 # time-stamp-format: "%:y-%02m-%02d.%02H"
186 # time-stamp-end: "$"
187 # End: