#!/bin/bash ################################################################################ # # File: add_moa # RCS: $Header: add_moa,v 1.4 98/03/19 13:52:49 fong Exp $ # Description: This script adds a new person to moa # Author: Andrew DeFaria, California Language Labs # Created: Mon May 19 15:56:06 PDT 1997 # Modified: # Language: Korn Shell # # (c) Copyright 2001, Andrew@DeFaria.com, all rights reserved # ################################################################################ # Set me to command name me=$(basename $0) # Set adm_base adm_base=${adm_base:-//sonscentral/Corporate/Software/adm} # Set adm_fpath adm_fpath=${adm_fpath:-$adm_base/functions} # Source functions . $adm_fpath/common function usage { print -u2 "Usage: $me -username -fullname " print -u2 "\t-phone -homeserver -shell " exit 1 } # usage function add_to_moa { cd $admin_root/lib co -q -l $master_passwd if [ $? -ne 0 ]; then error "Unable to checkout $master_passwd" exit $? fi trap cancel_checkout INT ERR if [ "$shell" = "tcsh" ]; then shell="/app/tcsh" else shell="/bin/$shell" fi uid=$(/app/newuid) # generate unique uid print "$username:*:$uid:$gid:$fullname,42U,$phone,_MoA_:/nfs/$homeserver/data/home/$username:$shell" >> $master_passwd if [ $? -ne 0 ]; then error "Unable to add entry to $master_passwd" exit $? fi ci -u -q -m"Added $fullname" $master_passwd if [ $? -ne 0 ]; then error "Unable to check in new master password file!" exit $? fi trap INT ERR cd $OLDPWD } # add_to_moa function cancel_checkout { info "Canceling checkout" rcs -q -u $master_passwd chmod -w $master_passwd co -q $master_passwd exit 1 } # cancel_checkout A function user_exists { grep -ve "^#" $master_passwd | cut -f1 -d: | grep "$username" >/dev/null 2>&1 return $? } # user_exists # Find admin root if [ -d /net/bismol/app/admin ]; then admin_root=/net/bismol/app/admin elif [ -d /net/hpclbis/app/admin ]; then admin_root=/net/hpclbis/app/admin elif [ -d /nfs/bismol/app/admin ]; then admin_root=/nfs/bismol/app/admin elif [ -d /nfs/hpclbis/app/admin ]; then admin_root=/nfs/hpclbis/app/admin elif [ -d /nfs/hpclbis/root/app/admin ]; then admin_root=/nfs/hpclbis/root/app/admin else error "Internal error: Unable to ascertain admin_root!" exit 1 fi master_passwd=$admin_root/lib/master_passwd gid=191 # lang group username= fullname= phone= homeserver= shell= while [ $# -ge 1 ]; do case "$1" in -usage) usage ;; -username) if [ $# -le 1 ]; then error "Username not specified!" usage fi shift username="$1" ;; -fullname) if [ $# -le 1 ]; then error "Full name not specified!" usage fi shift fullname="$1" ;; -phone) if [ $# -le 1 ]; then error "Phone not specified!" usage fi shift phone="$1" ;; -homeserver) if [ $# -le 1 ]; then error "Home machine not specified!" usage fi shift homeserver="$1" ;; -shell) if [ $# -le 1 ]; then error "Shell not specified!" usage fi shift shell="$1" ;; *) error "Unknown parameter encounter: \"$1\"" usage ;; esac shift done if [ "_$username" = "_" -o \ "_$fullname" = "_" -o \ "_$phone" = "_" -o \ "_$homeserver" = "_" -o \ "_$shell" = "_" ]; then error "Missing parameter" usage fi #if $(user_exists); then #error "$username already exists in the master password file" #else add_to_moa if [ $? -eq 0 ]; then info "Account for $fullname has been successfully created" else error "Problems encountered trying to create account for $fullname" fi #fi