| 1 | #!/bin/sh
|
|---|
| 2 | # Sign files and upload them.
|
|---|
| 3 |
|
|---|
| 4 | scriptversion=2005-05-14.22
|
|---|
| 5 |
|
|---|
| 6 | # Copyright (C) 2004, 2005 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 <[email protected]>.
|
|---|
| 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.
|
|---|
| 33 |
|
|---|
| 34 | Options:
|
|---|
| 35 | --help print this help text and exit
|
|---|
| 36 | --to DEST specify one destination for FILES
|
|---|
| 37 | (multiple --to options are allowed)
|
|---|
| 38 | --user NAME sign with key NAME
|
|---|
| 39 | --version output version information and exit
|
|---|
| 40 |
|
|---|
| 41 | Recognized destinations are:
|
|---|
| 42 | alpha.gnu.org:DIRECTORY build directive files and upload files by FTP
|
|---|
| 43 | ftp.gnu.org:DIRECTORY build directive files and upload files by FTP
|
|---|
| 44 | [user@]host:DIRECTORY upload files with scp
|
|---|
| 45 |
|
|---|
| 46 | Example:
|
|---|
| 47 | gnupload --to sources.redhat.com:~ftp/pub/automake \\
|
|---|
| 48 | --to alpha.gnu.org:automake \\
|
|---|
| 49 | automake-1.8.2b.tar.gz automake-1.8.2b.tar.bz2
|
|---|
| 50 |
|
|---|
| 51 | Report bugs to <[email protected]>.
|
|---|
| 52 | Send patches to <[email protected]>."
|
|---|
| 53 |
|
|---|
| 54 | while test -n "$1"; do
|
|---|
| 55 | case $1 in
|
|---|
| 56 | --help)
|
|---|
| 57 | echo "$usage"
|
|---|
| 58 | exit $?
|
|---|
| 59 | ;;
|
|---|
| 60 | --to)
|
|---|
| 61 | if test -z "$2"; then
|
|---|
| 62 | echo "$0: Missing argument for --to" 1>&2
|
|---|
| 63 | exit 1
|
|---|
| 64 | else
|
|---|
| 65 | to="$to $2"
|
|---|
| 66 | shift 2
|
|---|
| 67 | fi
|
|---|
| 68 | ;;
|
|---|
| 69 | --user)
|
|---|
| 70 | if test -z "$2"; then
|
|---|
| 71 | echo "$0: Missing argument for --user" 1>&2
|
|---|
| 72 | exit 1
|
|---|
| 73 | else
|
|---|
| 74 | GPG="$GPG --local-user $2"
|
|---|
| 75 | shift 2
|
|---|
| 76 | fi
|
|---|
| 77 | ;;
|
|---|
| 78 | --version)
|
|---|
| 79 | echo "gnupload $scriptversion"
|
|---|
| 80 | exit $?
|
|---|
| 81 | ;;
|
|---|
| 82 | -*)
|
|---|
| 83 | echo "$0: Unknown option \`$1', try \`$0 --help'" 1>&2
|
|---|
| 84 | exit 1
|
|---|
| 85 | ;;
|
|---|
| 86 | *)
|
|---|
| 87 | break
|
|---|
| 88 | ;;
|
|---|
| 89 | esac
|
|---|
| 90 | done
|
|---|
| 91 |
|
|---|
| 92 | if test $# = 0; then
|
|---|
| 93 | echo "$0: No file to upload" 1>&2
|
|---|
| 94 | exit 1
|
|---|
| 95 | else
|
|---|
| 96 | :
|
|---|
| 97 | fi
|
|---|
| 98 |
|
|---|
| 99 | # Make sure all files exist. We don't want to ask
|
|---|
| 100 | # for the passphrase if the script will fail.
|
|---|
| 101 | for file;
|
|---|
| 102 | do
|
|---|
| 103 | if test ! -f $file; then
|
|---|
| 104 | echo "$0: Cannot find \`$file'" 1>&2
|
|---|
| 105 | exit 1
|
|---|
| 106 | else
|
|---|
| 107 | :
|
|---|
| 108 | fi
|
|---|
| 109 | done
|
|---|
| 110 |
|
|---|
| 111 | # Make sure passphrase is not exported in the environment.
|
|---|
| 112 | unset passphrase
|
|---|
| 113 |
|
|---|
| 114 | # Reset PATH to be sure that echo is a built-in. We will later use
|
|---|
| 115 | # `echo $passphrase' to output the passphrase, so it is important that
|
|---|
| 116 | # it is a built-in (third-party programs tend to appear in `ps'
|
|---|
| 117 | # listings with their arguments...).
|
|---|
| 118 | # Remember this script runs with `set -e', so if echo is not built-in
|
|---|
| 119 | # it will exit now.
|
|---|
| 120 | PATH=/empty echo -n "Enter GPG passphrase: "
|
|---|
| 121 | stty -echo
|
|---|
| 122 | read -r passphrase
|
|---|
| 123 | stty echo
|
|---|
| 124 | echo
|
|---|
| 125 |
|
|---|
| 126 | for file;
|
|---|
| 127 | do
|
|---|
| 128 | echo "Signing $file..."
|
|---|
| 129 | rm -f $file.sig
|
|---|
| 130 | echo $passphrase | $GPG --passphrase-fd 0 -ba -o $file.sig $file
|
|---|
| 131 | done
|
|---|
| 132 |
|
|---|
| 133 | for dest in $to;
|
|---|
| 134 | do
|
|---|
| 135 | for file;
|
|---|
| 136 | do
|
|---|
| 137 | echo "Uploading $file to $dest..."
|
|---|
| 138 | files="$file $file.sig"
|
|---|
| 139 | case $dest in
|
|---|
| 140 | alpha.gnu.org:*)
|
|---|
| 141 | rm -f $file.directive $file.directive.asc
|
|---|
| 142 | echo directory: `echo $dest | sed 's/[^:]*://'` >$file.directive
|
|---|
| 143 | echo "$passphrase" | $GPG --passphrase-fd 0 --clearsign $file.directive
|
|---|
| 144 | ncftpput ftp-upload.gnu.org /incoming/alpha $files $file.directive.asc
|
|---|
| 145 | rm -f $file.directive $file.directive.asc
|
|---|
| 146 | ;;
|
|---|
| 147 | ftp.gnu.org:*)
|
|---|
| 148 | rm -f $file.directive $file.directive.asc
|
|---|
| 149 | echo directory: `echo $dest | sed 's/[^:]*://'` >$file.directive
|
|---|
| 150 | echo "$passphrase" | $GPG --passphrase-fd 0 --clearsign $file.directive
|
|---|
| 151 | ncftpput ftp-upload.gnu.org /incoming/ftp $files $file.directive.asc
|
|---|
| 152 | rm -f $file.directive $file.directive.asc
|
|---|
| 153 | ;;
|
|---|
| 154 | *)
|
|---|
| 155 | scp $files $dest
|
|---|
| 156 | ;;
|
|---|
| 157 | esac
|
|---|
| 158 | done
|
|---|
| 159 | done
|
|---|
| 160 |
|
|---|
| 161 | # Local variables:
|
|---|
| 162 | # eval: (add-hook 'write-file-hooks 'time-stamp)
|
|---|
| 163 | # time-stamp-start: "scriptversion="
|
|---|
| 164 | # time-stamp-format: "%:y-%02m-%02d.%02H"
|
|---|
| 165 | # time-stamp-end: "$"
|
|---|
| 166 | # End:
|
|---|