home *** CD-ROM | disk | FTP | other *** search
/ tusportal.tus.k12.pa.us / tusportal.tus.k12.pa.us.tar / tusportal.tus.k12.pa.us / Wyse / latest-image.raw / 0.img / usr / sbin / applygnupgdefaults < prev    next >
Text File  |  2009-03-19  |  2KB  |  84 lines

  1. #!/bin/sh                                               
  2. # Apply defaults from/etc/gnupg/gpg.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. error () {
  18.   echo "$PGM: $*" >&2
  19.   echo "$PGM: $*" >>$errorfile
  20. }
  21.  
  22. info () {
  23.   echo "$PGM: $*" >&2
  24. }
  25.  
  26. if [ -n "$1" ]; then 
  27.     echo "usage: $PGM" >&2
  28.     exit 1
  29. fi
  30.  
  31. # Cleanup on exit
  32. cleanup ()
  33. {
  34.     [ -n "$errorfile" -a -f "$errorfile" ] && rm "$errorfile"
  35. }
  36. trap cleanup EXIT SIGINT SIGHUP SIGPIPE
  37. errorfile="/tmp/$PGM.$$.log"
  38. : >$errorfile
  39.  
  40.  
  41. # Check whether we can use getent
  42. if getent --help </dev/null >/dev/null 2>&1 ; then
  43.     cat_passwd='getent passwd'
  44. else
  45.     cat_passwd='cat /etc/passwd'
  46.     info "please note that only users from /etc/passwd are processed"
  47. fi
  48.  
  49. if [ ! -f /etc/gnupg/gpgconf.conf ]; then
  50.     error "global configuration file \`/etc/gnupg/gpgconf.conf' does not exist"
  51.     exit 1
  52. fi
  53. if [ ! -f /etc/shells ]; then
  54.     error "missing file \`/etc/shells'"
  55.     exit 1
  56. fi
  57.  
  58. if [ $(id -u) -ne 0 ]; then
  59.     error "needs to be run as root"
  60.     exit 1
  61. fi
  62.  
  63. ${cat_passwd} \
  64.   | while IFS=: read -r user dmy_a uid dmy_c dmy_d home shell dmy_rest; do
  65.     # Process only entires with a valid login shell
  66.     grep </etc/shells "^$shell" 2>/dev/null >/dev/null || continue
  67.     # and with an existant gnupg home directory
  68.     [ -d "$home/.gnupg" ] || continue
  69.     # but not root
  70.     [ "${uid:-0}" -eq 0 ] && continue
  71.     info "running \"gpgconf --apply-defaults\" for $user"
  72.     if su -l -s /bin/sh \
  73.        -c 'gpgconf --apply-defaults && echo SUCCESS' $user \
  74.        | tail -1 | grep ^SUCCESS >/dev/null ; then
  75.       :
  76.     else
  77.       error "failed to update gnupg defaults for $user"
  78.     fi
  79. done
  80.  
  81. [ "$(wc -c <$errorfile)" -gt 0 ] && exit 1
  82. exit 0
  83.  
  84.