| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | # Apply defaults from /etc/gnupg/gpgconf.conf to all users -*- sh -*- |
| 3 | # |
| 4 | # Copyright 2007 Free Software Foundation, Inc. |
| 5 | # |
| 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. |
| 9 | # |
| 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. |
| 13 | |
| 14 | PGM=applygnupgdefaults |
| 15 | errorfile= |
| 16 | |
| 17 | errorscip-shell shell shell-project 0.0.0 error(). () { |
| 18 | echoscip-shell system . . echo. "$PGM: $*" >&2 |
| 19 | [scip-shell system . . `[`. -n "$errorfile" ] && echoscip-shell system . . echo. "$PGM: $*" >>$errorfile |
| 20 | } |
| 21 | |
| 22 | infoscip-shell shell shell-project 0.0.0 info(). () { |
| 23 | echoscip-shell system . . echo. "$PGM: $*" >&2 |
| 24 | } |
| 25 | |
| 26 | if [scip-shell system . . `[`. -n "$1" ]; then |
| 27 | echoscip-shell system . . echo. "usage: $PGM" >&2 |
| 28 | exit 1 |
| 29 | fi |
| 30 | |
| 31 | # Cleanup on exit |
| 32 | cleanupscip-shell shell shell-project 0.0.0 cleanup(). () |
| 33 | { |
| 34 | [scip-shell system . . `[`. -n "$errorfile" -a -f "$errorfile" ] && rmscip-shell system . . rm. "$errorfile" |
| 35 | } |
| 36 | trap cleanup EXIT SIGINT SIGHUP SIGPIPE |
| 37 | errorfile=$(mktempscip-shell system . . mktemp. "/tmp/$PGM.log.XXXXXX") |
| 38 | [scip-shell system . . `[`. -n "$errorfile" -a -f "$errorfile" ] || exit 2 |
| 39 | |
| 40 | # Check whether we can use getent |
| 41 | if getentscip-shell system . . getent. --help </dev/nullscip-shell filesystem . . `/dev/null`. >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 ; then |
| 42 | cat_passwd='getent passwd' |
| 43 | else |
| 44 | cat_passwd='cat /etc/passwd' |
| 45 | infoscip-shell shell shell-project 0.0.0 info(). "please note that only users from /etc/passwd are processed" |
| 46 | fi |
| 47 | |
| 48 | if [scip-shell system . . `[`. ! -f /etc/gnupg/gpgconf.confscip-shell filesystem . . `/etc/gnupg/gpgconf.conf`. ]; then |
| 49 | errorscip-shell shell shell-project 0.0.0 error(). "global configuration file \`/etc/gnupg/gpgconf.conf' does not exist" |
| 50 | exit 1 |
| 51 | fi |
| 52 | if [scip-shell system . . `[`. ! -f /etc/shellsscip-shell filesystem . . `/etc/shells`. ]; then |
| 53 | errorscip-shell shell shell-project 0.0.0 error(). "missing file \`/etc/shells'" |
| 54 | exit 1 |
| 55 | fi |
| 56 | |
| 57 | if [scip-shell system . . `[`. $(idscip-shell system . . id. -u) -ne 0 ]; then |
| 58 | errorscip-shell shell shell-project 0.0.0 error(). "needs to be run as root" |
| 59 | exit 1 |
| 60 | fi |
| 61 | |
| 62 | ${cat_passwd} \ |
| 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 | grepscip-shell system . . grep. </etc/shellsscip-shell filesystem . . `/etc/shells`. "^$shell" 2>/dev/nullscip-shell filesystem . . `/dev/null`. >/dev/nullscip-shell filesystem . . `/dev/null`. || continue |
| 66 | # and with an pre-existing gnupg home directory |
| 67 | [scip-shell system . . `[`. -d "$home/.gnupg" ] || continue |
| 68 | # but not root |
| 69 | [scip-shell system . . `[`. "${uid:-0}" -eq 0 ] && continue |
| 70 | infoscip-shell shell shell-project 0.0.0 info(). "running \"gpgconf --apply-defaults\" for $user" |
| 71 | if suscip-shell system . . su. -l -s /bin/shscip-shell filesystem . . `/bin/sh`. \ |
| 72 | -c 'gpgconf --apply-defaults && echo SUCCESS' $user \ |
| 73 | | tailscip-shell system . . tail. -1 | grepscip-shell system . . grep. ^SUCCESS >/dev/nullscip-shell filesystem . . `/dev/null`. ; then |
| 74 | : |
| 75 | else |
| 76 | errorscip-shell shell shell-project 0.0.0 error(). "failed to update gnupg defaults for $user" |
| 77 | fi |
| 78 | done |
| 79 | |
| 80 | [scip-shell system . . `[`. "$(wcscip-shell system . . wc. -c <$errorfile)" -gt 0 ] && exit 1 |
| 81 | exit 0 |