Revisit the condition when to use multibyte parsing in strftime.
[gnulib.git] / build-aux / gnupload
1 #!/bin/sh
2 # Sign files and upload them.
3
4 scriptversion=2008-11-12.21
5
6 # Copyright (C) 2004, 2005, 2006, 2007, 2008  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 delete=false
28
29 usage="Usage: $0 [OPTIONS]... FILES...
30
31 Sign all FILES, and upload them to (or delete them from) selected
32 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   --delete                 delete FILES from destination instead of uploading
41   --version                output version information and exit
42
43 Recognized destinations are:
44   alpha.gnu.org:DIRECTORY
45   savannah.gnu.org:DIRECTORY
46   savannah.nongnu.org:DIRECTORY
47   ftp.gnu.org:DIRECTORY
48                            build directive files and upload files by FTP
49   [user@]host:DIRECTORY    upload files with scp
50
51 Deletion only works for ftp.gnu.org and alpha.gnu.org (using the
52 archive: directive).  Otherwise it is a no-op.  Deleting a file foo also
53 deletes foo.sig; do not specify the .sig explicitly.
54
55 Simple single-target single-file examples:
56   gnupload --to alpha.gnu.org:automake automake-1.8.2b.tar.gz
57   gnupload --to ftp.gnu.org:automake automake-1.8.3.tar.gz
58   gnupload --to alpha.gnu.org:automake --delete automake-oops.tar.gz
59
60 Multiple-target multiple-file example:
61   gnupload --to sources.redhat.com:~ftp/pub/automake \\
62            --to alpha.gnu.org:automake \\
63            automake-1.8.2b.tar.gz automake-1.8.2b.tar.bz2
64
65 Report bugs to <bug-automake@gnu.org>.
66 Send patches to <automake-patches@gnu.org>."
67
68 while test -n "$1"; do
69   case $1 in
70     --delete)
71       delete=true
72       shift
73       ;;
74     --help)
75       echo "$usage"
76       exit $?
77       ;;
78     --to)
79       if test -z "$2"; then
80         echo "$0: Missing argument for --to" 1>&2
81         exit 1
82       else
83         to="$to $2"
84         shift 2
85       fi
86       ;;
87     --user)
88       if test -z "$2"; then
89         echo "$0: Missing argument for --user" 1>&2
90         exit 1
91       else
92         GPG="$GPG --local-user $2"
93         shift 2
94       fi
95       ;;
96     --version)
97       echo "gnupload $scriptversion"
98       exit $?
99       ;;
100     -*)
101       echo "$0: Unknown option \`$1', try \`$0 --help'" 1>&2
102       exit 1
103       ;;
104     *)
105       break
106       ;;
107   esac
108 done
109
110 if test $# = 0; then
111   echo "$0: No file to upload or delete" 1>&2
112   exit 1
113 else
114   :
115 fi
116
117 if $delete; then :; else
118   # Make sure all files exist.  We don't want to ask
119   # for the passphrase if the script will fail.
120   for file
121   do
122     if test ! -f $file; then
123       echo "$0: Cannot find \`$file'" 1>&2
124       exit 1
125     else
126       :
127     fi
128   done
129 fi
130
131 # Make sure passphrase is not exported in the environment.
132 unset passphrase
133
134 # Reset PATH to be sure that echo is a built-in.  We will later use
135 # `echo $passphrase' to output the passphrase, so it is important that
136 # it is a built-in (third-party programs tend to appear in `ps'
137 # listings with their arguments...).
138 # Remember this script runs with `set -e', so if echo is not built-in
139 # it will exit now.
140 PATH=/empty echo -n "Enter GPG passphrase: "
141 stty -echo
142 read -r passphrase
143 stty echo
144 echo
145
146 # Nothing to sign if deleting.
147 if $delete; then :; else
148   for file
149   do
150     echo "Signing $file..."
151     rm -f $file.sig
152     echo $passphrase | $GPG --passphrase-fd 0 -ba -o $file.sig $file
153   done
154 fi
155
156 for dest in $to
157 do
158   for file
159   do
160     # Prepare arguments.
161     if $delete; then
162       echo "Removing $file from $dest..."
163       files=  # nothing to upload if deleting
164       directive="archive: $file"
165     else
166       echo "Uploading $file to $dest..."
167       files="$file $file.sig"
168       directive="filename: "`basename -- "$file"`
169     fi
170     destdir=`echo $dest | sed 's/[^:]*://'`
171
172     case $dest in
173       alpha.gnu.org:*)
174         rm -f $file.directive $file.directive.asc
175         cat >$file.directive<<EOF
176 version: 1.1
177 directory: $destdir
178 $directive
179 EOF
180         echo "$passphrase" | $GPG --passphrase-fd 0 --clearsign $file.directive
181         ncftpput ftp-upload.gnu.org /incoming/alpha $files $file.directive.asc
182         rm -f $file.directive $file.directive.asc
183         ;;
184       ftp.gnu.org:*)
185         rm -f $file.directive $file.directive.asc
186         cat >$file.directive<<EOF
187 version: 1.1
188 directory: $destdir
189 $directive
190 EOF
191         echo "$passphrase" | $GPG --passphrase-fd 0 --clearsign $file.directive
192         ncftpput ftp-upload.gnu.org /incoming/ftp $files $file.directive.asc
193         rm -f $file.directive $file.directive.asc
194         ;;
195       savannah.gnu.org:*)
196         # We only know how to implement delete for {ftp,alpha}.gnu.org.
197         $delete \
198         || ncftpput savannah.gnu.org /incoming/savannah/$destdir $files
199         ;;
200       savannah.nongnu.org:*)
201         $delete \
202         || ncftpput savannah.nongnu.org /incoming/savannah/$destdir $files
203         ;;
204       *)
205         $delete \
206         || scp $files $dest
207         ;;
208     esac
209   done
210 done
211
212 # Local variables:
213 # eval: (add-hook 'write-file-hooks 'time-stamp)
214 # time-stamp-start: "scriptversion="
215 # time-stamp-format: "%:y-%02m-%02d.%02H"
216 # time-stamp-end: "$"
217 # End: