2 # Add a new .gnupg home directory for a list of users -*- sh -*-
4 # Copyright 2004 Free Software Foundation, Inc.
6 # This file is free software; as a special exception the author gives
7 # unlimited permission to copy and/or distribute it, with or without
8 # modifications, as long as this notice is preserved.
10 # This file is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
12 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
30 home
=$
(${cat_passwd} |
awk -F: -v n
="$user" '$1 == n {print $6}')
31 if [ -z "$home" ]; then
32 if ${cat_passwd} |
awk -F: -v n
="$user" '$1 == n {exit 1}'; then
33 error
"no such user \`$user'"
35 error
"no home directory for user \`$user'"
39 if [ ! -d "$home" ]; then
40 error
"home directory \`$home' of user \`$user' does not exist"
43 if [ -d "$home/.gnupg" ]; then
44 info
"skipping user \`$user': \`.gnupg' already exists"
47 info
"creating home directory \`$home/.gnupg' for \`$user'"
48 if ! mkdir
"$home/.gnupg" ; then
49 error
"error creating \`$home/.gnupg'"
53 if ! chown
$user "$home/.gnupg" ; then
54 error
"error changing ownership of \`$home/.gnupg'"
58 group
=$
(id
-g "$user")
59 [ -z "$group" ] && group
="0"
61 if [ "$group" -gt 0 ]; then
62 if ! chgrp
$group "$home/.gnupg" ; then
63 error
"error changing group of \`$home/.gnupg'"
68 if ! cd "$home/.gnupg" ; then
69 error
"error cd-ing to \`$home/.gnupg'"
72 for f
in $filelist; do
73 if [ -d /etc
/skel
/.gnupg
/$f ]; then
76 cp /etc
/skel
/.gnupg
/$f $f
78 if ! chown
$user $f ; then
79 error
"error changing ownership of \`$f'"
82 if [ "$group" -gt 0 ]; then
83 if ! chgrp
$group "$f" ; then
84 error
"error changing group of \`$f'"
93 echo "usage: $PGM userids"
97 # Check whether we can use getent
98 if getent
--help </dev
/null
>/dev
/null
2>&1 ; then
99 cat_passwd
='getent passwd'
101 cat_passwd
='cat /etc/passwd'
102 info
"please note that only users from /etc/passwd are checked"
105 if [ ! -d /etc
/skel
/.gnupg
]; then
106 error
"skeleton directory \`/etc/skel/.gnupg' does not exist"
109 cd "/etc/skel/.gnupg" ||
(error
"error cd-ing to \`/etc/skel/.gnupg'"; exit 1)
110 filelist
=$
(find . \
( -type f
-or -type d \
) -not -name '*~' -not -name .
-print)
113 if ! umask 0077 ; then
114 error
"error setting umask"