#!/bin/sh
# This is a shell archive (produced by GNU shar 4.0).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 1995-01-26 11:14 EST by <dcs@proton>.
# Source directory was `/u/dcs/ws'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#   1093 -rw-r--r-- automount-map-fixer/README
#   3551 -rwxr-xr-x automount-map-fixer/automount-map-fixer.pl
#
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
  shar_touch=touch
else
  shar_touch=:
  echo 'WARNING: not restoring timestamps'
fi
rm -f 1231235999 $$.touch
#
# ============= automount-map-fixer/README ==============
if test ! -d 'automount-map-fixer'; then
  echo 'x - creating directory automount-map-fixer'
  mkdir 'automount-map-fixer'
fi
if test -f 'automount-map-fixer/README' && test X"$1" != X"-c"; then
  echo 'x - skipping automount-map-fixer/README (File already exists)'
else
  echo 'x - extracting automount-map-fixer/README (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'automount-map-fixer/README' &&
XFrom: rblack@warhol.me.ic.ac.uk (Robert Black)
Newsgroups: comp.sys.sgi.bugs
Subject: NIS automount map problem & fix.
Date: 25 Jan 1995 16:44:13 GMT
Organization: Imperial College, Dept of Mechanical Engineering
Message-ID: <3g5v4t$i04@ccserver.cc.ic.ac.uk>
X
There appears to be a problem with NIS automount maps which include file maps.
According to the IRIX 5.3 documentation this should work, however, when you
include a map in a file from within a NIS map it sometimes gets ignored. Silicon
Graphics are aware of this problem.
X
Here is a work-around script for the problem. It works by creating a directory
to store copies of the NIS maps in with correctly modified sub-map entries. As
it stands it will only work with the default NIS auto.master master map although
it should be fairly easy to modify it to work with other master maps. It is
designed to be used from a crontab to keep the files updated with the latest NIS
configuration.
X
WARNING: DO NOT USE THIS SCRIPT UNLESS YOU RUN INTO THE NIS MAP PROBLEM AND KNOW
WHAT YOU ARE DOING. IT COULD MESS UP YOUR AUTOMOUNT CONFIGURATION.
SHAR_EOF
  $shar_touch -am 0126111395 'automount-map-fixer/README' &&
  chmod 0644 'automount-map-fixer/README' ||
  echo 'restore of automount-map-fixer/README failed'
  shar_count="`wc -c < 'automount-map-fixer/README'`"
  test 1093 -eq "$shar_count" ||
    echo "automount-map-fixer/README: original size 1093, current size $shar_count"
fi
# ============= automount-map-fixer/automount-map-fixer.pl ==============
if test -f 'automount-map-fixer/automount-map-fixer.pl' && test X"$1" != X"-c"; then
  echo 'x - skipping automount-map-fixer/automount-map-fixer.pl (File already exists)'
else
  echo 'x - extracting automount-map-fixer/automount-map-fixer.pl (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'automount-map-fixer/automount-map-fixer.pl' &&
