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