#/usr/bin/perl -w # version 0.3 # # 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 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 $NISDOMAIN = chomp_(`dnsdomainname`); 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 => 'NIS Configuration Wizard', var => { NISDOMAIN => chomp_($NISDOMAIN), NISSERVER => chomp_($HOST), NIS_DIRMAKEFILE => $NIS_DIRMAKEFILE, HOMENIS => $HOMENIS, NETWORKFILE => $NETWORKFILE, NFSEXPORTS => $NFSEXPORTS, AUTOMASTER => $AUTOMASTER, AUTOHOME => $AUTOHOME, }, needed_rpm => [ 'ypbind', 'nfs-utils', 'yp-tools', 'nfs-utils-clients' ], defaultimage => "$ENV{__WIZ_HOME__}/nisautofs_wizard/images/nisautofs.png", init => sub { if (member($NISDOMAIN, qw(localdomain (none)))) { return 0, N("You need to readjust your NIS domainname. For a NIS server you need a correct NIS domainname, not equal to localdomain or none.") } 1 }, }; my %level = ( 1 => N("NIS server with autofs map"), 2 => N("NIS client"), ); $o->{pages} = { welcome => { name => N("NIS server with autofs map") . "\n\n" . N("Setup a NIS server with autofs map, auto.home and auto.master files.") . "\n\n" . N("Users automatically mount their home directory from server, when they log on a NIS client computer network."), no_back => 1, pre => sub { $o->{var}{wiz_level} ||= 1 }, post => sub { if ($o->{var}{wiz_level} == 2) { return 'nis_client' } }, data => [ { label => N("What do you want to do ?"), val => \$o->{var}{wiz_level}, list => [ keys %level ], format => sub { $level{$_[0]} } }, ], next => 'nis_server', }, nis_client => { name => N("Configure computer to 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 server with autofs map") . "\n\n" . N("A NIS server is useful to create user, hostname database. The wizard also build autofs map, so it provides the capabilities for NIS user to automount their home directory on a NIS client computer.") . "\n\n" . N("NIS server: name of your computer.") . "\n" . N("Home NIS: home base directory for users on NIS server. This directory will be export through NFS server.") . "\n" . N("NIS domain: NIS domain to use (generally same as your DNS domainaname)."), data => [ { label => N("NIS server:"), val => $HOST }, { label => N("Home NIS:"), val => \$o->{var}{HOMENIS} }, { label => N("NIS domainname:"), val => \$o->{var}{NISDOMAIN} }, ], post => \&test_set, next => 'summaryserver', }, summaryserver => { name => N("The wizard will set your NIS server with autofs map"), data => [ { label => N("NIS server:"), fixed_val => \$HOST }, { label => N("Home NIS:"), fixed_val => \$o->{var}{HOMENIS} }, { label => N("NIS domainname:"), fixed_val => \$o->{var}{NISDOMAIN} }, { label => N("NIS directory:"), 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("The YPBIND daemon finds the server for NIS domains and maintains the NIS binding information.") . "\n\n" . N("NIS server: hostname of the NIS server.") . "\n" . N("NIS domainname: name of NIS domain."), data => [ { label => N("NIS server:"), fixed_val => \$o->{var}{NISSERVER} }, { label => N("NIS domainname:"), 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 not be 'none' or 'localdomain'") . "\n\n" . N("Please adjust it."), 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 server with autofs map.") } ], no_back => 1, end => 1, next => 0 }, error_end => { name => N("Failed"), data => [ { label => N("Relaunch drakwizard, and try to change some parameters.") } ], 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 $HOMENIS = $o->{var}{HOMENIS}; 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 --auto");# if (system('/bin/rpm', '>/dev/null', '-q', $rpm)); } sub do_it_server { return if $::testing; my $in = 'interactive'->vnew('su', 'nisautofsconfig'); my $w = $in->wait_message(N("NIS with Autofs map"), N("Configuring your system to be a NIS server with Autofs map...")); # system("urpme --auto autofs") if (system("/bin/rpm -q autofs >/dev/null")); uninstall_rpm('autofs'); system("urpmi --auto --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 needed_service($_) foreach qw(ypserv nfs); undef $w; check_started($_) foreach qw(ypserv nfsd); } sub do_it_client { return if $::testing; 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(); needed_service($_) foreach qw(ypbind autofs); undef $w; check_started($_) foreach qw(ypbind autofs); } sub new { my ($class) = @_; bless { o => $o, }, $class; } 1;