#!/bin/sh
# automount2amd --- make amd maps from automount maps
# Author: Noah Friedman <friedman@splode.com>
# Created: 1996-11-06
# Public domain

# $Id: automount2amd,v 2.3 2000/01/17 18:29:37 friedman Exp $

# Commentary:
# Code:

exec ${PERL-perl} -Sx $0 ${1+"$@"}
#!perl

sub main
{
  my $DOMAIN = $ENV{'NIS_DOMAIN'};
  my $bsize = 8192;
  my $DEFAULTS = join ("",
                       "type:=nfs;cache:=inc;",
                       "opts:=rw,intr,spongy,tcp,nodevs,grpid,nosuid,",
                       "rsize=$bsize,wsize=$bsize,utimeout=600");
  my $AUTO = "type:=auto;fs:=\${map};pref:=\${key}/";

  printf ("/defaults %s\n\n", $DEFAULTS);

  while (<>)
    {
      chop;
      s|^/||o;
      if (m,^(\w\S*)(\s+\-\w\S*\s+|\s+)(\w[^:]*):(\/\S*)\s*(.*),o)
        {
          my ($dir, $options, $machine, $path, $rest) = ($1, $2, $3, $4, $5);
          my @pathsubs = split (m|/+|o, $dir);
          my @machines = split (/,/, $machine);

          my $subdir = "";
          for my $component (@pathsubs)
            {
              $subdir .= "/" . $component;
              $subdir =~ s|^/||o;

              $fs_entry{$subdir} = "\t$AUTO"
                unless (defined $fs_entry{$subdir});
            }

          my $rhoststring = "";
          for my $machine (@machines)
            {
              $machine .= ".$DOMAIN"
                if (defined $DOMAIN && index ($machine, ".") != -1);
              $rhoststring .= " \\\n\trfs:=$path;rhost:=$machine";
            }
          $fs_entry{$dir} = "$rhoststring";
        }
    }

  for my $entry (sort keys %fs_entry)
    {
      printf ("%s%s\n\n", $entry, $fs_entry{$entry});
    }
}

main();

# automount2amd ends here
