1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#!/bin/sh
# Execute a command in an environment which encrypts, decrypts, and
# verifies files on demand.
#
# Copyright (C) 2016 Free Software Foundation, Inc.
#
# This file is part of the GNU Hurd.
#
# The GNU Hurd is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2, or (at
# your option) any later version.
#
# The GNU Hurd is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
USAGE="Usage:
[gpg-env] encrypt for RECIPIENT [RECIPIENT...] -- [OPTION...] [COMMAND...]
[gpg-env] encrypt with password [OPTION...] [COMMAND...]
[gpg-env] decrypt [OPTION...] [COMMAND...]
[gpg-env] decrypt with password [OPTION...] [COMMAND...]
[gpg-env] verify [OPTION...] [COMMAND...]"
DOC="Execute COMMAND in an environment where files are automatically
encrypted, decrypted and verified."
help()
{
[ "$1" ] && echo "$1
"
echo "$USAGE"
echo ""
echo "$DOC"
echo ""
echo " -?, --help Give this help list"
echo " --usage Give a short usage message"
echo " -V, --version Print program version"
[ "$1" ] && exit 1 || exit 0
}
if [ "$(basename $0)" = "gpg-env.sh" ] \
|| [ "$(basename $0)" = "gpg-env" ]; then
ACTION="$1"
if [ ! "$ACTION" ]; then
help "No action given."
fi
shift
else
ACTION="$(basename $0)"
fi
case "$ACTION" in
"encrypt") ;;
"decrypt") ;;
"verify") ;;
*)
help "Invalid action '$ACTION'."
esac
ENCRYPT=""
if [ "$ACTION" = "encrypt" ]; then
if [ "$1" = "with" ] && [ "$2" = "password" ]; then
ENCRYPT="--symmetric"
shift 2
elif [ "$1" = "for" ]; then
shift
while [ "$#" -gt 0 ] && [ "x$1" != "x--" ]; do
ENCRYPT="$ENCRYPT --recipient $1"
shift
done
if [ "$ENCRYPT" = "" ]; then
echo "No recipients given."
exit 1
fi
if [ "x$1" = "x--" ]; then
shift
elif [ "$#" -eq 0 ]; then
# it's ok if there are no more arguments
:
else
echo "Recipient list must be terminated using '--'."
exit 1
fi
fi
fi
while [ "$#" -gt 0 ]; do
case "$1" in
--help|"-?")
help
;;
--usage)
echo "$USAGE"
echo "Options: [-V?] [--help] [--usage] [--version]"
exit 0;;
--version|-V)
echo "STANDARD_HURD_VERSION_gpg-env_"; exit 0;;
--)
shift
break
;;
*)
break
esac
done
if [ $# -eq 0 ]; then
set -- ${SHELL:-/bin/sh}
fi
# We exec settrans, which execs the target command in the chroot
# context provided by /hurd/gpg.
exec /bin/settrans \
--chroot-chdir "$PWD" \
--chroot "$@" -- \
/ /hurd/gpg $ENCRYPT
|