#/usr/bin/perl -w # version 0.3 # # Copyright (C) 2002,2005 Mandrakesoft # # Author: aginies _at_ mandriva.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_(`nisdomainname`); 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, create_missing_directory => '', }, needed_rpm => [ 'ypserv', 'ypbind', 'nfs-utils', 'yp-tools', 'nfs-utils-clients' ], defaultimage => "$ENV{__WIZ_HOME__}/nisautofs_wizard/images/nisautofs.png", init => sub { test_host_domain($HOST, $NISDOMAIN); }, }; $::Wizard_pix_up = "/usr/share/mcc/themes/default/nisautofs.png"; $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, next => 'nis_server', }, nis_server => { name => N("NIS server with autofs map") . "\n" . N("A NIS server is useful to create user, hostname database. The wizard builds autofs map, so it will provide 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 exported through NFS server.") . "\n" . N("NIS domain: NIS domain to use (generally same as your DNS domain name)."), data => [ { label => N("NIS server:"), val => $HOST }, { label => N("Home NIS:"), val => \$o->{var}{HOMENIS} }, { label => N("NIS domainname:"), val => \$o->{var}{NISDOMAIN} }, { text => N("Create home NIS directory if it doesn't exist"), type => 'bool', val => \$o->{var}{create_missing_directory} }, ], complete => sub { if (!-d $o->{var}{HOMENIS} and $o->{var}{create_missing_directory}) { mkdir_p($o->{var}{HOMENIS}); } elsif (!-d $o->{var}{HOMENIS}) { $::in->ask_warn(N("Warning"), N("Directory doesn't exist. Please create it manually.")); return 0; } if ($o->{var}{NISDOMAIN} eq '(none)' || !$o->{var}{NISDOMAIN}) { return 'error_nisd' } }, 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', }, error_nisd => { name => N("Error: nisdomainname should not be 'none' or 'localdomain'.") . "\n\n" . N("Please adjust it."), no_back => 1, next => 'nis_server', }, 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 { $HOMENIS = $o->{var}{HOMENIS}; 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'); # 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; needed_service("ypbind"); check_started($_) foreach qw(ypserv nfsd); } sub new { my ($class) = @_; bless { o => $o, }, $class; } 1;