#!/usr/bin/perl

#***********************************************************************
#
#             ARL:UT Group Administration Shell Package
#                         September 13, 1994
#
#  Copyright 1994. The University of Texas at Austin (UTA).  All rights
#  reserved.  By using this software the USER indicates that he or she
#  has read, understood, and will comply with the following:
#
#  -UTA hereby grants USER nonexclusive permission to use, copy, and/or
#  modify this software for internal purposes only.  Any non-internal 
#  distribution, including commercial sale or license, of this software,
#  copies of the software, its associated documentation, and/or
#  modifications of either is strictly prohibited without the prior
#  consent of UTA.  Title to copyright to this software and its 
#  associated documentation shall at all times remain with UTA. 
#  Appropriate copyright notice shall be placed on all software copies,
#  and a complete copy of this notice shall be included in all copies
#  of the associated documentation.  No right is granted to use in 
#  advertising, publicity, or otherwise any trademark, service mark,
#  or the name of UTA.
#
#  -This software and any associated documentation is provided "as is",
#  and UTA MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED,
#  INCLUDING THOSE OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
#  PURPOSE, OR THAT USE OF THE SOFTWARE, MODIFICATIONS, OR ASSOCIATED
#  DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS 
#  OR OTHER INTELLECTUAL PROPERTY RIGHTS OF A THIRD PARTY.  UTA, the
#  University of Texas System, its Regents, officers, and employees 
#  shall not be liable under any circumstances for any direct, indirect,
#  special, incidental, or consequential damages with respect to any
#  claim by USER or any third party on account of or arising from the
#  use, or inability to use, this software or its associated 
#  documentation, even if UTA has been advised of the possibility of
#  those damages.
#
#***********************************************************************

#
# Last modified by Pug on 9/14/94.
#
# This program is going to be used to convert a gash auto.home.* file into
# the correctly formated automounter file.
#
# Input file format:
#
# user [w] volumename  [ [w] volumname ]+
#
# 
# Input file name will be *.extension and the output filename will be
# auto.home.extension. Thus the output file is dependent on the input
# files extension only.
# 

if (($#ARGV != 0) || (@ARGV[0] !~ /\./)) {
    print "gash2auto converts a gash automounter file to the corresponding Sun automount\nfiles. Output file will be auto.home.extension. Where the .extension is the\nextension after the last . of the input file.\n\nUsage:\n\tgash2auto {gash_auto_file]\n";
    exit;
}

#
# Open input file.
#

open(GASHFILE, @ARGV[0]) || die "Can't open gash file @ARGV[0]: $!\n"; 

#
# Get auto.home.extension file and open it.
#

@file = split(/\./, @ARGV[0]);
$extension = pop(@file);
open(HOMEFILE, "> auto.home.$extension") || die "Can't open home file: $!\n";

# 
# Open auto.vol file and read it into an array.
# This is used to convert volume names into real mountpoints.
#

open(VOLUME, "auto.vol") || die "Can't open file auto.vol: $!\n";
while (<VOLUME>) {
    chop;
    if (/^\S+\s+\S+:\S+/) {
	($volname, $locations) = split(/\s+/, $_, 2);
	$locations =~ s/\s+/:&\t/g;
	$locations .= ":&";
	$vols{$volname} = $locations;
    }
}
close(VOLUME);

#
# Parse the input file and output the appropriate machine information
# from the auto.vol file. It is assumed that GASH did the right thing
# and there are only entries in the auto.home.* file that have
# corresponding auto.vol entries.
#

while (<GASHFILE>) {
    chop;
    ($user,@volname) = split(/\s+/, $_);
    print HOMEFILE $user, "\t";
    while ($#volname >= 0) {
	print HOMEFILE "\t", $vols{pop(@volname)};
    }
    print HOMEFILE "\n";
}

close(GASHFILE);
close(HOMEFILE);
