From 3822b7bf653c59a0a0d1fe437b5b13081abcb155 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Mon, 19 Nov 2018 14:21:59 +0100 Subject: [PATCH] mxmount: Expand host groups by hostconfig When /etc/mxmounts uses the netgroup syntax to export to a list of clients (usually @amd), expand the list using hostconfig to a list of hosts from inside this mxmount, so that we no longer export to NIS netgroups. This is one step to get rid of NIS. Only hosts with the tag newexport should do it for now, so that we can see if there are problems before switching all hosts. We could expand /filesystem @group(opts) to /filesystem host1(opts) hosts2(opts) host3(opts) host4(opts)... but because our opts are about 50 characters and we have about 540 hosts on @amd, we save about 27000 characters per line by converting to /filesystem -opts host1 host2 host3... Notes: * `hostconfig --list` does not only accept single tag (=group) names, but complex boolean expressions as well. We could export to @1 (=allways true, any known host) or @testing&!desktop. It is suggested, not to use this as a feature. --- mxmount/mxmount | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/mxmount/mxmount b/mxmount/mxmount index 47d69d6..ed7d2ae 100755 --- a/mxmount/mxmount +++ b/mxmount/mxmount @@ -64,7 +64,7 @@ sub add_data0_if_not_present { sub create_exports { my $allmp = $D{$hostname}; - my @CMD; + my $newexport=system('hostconfig newexport')==0; open(EXPORTS, '>', $exports) or die "can't open $exports: $!"; @@ -78,11 +78,24 @@ sub create_exports { foreach my $mp (@$allmp) { next if($mp->{noexport}); - @CMD = ($mp->{mountpoint}, $mp->{exportopts}); - - print join " ", "$exports: ", @CMD, "\n"; - print EXPORTS join " ", @CMD, "\n"; - + unless ($newexport) { + my @CMD = ($mp->{mountpoint}, $mp->{exportopts}); + print join " ", "$exports: ", @CMD, "\n"; + print EXPORTS join " ", @CMD, "\n"; + } else { + my ($mountpoint,$exportopts)=($mp->{mountpoint}, $mp->{exportopts}); # '/amd/theinternet/1','@amd(sync,rw,...)' + my ($hostspec,$optspec)=$exportopts=~/^([^(]+)(.*)/; # '@amd','(sync,rw,...)' + my ($opts)=$optspec=~/\((.*)\)/; # 'sync,rw,...' + my $hosts=''; + warn "export $mountpoint to $hostspec opts $opts\n"; + if (my ($group) = $hostspec=~/^@(.+)/) { + $hosts=`hostconfig --list $group`; # expanded group + $hosts or warn "group $group is empty\n"; + } else { + $hosts=$hostspec; # single host + } + $hosts and printf EXPORTS "%s -%s %s\n",$mountpoint,$opts,$hosts; + } } close EXPORTS; }