Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
mxtools/make-automaps/make-automaps
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
189 lines (162 sloc)
5.94 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/local/system/perl/bin/perl | |
use strict; | |
use warnings; | |
chomp (my $hostname=`uname -n`);$hostname=~s/\..*//; | |
{ | |
my %SERVER_LIMIT_NFS40; | |
sub server_vers_opt { | |
my ($servername)=@_; | |
unless (exists $SERVER_LIMIT_NFS40{$servername}) { | |
my $pid=fork; | |
if (defined $pid) { | |
unless ($pid) { | |
open STDERR,'>','/dev/null'; | |
exec 'hostconfig','--host',$servername,'nfs40'; | |
die "exec failed: $!\n"; | |
} | |
wait; | |
$SERVER_LIMIT_NFS40{$servername} = $? ? 0 : 1; | |
} else { | |
$SERVER_LIMIT_NFS40{$servername} = 0; | |
} | |
} | |
return $SERVER_LIMIT_NFS40{$servername} ? ('-vers=4.0') : (); | |
} | |
} | |
sub convert_map { | |
my ($amd,$auto,$parse_line)=@_; | |
open IN,'<',$amd or die "$amd: $!\n"; | |
open OUT,'>',$auto or die "$auto: $!\n"; | |
while (<IN>) { | |
/\S/ or next; | |
/-fs:=offline/ and next; | |
/^\/defaults/ and next; | |
my $out=$parse_line->($_,$amd); | |
$out and print OUT "$out\n";; | |
} | |
} | |
sub parse_jbod_line { | |
my ($in,$source)=@_; | |
if ($in=~m"^(X\d+)\s+host==([^;]+);type:=link;fs:=/amd/\2/X/\1 host!=\2;type:=nfs;rhost:=\2;fs:=/amd/\2/x/\1;rfs:=/amd/\2/X/\1$") { | |
return join(' ',$1,server_vers_opt($2),"$2:/amd/$2/X/$1"); | |
} elsif ($in=~m"^(C[\dA-Z]\d+)\s+host==([^;]+);type:=link;fs:=/amd/\2/C/\1 host!=\2;type:=nfs;rhost:=\2;fs:=/amd/\2/c/\1;rfs:=/amd/\2/C/\1$") { | |
return join(' ',$1,server_vers_opt($2),"$2:/amd/$2/C/$1"); | |
} elsif ($in=~m"^(M[\dA-Z]\d+)\s+host==([^;]+);type:=link;fs:=/amd/\2/M/\1 host!=\2;type:=nfs;rhost:=\2;fs:=/amd/\2/m/\1;rfs:=/amd/\2/M/\1$") { | |
return join(' ',$1,server_vers_opt($2),"$2:/amd/$2/M/$1"); | |
} elsif ($in=~m"^(X\d+)\s+-fs:=/amd/([^/]+)/X/\1 host==\2;type:=link host!=\2;type:=nfs;rhost:=\2") { | |
return join(' ',$1,server_vers_opt($2),"$2:/amd/$2/X/$1"); | |
} else { | |
warn "?? $source : $_ ??"; | |
} | |
return undef; | |
} | |
our %IGNORE=map{$_=>1} qw(ftpadm ftp ftpin wwwcmb postgresdata mysqldata kde qt xfce bigblast mzsqldb sge sge6-2 drvault); | |
sub parse_map_line { | |
my ($in,$source)=@_; | |
# return key,host,fs | |
if ($in=~m"^(\S+)\s+type:=nfsl;rhost:=([^;]+);fs:=(.+)") { | |
return $1,$2,$3; | |
} elsif ($in=~m"^(\S+)\s+-fs:=([\S]+) host==([^;]+);type:=link host!=\3;type:=nfs;rhost:=\3$") { | |
return $1,$3,$2; | |
} elsif ($in=~m"^(\S+)\s+true;type:=nfsl;rhost:=([^;]+);fs:=(.+)") { | |
return $1,$2,$3; | |
} elsif ($in=~m"^(\S+)\s+host==([^;]+);type:=link;fs:=([\S]+) type:=nfs;rhost:=\2;fs:=\3$") { | |
return $1,$2,$3; | |
} elsif ($in=~m"^(\S+)\s+host==([^;]+);type:=link;fs:=([\S]+) type:=nfs;rhost:=\2;rfs:=\3$") { | |
return $1,$2,$3; | |
} elsif ($in=~m"^(\S+)\s+host==([^;]+);type:=link;fs:=([\S]+) type:=nfs;fs:=\3;rhost:=\2;rfs:=\3$") { | |
return $1,$2,$3; | |
} elsif ($in=~m"^(\S+)\s+type:=link;fs:=(.+)") { | |
return "#OFFLINE# $1",'',$2; | |
} elsif ($in=~m"^(\S+)\s+true;type:=link;fs:=(.+)") { | |
return "#OFFLINE# $1",'',$2; | |
} elsif ($in=~/^local/ && $source =~ /amd\.scratch$/) { | |
# silently ignore | |
} else { | |
warn "?? $source $in" unless $in=~/^(\S+)/ and $IGNORE{$1} | |
} | |
return (); | |
} | |
sub parse_subkey_line { my ($key,$host,$fs)=parse_map_line(@_); return $key ? join(' ',$key,server_vers_opt($host),"$host:$fs/$key") : undef; } | |
sub parse_nosubkey_line { my ($key,$host,$fs)=parse_map_line(@_); return $key ? join(' ',$key,server_vers_opt($host),"$host:$fs") : undef; } | |
sub create_pkg_map { | |
my $cache; | |
# ensure the map exists even if we fail out later | |
open my $out,'>','/etc/automount/auto.pkg' or die "/etc/automount/auto.pkg: $!\n"; | |
open my $in,'<','/etc/mxpkg' or return warn "/etc/mxpkg: $!\n"; | |
while (<$in>) { | |
s/#.*//; | |
/\S/ or next; | |
my ($pkg,$flags)=split ' '; | |
my $local="/var/pkg/$pkg"; | |
my $rw; | |
if (-d $local) { | |
$rw = $flags eq 'BUILD' ? ' -rw' : ''; | |
print $out "$pkg$rw :$local\n"; | |
} else { | |
if (server_vers_opt('ellie')) { | |
$rw = $flags eq 'BUILD' ? ' -vers=4.0,rw' : ' -vers=4.0'; | |
} else{ | |
$rw = $flags eq 'BUILD' ? ' -rw' : ''; | |
} | |
print $out "$pkg$rw ellie:/amd/ellie/1/package/pkg/$pkg\n"; | |
} | |
} | |
} | |
umask 022; | |
-d "/etc/automount" or mkdir("/etc/automount") or die "/etc/automount: $!\n"; | |
convert_map('/etc/amd/amd.jbod','/etc/automount/auto.jbod',\&parse_jbod_line); | |
convert_map('/etc/amd/amd.home','/etc/automount/auto.home',\&parse_subkey_line); | |
convert_map('/etc/amd/amd.project','/etc/automount/auto.project',\&parse_nosubkey_line); | |
convert_map('/etc/amd/amd.confidential','/etc/automount/auto.confidential',\&parse_nosubkey_line); | |
convert_map('/etc/amd/amd.package','/etc/automount/auto.package',\&parse_nosubkey_line); | |
convert_map('/etc/amd/amd.scratch','/etc/automount/auto.scratch',\&parse_subkey_line); | |
convert_map('/etc/amd/amd.src','/etc/automount/auto.src',\&parse_subkey_line); | |
######################################## /scratch | |
open O,'>>','/etc/automount/auto.scratch' or die "/etc/automount/auto.scratch: $!\n"; | |
print O<<"eof"; | |
local :/amd/$hostname/S/scratch | |
local1 :/amd/$hostname/S/scratch | |
local2 :/amd/$hostname/S2/scratch | |
local3 :/amd/$hostname/S3/scratch | |
local4 :/amd/$hostname/S4/scratch | |
local5 :/amd/$hostname/S5/scratch | |
local6 :/amd/$hostname/S6/scratch | |
local7 :/amd/$hostname/S7/scratch | |
local8 :/amd/$hostname/S8/scratch | |
local9 :/amd/$hostname/S9/scratch | |
local10 :/amd/$hostname/S10/scratch | |
eof | |
######################################## /package | |
open O,'>>','/etc/automount/auto.package' or die "/etc/automount/auto.package: $!\n"; | |
for my $package (qw(postgresdata mysqldata)) { | |
for my $path ( | |
"/amd/$hostname/0/package/$package", | |
"/amd/$hostname/1/package/$package", | |
"/amd/$hostname/2/package/$package", | |
"/amd/$hostname/3/package/$package", | |
"/amd/$hostname/4/package/$package", | |
) { | |
if (-d $path) { | |
print O "$package :$path\n"; | |
last; | |
} | |
} | |
} | |
for my $package (qw(kde qt xfce)) { | |
for my $path ( | |
"/amd/$hostname/S/scratch/package/$package", | |
"/amd/$hostname/0/package/$package", | |
"/amd/$hostname/1/package/$package", | |
) { | |
if (-d $path) { | |
print O "$package :$path\n"; | |
last; | |
} | |
} | |
} | |
######################################## /pkg | |
create_pkg_map(); | |
######################################## | |
close O; | |
-e "/var/run/autofs-running" and system "kill -HUP `cat /var/run/autofs-running`"; |