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 >
Wrap
Text File
|
1993-09-20
|
2KB
|
74 lines
#! /bin/sh
#
# addaliases - add entries to /etc/aliases, based on passwd file
#
# Based on mkfnames.sh script from smail2.5 distribution.
#
ALIASES=/etc/aliases # location of aliases file to update
PASSWD="ypcat passwd" # command to list passwd file
#PASSWD="cat /etc/passwd"
#PASSWD="nidump passwd /"
NAMEPTX=/usr/local/bin/nameptx # location of nameptx program
MINUID=30 # minimum allowed uid for real users
(
if grep -s '^# DO NOT REMOVE THIS LINE (addaliases)' $ALIASES
then
sed '/^# DO NOT REMOVE THIS LINE (addaliases)/,$d' $ALIASES
else
cat $ALIASES - <<'!'
###########################################
# Automatically added local aliases below #
# Do not edit beyond this point #
!
fi
cat <<'!'
# DO NOT REMOVE THIS LINE (addaliases) #
###########################################
!
# Generate aliases for variations on user's full name and initials from
# passwd file GECOS field. Assumes that full names are in form
# "Firstname Lastname" with optional middle initials. One space should follow
# each period in initials, and there should be no commas within name. A comma
# or parenthesis can end the full name if GECOS field has other information.
# This code is taken from support code for smail, and was modified to work
# on sendmail-style aliases files.
echo "# automatic full name aliases, from passwd:"
T=/tmp/al$$.t
# Strip out dummy userids from passwd file, tack on priorities to
# give user IDs top priority, then full names.
# Ajust awk script as required at your site.
$PASSWD | awk -F: '$2 != "*" && $3 >= '$MINUID' {print}' |
sed -e 's/^[^:]*/1&::::&::\
2&/' |
# extract user name and full name fields
sed 's/\(.*\):.*:.*:.*:[0-9]*-*\([^(,:]*\).*:.*:.*/\1 \2/' |
$NAMEPTX | # permute the names
(tee $T; tr . _ < $T; rm $T) | # allow _ as well as . separator
#sort -u +0 -1 |
sort | sort -mu +0 -1 | # sort 1st by whole record,
# so priority code recognized
# Strip off priority code, add colon for sendmail aliases,
# strip out too-short names, and redundant definitions (name: name):
sed -e 's/ [1-9]/: /' \
-e '/^.: /d' -e '/^..: /d' \
-e '/[._][a-z]: /d' \
-e '/^\([a-z0-9_][a-z0-9_]*\): \1$/d'
) > /tmp/aliases.$$
mv $ALIASES $ALIASES.bak
mv /tmp/aliases.$$ $ALIASES
chmod 644 $ALIASES
if [ -f /var/yp/Makefile ]
then
echo "Modified $ALIASES. Run" '"newaliases" and "make aliases" in /var/yp.'
else
echo "Modified $ALIASES. Run" '"newaliases".'
fi