chiark / gitweb /
gnupg2 (2.1.17-3) unstable; urgency=medium
[gnupg2.git] / tools / gpg-zip.in
1 #!/bin/sh
2
3 # gpg-archive - gpg-ized tar using the same format as PGP's PGP Zip.
4 # Copyright (C) 2005 Free Software Foundation, Inc.
5 #
6 # This file is part of GnuPG.
7 #
8 # GnuPG 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 of the License, or
11 # (at your option) any later version.
12 #
13 # GnuPG 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 # Despite the name, PGP Zip format is actually an OpenPGP-wrapped tar
21 # file.  To be compatible with PGP itself, this must be a USTAR format
22 # tar file.  Unclear on whether there is a distinction here between
23 # the GNU or POSIX variant of USTAR.
24
25 VERSION=@VERSION@
26 TAR=@TAR@
27 GPG=gpg
28
29 usage="\
30 Usage: gpg-zip [--help] [--version] [--encrypt] [--decrypt] [--symmetric]
31        [--list-archive] [--output FILE] [--gpg GPG] [--gpg-args ARGS]
32        [--tar TAR] [--tar-args ARGS] filename1 [filename2, ...]
33        directory1 [directory2, ...]
34
35 Encrypt or sign files into an archive."
36
37 tar_verbose_opt="v"
38
39 while test $# -gt 0 ; do
40   case $1 in
41     -h | --help | --h*)
42       echo "$usage"
43       exit 0
44       ;;
45     --list-archive)
46       list=yes
47       create=no
48       unpack=no
49       shift
50       ;;
51     --encrypt | -e)
52       gpg_args="$gpg_args --encrypt"
53       list=no
54       create=yes
55       unpack=no
56       shift
57       ;;
58     --decrypt | -d)
59       gpg_args="$gpg_args --decrypt"
60       list=no
61       create=no
62       unpack=yes
63       shift
64       ;;
65     --symmetric | -c)
66       gpg_args="$gpg_args --symmetric"
67       list=no
68       create=yes
69       unpack=no
70       shift
71       ;;
72     --sign | -s)
73       gpg_args="$gpg_args --sign"
74       list=no
75       create=yes
76       unpack=no
77       shift
78       ;;
79     --recipient | -r)
80       gpg_args="$gpg_args --recipient $2"
81       shift
82       shift
83       ;;
84     --local-user | -u)
85       gpg_args="$gpg_args --local-user $2"
86       shift
87       shift
88       ;;
89     --output | -o)
90       gpg_args="$gpg_args --output $2"
91       shift
92       shift
93       ;;
94     --version)
95       echo "gpg-zip (GnuPG) $VERSION"
96       exit 0
97       ;;
98     --gpg)
99       GPG=$2
100       shift
101       shift
102       ;;
103     --gpg-args)
104       gpg_args="$gpg_args $2"
105       shift
106       shift
107       ;;
108     --tar)
109       TAR=$2
110       shift
111       shift
112       ;;
113     --tar-args)
114       tar_args="$tar_args $2"
115       shift
116       shift
117       ;;
118     --quiet)
119       tar_verbose_opt=""
120       shift
121       ;;
122     --)
123       shift
124       break
125       ;;
126     -*)
127       echo "$usage" 1>&2
128       exit 1
129       ;;
130     *)
131       break
132       ;;
133   esac
134 done
135
136 if test x$create = xyes ; then
137 #   echo "$TAR $tar_args -cf - "$@" | $GPG --set-filename x.tar $gpg_args" 1>&2
138    $TAR $tar_args -cf - "$@" | $GPG --set-filename x.tar $gpg_args
139 elif test x$list = xyes ; then
140 #   echo "cat \"$1\" | $GPG $gpg_args | $TAR $tar_args -tf -" 1>&2
141    cat "$1" | $GPG $gpg_args | $TAR $tar_args -tf -
142 elif test x$unpack = xyes ; then
143 #   echo "cat \"$1\" | $GPG $gpg_args | $TAR $tar_args -xvf -" 1>&2
144    cat "$1" | $GPG $gpg_args | $TAR $tar_args -x${tar_verbose_opt}f -
145 else
146    echo "$usage" 1>&2
147    exit 1
148 fi