#!/usr/sbin/perl
# This script is designed to work around the problem encountered in IRIX 5.3
# when trying to use file automount maps from within NIS automount maps. If you
# don't have this problem then this script will at best make your automount
# configuration much less efficient.
#
# DO NOT USE THIS SCRIPT UNLESS YOU REALLY KNOW WHAT YOU ARE DOING AND
# UNDERSTAND ROUGHLY WHAT THIS SCRIPT DOES. IF NOT USED PROPERLY THIS
# SCRIPT COULD MESS UP A PERFECTLY GOOD AUTOMOUNT CONFIGURATION.
#
# This script is copyright Robert Black (r.black@ic.ac.uk) but may be
# distributed freely provided that this copyright notice is not removed
# and any modifications made are commented as such.
#
#
#
# This script works by copying all the maps it can find into the directory
# stored in $automount_tmpdir. It modifies the maps to correctly access sub
# maps. THe script assumes the use of a NIS master map and some tinkering
# will be required to make it work with other setups.
X
X
###### CONFIGURATION OPTIONS ######
X
# These variables need to be configured to reflect the local automount
# configuration.
X
@master_maps = ('auto.master');	# List of master maps
X
$automount_tmpdir = '/etc/automount.tmpdir';
X
###### INITIALISATION ######
X
unless (-d $automount_tmpdir)
{
X    if (-e $automount_tmpdir)
X    {
X	die "$automount_tmpdir exists and is not a directory\n";
X    }
X    mkdir($automount_tmpdir, 0755) ||
X	die "Unable to create $automount_tmpdir: $!\n";
}
X
unless(-e "/etc/config/automount.options.normal")
{
X    unless(-e "/etc/config/automount.options")
X    {
X	open(OPTIONS, "/etc/config/automount.options");
X	print OPTIONS " ";
X	close (OPTIONS);
X    }
X    system("/bin/cp /etc/config/automount.options
/etc/config/automount.options.normal");
X    open(OPTIONS, ">>/etc/config/automount.options") ||
X	warn "Unable to reconfigure automount options.\n";
X    print OPTIONS " -m -f $automount_tmpdir/auto.master";
X    close(OPTIONS);
X    warn "Automount configuration changed. Please restart the automounter.\n";
}
X
###### THE MAIN ROUTINE ######
X
X &process_master_maps(@master_maps);
X
###### SUBROUTINES ######
X
sub process_master_maps
{
X    local(@map_list, $map, $line);
X    while (@_)
X    {
X	open(MASTER_MAP, &map_name($_[0])) ||
X	    die "Unable to open master map: $_[0]\n";
X	open(MASTER_FILE, ">" . &tmp_file_name($_[0])) ||
X	    die "Unable to create file " . &tmp_file_name($_[0]) . ": $!\n";
X	while(<MASTER_MAP>)
X	{
X	    $line = $_;
X	    unless ($line =~ /\#/ || $line =~ m/^\S+\s+-\S+/)
X	    {
X		if ($line =~ m/^\S+\s+(\S+)/)
X		{
X		    $map = $1;
X		    push(@map_list, $map);
X		    $tmp_map = &tmp_file_name($map);
X		    $line =~ s/^(\S+\s+)\S+/$1$tmp_map/;
X		}
X		print MASTER_FILE $line;
X	    }
X	}
X	close(MASTER_FILE);
X	close(MASTER_MAP);
X	shift(@_);
X    }
X    &process_sub_maps(@map_list);
}
X
sub process_sub_maps
{
X    local($map, $line);
X    while (@_)
X    {
X	open(SUB_MAP, &map_name($_[0])) ||
X	    warn "Unable to open map: $_[0]\n";
X	open(SUB_FILE, ">" . &tmp_file_name($_[0])) ||
X	    die "Unable to create file " . &tmp_file_name($_[0]) . ": $!\n";
X	while(<SUB_MAP>)
X	{
X	    $line = $_;
X	    if ($line =~ /^\+\s*(\S+)/)
X	    {
X		$map = $1;
X		push(@_, $map);
X		$tmp_map = &tmp_file_name($map);
X		$line =~ s/^\+\s*\S+/\+$tmp_map/;
X	    }
X	    print SUB_FILE $line;
X	}
X	close(SUB_FILE);
X	close(SUB_MAP);
X	shift(@_);
X    }
}
X
sub map_name
{
X    if ($_[0] =~ /\//)
X    {
X	$_[0];
X    } else {
X        "/bin/ypcat -k $_[0] |";
X    }
}
X
sub tmp_file_name
{
X    @file_path = split('/', $_[0]);
X    $automount_tmpdir . '/' . pop(@file_path);
}
SHAR_EOF
  $shar_touch -am 0126111495 'automount-map-fixer/automount-map-fixer.pl' &&
  chmod 0755 'automount-map-fixer/automount-map-fixer.pl' ||
  echo 'restore of automount-map-fixer/automount-map-fixer.pl failed'
  shar_count="`wc -c < 'automount-map-fixer/automount-map-fixer.pl'`"
  test 3551 -eq "$shar_count" ||
    echo "automount-map-fixer/automount-map-fixer.pl: original size 3551, current size $shar_count"
fi
exit 0
