home *** CD-ROM | disk | FTP | other *** search
/ ftp.muug.mb.ca / 2014.06.ftp.muug.mb.ca.tar / ftp.muug.mb.ca / pub / src / autoalias.shar / addaliases next >
Text File  |  1993-09-20  |  2KB  |  74 lines

  1. #! /bin/sh
  2. #
  3. # addaliases - add entries to /etc/aliases, based on passwd file
  4. #
  5. # Based on mkfnames.sh script from smail2.5 distribution.
  6. #
  7. ALIASES=/etc/aliases            # location of aliases file to update
  8. PASSWD="ypcat passwd"            # command to list passwd file
  9. #PASSWD="cat /etc/passwd"
  10. #PASSWD="nidump passwd /"
  11. NAMEPTX=/usr/local/bin/nameptx        # location of nameptx program
  12. MINUID=30                # minimum allowed uid for real users
  13.  
  14. (
  15. if grep -s '^# DO NOT REMOVE THIS LINE  (addaliases)' $ALIASES
  16. then
  17.     sed '/^# DO NOT REMOVE THIS LINE  (addaliases)/,$d' $ALIASES
  18. else
  19.     cat $ALIASES - <<'!'
  20. ###########################################
  21. # Automatically added local aliases below #
  22. # Do not edit beyond this point           #
  23. !
  24. fi
  25. cat <<'!'
  26. # DO NOT REMOVE THIS LINE  (addaliases)   #
  27. ###########################################
  28. !
  29.  
  30. # Generate aliases for variations on user's full name and initials from
  31. # passwd file GECOS field.  Assumes that full names are in form
  32. # "Firstname Lastname" with optional middle initials.  One space should follow
  33. # each period in initials, and there should be no commas within name.  A comma
  34. # or parenthesis can end the full name if GECOS field has other information.
  35. # This code is taken from support code for smail, and was modified to work 
  36. # on sendmail-style aliases files.
  37.  
  38. echo "# automatic full name aliases, from passwd:"
  39.  
  40. T=/tmp/al$$.t
  41.  
  42. # Strip out dummy userids from passwd file, tack on priorities to
  43. # give user IDs top priority, then full names.
  44. # Ajust awk script as required at your site.
  45. $PASSWD | awk -F: '$2 != "*" && $3 >= '$MINUID' {print}'    |
  46. sed -e 's/^[^:]*/1&::::&::\
  47. 2&/'                |
  48.  
  49. # extract user name and full name fields
  50. sed 's/\(.*\):.*:.*:.*:[0-9]*-*\([^(,:]*\).*:.*:.*/\1    \2/'    |
  51. $NAMEPTX            |    # permute the names
  52. (tee $T; tr . _ < $T; rm $T)    |    # allow _ as well as . separator
  53. #sort -u +0 -1            |
  54. sort | sort -mu +0 -1        |    # sort 1st by whole record,
  55.                     # so priority code recognized
  56. # Strip off priority code, add colon for sendmail aliases,
  57. # strip out too-short names, and redundant definitions (name:    name):
  58. sed -e 's/    [1-9]/:    /' \
  59.     -e '/^.:    /d' -e '/^..:    /d' \
  60.     -e '/[._][a-z]:    /d' \
  61.     -e '/^\([a-z0-9_][a-z0-9_]*\):    \1$/d'
  62. ) > /tmp/aliases.$$
  63.  
  64. mv $ALIASES $ALIASES.bak
  65. mv /tmp/aliases.$$ $ALIASES
  66. chmod 644 $ALIASES
  67.  
  68. if [ -f /var/yp/Makefile ]
  69. then
  70.   echo "Modified $ALIASES.  Run" '"newaliases" and "make aliases" in /var/yp.'
  71. else
  72.   echo "Modified $ALIASES.  Run" '"newaliases".'
  73. fi
  74.