2 # Apply defaults from /etc/gnupg/gpg.conf to all users -*- sh -*-
4 # Copyright 2007 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.
14 PGM=applygnupgdefaults
19 [ -n "$errorfile" ] && echo "$PGM: $*" >>$errorfile
27 echo "usage: $PGM" >&2
34 [ -n "$errorfile" -a -f "$errorfile" ] && rm "$errorfile"
36 trap cleanup EXIT SIGINT SIGHUP SIGPIPE
37 errorfile=$(mktemp "/tmp/$PGM.log.XXXXXX")
38 [ -n "$errorfile" -a -f "$errorfile" ] || exit 2
40 # Check whether we can use getent
41 if getent --help </dev/null >/dev/null 2>&1 ; then
42 cat_passwd='getent passwd'
44 cat_passwd='cat /etc/passwd'
45 info "please note that only users from /etc/passwd are processed"
48 if [ ! -f /etc/gnupg/gpgconf.conf ]; then
49 error "global configuration file \`/etc/gnupg/gpgconf.conf' does not exist"
52 if [ ! -f /etc/shells ]; then
53 error "missing file \`/etc/shells'"
57 if [ $(id -u) -ne 0 ]; then
58 error "needs to be run as root"
63 | while IFS=: read -r user dmy_a uid dmy_c dmy_d home shell dmy_rest; do
64 # Process only entries with a valid login shell
65 grep </etc/shells "^$shell" 2>/dev/null >/dev/null || continue
66 # and with an pre-existing gnupg home directory
67 [ -d "$home/.gnupg" ] || continue
69 [ "${uid:-0}" -eq 0 ] && continue
70 info "running \"gpgconf --apply-defaults\" for $user"
72 -c 'gpgconf --apply-defaults && echo SUCCESS' $user \
73 | tail -1 | grep ^SUCCESS >/dev/null ; then
76 error "failed to update gnupg defaults for $user"
80 [ "$(wc -c <$errorfile)" -gt 0 ] && exit 1