#!/usr/local/perl/bin/perl -I/usr/local/perl/lib

###
### Create Auto Home entries for NIS+
###   create_auto -n <name> -d <directory>
###
### Submitted By: Marc Jacquard
###               Marc.Jacquard@firstdatacorp.com
###
### Adjust as needed
###

require "getopts.pl";
require "flush.pl";

if($>){die "bye: euid != 0"};
#
# Check the options
#
&Getopts('n:d:');

if($opt_n && $opt_n != 1){ $name = $opt_n; }
else{ die "No user name!(-n): $opt_n\n"; }

if($opt_d && $opt_d != 1){ $dir = $opt_d; }
else{ die "No dir name!(-d): $opt_d\n"; }


#
# NIS+  Auto-home file
#
print "Updating auto_home table\n";
open(AUTONIS, ">>/var/nis/config/auto_home")||die "Can't open auto_home!
\n";
#the line below needs to have the srvs1 line modified to whatever system
and directory structure
#you use at your site.
print (AUTONIS "$name         srvs1:/export/$dir/\&\n");
&flush(AUTONIS);
# Update tables
system "/usr/lib/nis/nisaddent -m -f /var/nis/config/auto_home -t
auto_home.org_dir key-value";
# Update replica servers
system "/usr/lib/nis/nisping -C mydomain.org."; # the word "mydomain" needs
to be changed to your domain name
system "sleep 10";
system "/usr/lib/nis/nisping -C groups_dir";
system "sleep 10";
system "/usr/lib/nis/nisping -C org_dir";
#
#
print "Done!\n";




##############################################################################
### This script is submitted to BigAdmin by a user of the BigAdmin community.
### Sun Microsystems, Inc. is not responsible for the
### contents or the code enclosed. 
###
###
### Copyright 2006 Sun Microsystems, Inc. ALL RIGHTS RESERVED
### Use of this software is authorized pursuant to the
### terms of the license found at
### http://www.sun.com/bigadmin/common/berkeley_license.html
##############################################################################


