Sync from Automake.
[gnulib.git] / build-aux / gnupload
1 #!/bin/sh
2 # Sign files and upload them.
3
4 scriptversion=2006-11-12.11
5
6 # Copyright (C) 2004, 2005, 2006  Free Software Foundation
7 #
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)
11 # any later version.
12 #
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.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 # 02110-1301, USA.
22
23 # Originally written by Alexandre Duret-Lutz <adl@gnu.org>.
24
25 set -e
26
27 GPG='/usr/bin/gpg --batch --no-tty'
28 to=
29
30 usage="Usage: $0 [OPTIONS]... FILES...
31
32 Sign all FILES, and upload them to selected destinations, according to
33 <http://www.gnu.org/prep/maintain/html_node/Automated-FTP-Uploads.html>.
34
35 Options:
36   --help                   print this help text and exit
37   --to DEST                specify one destination for FILES
38                            (multiple --to options are allowed)
39   --user NAME              sign with key NAME
40   --version                output version information and exit
41
42 Recognized destinations are:
43   alpha.gnu.org:DIRECTORY
44   savannah.gnu.org:DIRECTORY
45   savannah.nongnu.org:DIRECTORY
46   ftp.gnu.org:DIRECTORY
47                            build directive files and upload files by FTP
48   [user@]host:DIRECTORY    upload files with scp
49
50 Example:
51   gnupload --to sources.redhat.com:~ftp/pub/automake \\
52            --to alpha.gnu.org:automake \\
53            automake-1.8.2b.tar.gz automake-1.8.2b.tar.bz2
54
55 Report bugs to <bug-automake@gnu.org>.
56 Send patches to <automake-patches@gnu.org>."
57
58 while test -n "$1"; do
59   case $1 in
60     --help)
61       echo "$usage"
62       exit $?
63       ;;
64     --to)
65       if test -z "$2"; then
66         echo "$0: Missing argument for --to" 1>&2
67         exit 1
68       else
69         to="$to $2"
70         shift 2
71       fi
72       ;;
73     --user)
74       if test -z "$2"; then
75         echo "$0: Missing argument for --user" 1>&2
76         exit 1
77       else
78         GPG="$GPG --local-user $2"
79         shift 2
80       fi
81       ;;
82     --version)
83       echo "gnupload $scriptversion"
84       exit $?
85       ;;
86     -*)
87       echo "$0: Unknown option \`$1', try \`$0 --help'" 1>&2
88       exit 1
89       ;;
90     *)
91       break
92       ;;
93   esac
94 done
95
96 if test $# = 0; then
97   echo "$0: No file to upload" 1>&2
98   exit 1
99 else
100   :
101 fi
102
103 # Make sure all files exist.  We don't want to ask
104 # for the passphrase if the script will fail.
105 for file;
106 do
107   if test ! -f $file; then
108     echo "$0: Cannot find \`$file'" 1>&2
109     exit 1
110   else
111     :
112   fi
113 done
114
115 # Make sure passphrase is not exported in the environment.
116 unset passphrase
117
118 # Reset PATH to be sure that echo is a built-in.  We will later use
119 # `echo $passphrase' to output the passphrase, so it is important that
120 # it is a built-in (third-party programs tend to appear in `ps'
121 # listings with their arguments...).
122 # Remember this script runs with `set -e', so if echo is not built-in
123 # it will exit now.
124 PATH=/empty echo -n "Enter GPG passphrase: "
125 stty -echo
126 read -r passphrase
127 stty echo
128 echo
129
130 for file;
131 do
132   echo "Signing $file..."
133   rm -f $file.sig
134   echo $passphrase | $GPG --passphrase-fd 0 -ba -o $file.sig $file
135 done
136
137 for dest in $to;
138 do
139   for file;
140   do
141     echo "Uploading $file to $dest..."
142     files="$file $file.sig"
143     destdir=`echo $dest | sed 's/[^:]*://'`
144     case $dest in
145       alpha.gnu.org:*)
146         rm -f $file.directive $file.directive.asc
147         cat >$file.directive<<EOF
148 version: 1.1
149 directory: $destdir
150 filename: $file
151 EOF
152         echo "$passphrase" | $GPG --passphrase-fd 0 --clearsign $file.directive
153         ncftpput ftp-upload.gnu.org /incoming/alpha $files $file.directive.asc
154         rm -f $file.directive $file.directive.asc
155         ;;
156       ftp.gnu.org:*)
157         rm -f $file.directive $file.directive.asc
158         cat >$file.directive<<EOF
159 version: 1.1
160 directory: $destdir
161 filename: $file
162 EOF
163         echo "$passphrase" | $GPG --passphrase-fd 0 --clearsign $file.directive
164         ncftpput ftp-upload.gnu.org /incoming/ftp $files $file.directive.asc
165         rm -f $file.directive $file.directive.asc
166         ;;
167       savannah.gnu.org:*)
168         ncftpput savannah.gnu.org /incoming/savannah/$destdir $files
169         ;;
170       savannah.nongnu.org:*)
171         ncftpput savannah.nongnu.org /incoming/savannah/$destdir $files
172         ;;
173       *)
174         scp $files $dest
175         ;;
176     esac
177   done
178 done
179
180 # Local variables:
181 # eval: (add-hook 'write-file-hooks 'time-stamp)
182 # time-stamp-start: "scriptversion="
183 # time-stamp-format: "%:y-%02m-%02d.%02H"
184 # time-stamp-end: "$"
185 # End: