From deb51774de746564a74e40be72d783b9cd7e42f2 Mon Sep 17 00:00:00 2001 From: Antoine Ginies Date: Mon, 15 Dec 2003 10:04:54 +0000 Subject: add nis+autofs Server and client side --- nisautofs_wizard/Nisautofs.pm | 342 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 342 insertions(+) create mode 100644 nisautofs_wizard/Nisautofs.pm (limited to 'nisautofs_wizard/Nisautofs.pm') diff --git a/nisautofs_wizard/Nisautofs.pm b/nisautofs_wizard/Nisautofs.pm new file mode 100644 index 00000000..f3d3c172 --- /dev/null +++ b/nisautofs_wizard/Nisautofs.pm @@ -0,0 +1,342 @@ +# version 0.2 +# +# Copyright (C) 2002,2003 Mandrakesoft +# +# Author: aginies _at_ mandrakesoft.com +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +package MDK::Wizard::nisautofs; +use lib qw(/usr/lib/libDrakX); +use ugtk2; +use strict; +use standalone; +use common; +use services; +use MDK::Wizard::Varspaceval; +use MDK::Wizard::Wizcommon; + + +# test root capa +my $wiz = new MDK::Wizard::Wizcommon; + +my $NISDOMAIN = $wiz->{net}->network_get("NISDOMAIN"); +my @HOST = split('\.', $wiz->{net}->network_get("HOSTNAME")); +my $HOST = @HOST[0]; # just need basename and not full qualified computer hostname (with domainaname) +my $NIS_DIRMAKEFILE = "/var/yp/"; +my $HOMENIS = "/home/nis"; +my $NETWORKFILE = "/etc/sysconfig/network"; +my $NFSEXPORTS = "/etc/exports"; +my $AUTOMASTER = "/etc/auto.master"; +my $AUTOHOME = "/etc/auto.home"; +my $YPCONF = "/etc/yp.conf"; + +my $o = { + name => 'LDAP Configuration Wizard', + var => { + NISDOMAIN => chomp_($NISDOMAIN), + NISSERVER => chomp_($HOST), + NIS_DIRMAKEFILE => "/var/yp/", + HOMENIS => "/home/nis", + NETWORKFILE => "/etc/sysconfg/network", + NFSEXPORTS => "/etc/exports", + AUTOMASTER => "/etc/auto.master", + AUTOHOME => "/etc/auto.home", + }, + needed_rpm => [ 'ypbind', 'nfs-utils', 'yp-tools', 'nfs-utils-clients' ], + defaultimage => "/usr/share/wizards/dns_wizard/images/NIS.png" + }; + +my %level = ( + 1 => N("Nis Server - Setup configuration NIS + Autofs(nfs) server"), + 2 => N("Nis Client - Setup a Nis Client"), + ); + +$o->{pages} = { + welcome => { + name => N("NIS+autofs configuration wizard") . "\n\n" . N('Setup a nis+autofs.'), + no_back => 1, + pre => sub { $o->{var}{wiz_level} ||= 1; }, + post => sub { if ($o->{var}{wiz_level} == 2) { + return 'nis_client' + } + }, + data => [ + { label => N("Wich operation on Wizard:"), val => \$o->{var}{wiz_level}, list => [ keys %level ], format => sub { $level{$_[0]} } }, + ], + next => 'nis_server', + }, + nis_client => { + name => N("Be a nis client") . "\n\n" . N("You just have to put nisdomain and nisserver"), + data => [ + { label => N("Nis Server:"), val => \$o->{var}{NISSERVER} }, + { label => N("Nis Domain:"), val => \$o->{var}{NISDOMAIN} }, + ], + next => 'summaryclient', + }, + nis_server => { + name => N('Nis+autofs') . "\n\n" . N(''), + data => [ + { label => N("Nis server:"), val => $HOST }, + { label => N("Home nis:"), val => \$o->{var}{HOMENIS} }, + { label => N("Nis directory Makefile:"), val => \$o->{var}{NIS_DIRMAKEFILE} }, + { label => N("Nis Domain:"), val => \$o->{var}{NISDOMAIN} }, + ], + post => \&test_set, + next => 'summaryserver', + }, + summaryserver => { + name => N('Will set your NIS + Autofs server with this configuration:'), + data => [ + { label => N("Nis server:"), fixed_val => \$HOST }, + { label => N("Home nis:"), fixed_val => \$o->{var}{HOMENIS} }, + { label => N("Nis Domain:"), fixed_val => \$o->{var}{NISDOMAIN} }, + { label => N("Nis directory Makefile:"), fixed_val => \$o->{var}{NIS_DIRMAKEFILE} }, + { label => N("Network File:"), fixed_val => \$o->{var}{NETWORKFILE}}, + { label => N("Nfs exports:"), fixed_val => \$o->{var}{NFSEXPORTS} }, + { label => N("Auto master:"), fixed_val => \$o->{var}{AUTOMASTER} }, + { label => N("Auto home:"), fixed_val => \$o->{var}{AUTOHOME} }, + ], + post => \&do_it_server, + next => 'endserver', + }, + summaryclient => { + name => N('Will set your machine has a NIS client with this configuration:'), + data => [ + { label => N("Nis Server:"), fixed_val => \$o->{var}{NISSERVER} }, + { label => N("Nis Domain:"), fixed_val => \$o->{var}{NISDOMAIN} }, + ], + post => \&do_it_client, + next => 'endclient', + }, + error_homedir => { + name => N('Error Should be a directory'), + next => 'nis_server', + }, + error_nisd => { + name => N('Error nisdomainame Should be correct (not none or localdomain)') . "\n\n" . N('Please adjust with domainname command or in /etc/sysconfig/network file (NISDOMAIN=yournisdomain)'), + end => 1, + next => 0, + }, + endclient => { + name => N('Congratulations'), + data => [ { label => N('The wizard successfully configured Your machine to be a nis client.') } ], + no_back => 1, + end => 1, + next => 0 + }, + endserver => { + name => N('Congratulations'), + data => [ { label => N('The wizard successfully configured Your machine to be a nis+autofs Server.') } ], + no_back => 1, + end => 1, + next => 0 + }, + }; + + +sub test_set { + if (member($o->{var}{NISDOMAIN}, qw(localdomain (none)))) { return 'error_nisd'; } + !-d $o->{var}{HOMENIS} or return 'error_dir'; + !-d $o->{var}{NIS_DIRMAKEFILE} or return 'error_dir'; +} +# update /etc/sysconfig/network +sub update_network { + save_config($NETWORKFILE); + if (any { /NISDOMAIN/ } cat_($NETWORKFILE)) { + substInFile { s/NISDOMAIN.*/NISDOMAIN=$o->{var}{NISDOMAIN}/g } $NETWORKFILE; + } else { + append_to_file($NETWORKFILE, "NISDOMAIN=$o->{var}{NISDOMAIN}\n"); + } +} + +# Setting nisdomainname +sub set_nisdomain { + system("nisdomainname $o->{var}{NISDOMAIN}"); +} + + +sub nfs_home_nis { + # test directory + if (-d $HOMENIS) { + print " - $HOMENIS directory exist\n"; + } else { + print " - Creating $HOMENIS directory\n"; + mkdir_p($HOMENIS); + } + + # check nis home + if (any { /$HOMENIS/ } cat_($NFSEXPORTS)) { + print " - " . $NFSEXPORTS . " ready\n"; + } else { + print " - Adjusting " . $NFSEXPORTS . "\n"; + append_to_file($NFSEXPORTS, "$HOMENIS *(async,rw,no_root_squash)\n"); + } +} + +# configure /etc/auto.* +sub configure_auto { + save_config($AUTOMASTER); + my $nisserver = chomp_($o->{var}{NISSERVER}); + output($AUTOMASTER, <) { + my ($login) = split(':'); + if (!member($login, @unwanted)) { + push(@users, $login); + } + } + close(PASS); + [ @users ]; +} + +sub update_yp { + my ($nd, $yps) = @_; + save_config($YPCONF); + output($YPCONF, <{NETWORKFILE}; + my %conf = getVarsFromSh($nf); + save_config($nf); + setVarsInSh($nf, { %conf, NISDOMAIN => $nd }); +} + +sub update_nsswitch { + substInFile { + s/automount:.*/automount: nis nisplus files/g; + s/hosts.*/hosts: dns nis files/; + } '/etc/nsswitch.conf'; +} + +sub uninstall_rpm { + my ($rpm) = @_; + system("urpme $rpm") if (system('/bin/rpm', '>/dev/null', '-q', $rpm)); +} + +sub do_it_server { + my $in = 'interactive'->vnew('su', 'nisautofsconfig'); + my $w = $in->wait_message(N("Nis+autofs Server"), N("Configuring your system as a Nis+Autofs(nfs) server ...")); +# system("urpme --auto autofs") if (system("/bin/rpm -q autofs >/dev/null")); + uninstall_rpm('autofs'); + system("urpmi --auto-select ypserv"); + needed_service('ypserv'); + # configure autofs to fit nis + configure_auto(); + # set correct nis + set_nisdomain(); + # create all make file needed + adjust_makefile(); + make_yp(); + # update client conf file (also on server) + update_yp(chomp_($o->{var}{NISDOMAIN}), chomp_($HOST)); + # update conf file + update_network(); + # update nsswitch.conf + update_nsswitch(); + # update nfs to fit nis + nfs_home_nis(); + # restart all needed services + map { needed_service($_); $_ } qw(ypserv nfs); + undef $w; +} + +sub do_it_client { + my $in = 'interactive'->vnew('su', 'nisautofsclient'); + my $w = $in->wait_message(N("Nis Client"), N("Configuring your system as Nis Client ...")); + uninstall_rpm('ypserv'); + system("urpmi --auto-select --auto autofs"); + test_autofile(); + # set correct nis + set_nisdomain(); + # update client conf file (also on server) + update_yp(chomp_($o->{var}{NISDOMAIN}), chomp_($o->{var}{NISSERVER})); + # update conf file + update_network(); + map { needed_service($_); $_ } qw(ypbind autofs); + undef $w; +} + +sub new { + my ($class, $conf) = @_; + bless { + o => $o, + }, $class; +} + +1; -- cgit v1.2.1