summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Ginies <aginies@mandriva.com>2003-12-15 10:04:54 +0000
committerAntoine Ginies <aginies@mandriva.com>2003-12-15 10:04:54 +0000
commitdeb51774de746564a74e40be72d783b9cd7e42f2 (patch)
treeba2e521824b3f1f2ba7a24fad804d3c8fbbf4bbe
parent7c4c113148bd4d5893a3826a4d741d4ac09ab18d (diff)
downloaddrakwizard-deb51774de746564a74e40be72d783b9cd7e42f2.tar
drakwizard-deb51774de746564a74e40be72d783b9cd7e42f2.tar.gz
drakwizard-deb51774de746564a74e40be72d783b9cd7e42f2.tar.bz2
drakwizard-deb51774de746564a74e40be72d783b9cd7e42f2.tar.xz
drakwizard-deb51774de746564a74e40be72d783b9cd7e42f2.zip
add nis+autofs Server and client side
-rw-r--r--nisautofs_wizard/Makefile8
-rw-r--r--nisautofs_wizard/Nisautofs.pm342
2 files changed, 350 insertions, 0 deletions
diff --git a/nisautofs_wizard/Makefile b/nisautofs_wizard/Makefile
new file mode 100644
index 00000000..9fc46808
--- /dev/null
+++ b/nisautofs_wizard/Makefile
@@ -0,0 +1,8 @@
+install2:
+ su -c 'make install'
+
+install:
+ mkdir -p --mode=u=rwx,g=rx,o=rx ${prefix}/share/wizards/nisautofs_wizard/images
+ mkdir -p --mode=u=rwx,g=rx,o=rx ${prefix}/$(PERL_VENDORLIB)/MDK/Wizard
+ install --mode=u=rw,g=r,o=r -p *.pm ${prefix}/$(PERL_VENDORLIB)/MDK/Wizard/
+ install --mode=a=r -p ./images/*.png ${prefix}/share/wizards/nisautofs_wizard/images
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, <<EOF);
+$HOMENIS auto.home --timeout=60
+EOF
+
+ save_config($AUTOHOME);
+ output($AUTOHOME, <<EOF);
+* -rw,nfs,soft,intr,nosuid,rsize=8192,wsize=8192 $nisserver:$HOMENIS/&
+EOF
+}
+
+sub adjust_makefile {
+# Makefile parameter
+ print " - Updating " . $NIS_DIRMAKEFILE . " to add autofs\n";
+ mkdir_p('/etc/mail');
+ system('touch /etc/mail/aliases');
+ substInFile {
+ s!^ALIASES!#ALIASES=/etc/aliases!g;
+ s/^all.*/all: passwd group hosts rpc services netid protocols auto.master auto.home/g;
+ } $NIS_DIRMAKEFILE . '/Makefile';
+}
+
+# create yp base
+sub make_yp {
+ system("make -C $NIS_DIRMAKEFILE");
+}
+
+sub needed_service {
+ my ($service) = @_;
+ if (services::is_service_running($service)) {
+ services::restart($service)
+ } else { services::start($service) }
+}
+
+sub get_nis_users {
+ my @unwanted = qw(install maui nobody mpi);
+ my @users;
+ open(PASS, "ypcat passwd|") || die " cant exec ypcat passwd!";
+ while(<PASS>) {
+ my ($login) = split(':');
+ if (!member($login, @unwanted)) {
+ push(@users, $login);
+ }
+ }
+ close(PASS);
+ [ @users ];
+}
+
+sub update_yp {
+ my ($nd, $yps) = @_;
+ save_config($YPCONF);
+ output($YPCONF, <<EOF);
+# /etc/yp.conf - ypbind configuration file
+# domain NISDOMAIN server HOSTNAME
+# Use server HOSTNAME for the domain NISDOMAIN.
+#domain NISDOMAIN broadcast
+# Use broadcast on the local net for domain NISDOMAIN
+#
+#ypserver HOSTNAME
+# Use server HOSTNAME for the local domain. The
+# IP-address of server must be listed in /etc/hosts.
+#
+domain $nd server $yps
+EOF
+}
+
+sub test_autofile {
+ map { if (-e $_) { rm_rf($_) } ; $_} $AUTOHOME, $AUTOMASTER;
+}
+
+sub save_config {
+ my ($old) = @_;
+ my $DATE = chomp_(`date +%d-%m-20%y`);
+ if (-f $old) {
+ cp_af($old, $old . '.' . $DATE);
+ }
+ return($old . '.' . $DATE);
+}
+
+sub update_network_nisdomain {
+ my ($nd) = @_;
+ my $nf = cluster_commonconf::system_network()->{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;