summaryrefslogtreecommitdiffstats
path: root/installsrv_wizard/Installsrv.pm
blob: 86fbc5ec97b8004bec1586d7c14f76496820d282 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# version 0.2
#
# Copyright (C) 2004 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::Installsrv;
#use lib qw(/usr/lib/libDrakX);
#use ugtk2 qw(:ask :helpers :wrappers :create :dialogs);
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 $INSTALLDIR = "/var/install/";
my $NFSEXPORTS = "/etc/exports";
my $WWWDIR = "/var/www/html";
my $testy;

my $o = {
	 name => 'MDK Install Server Wizard',
	 var => {
		 DESTDIR => '/var/install/clic',
		 SOURCEDIR => '/home/nis/install/clic',
		},
	 needed_rpm => [ 'nfs-utils', 'apache2' ],
	 defaultimage => "$ENV{__WIZ_HOME__}/installsrv_wizard/images/Install.png"
	};

$o->{pages} = {
	       welcome => {
			   name => N("Configure a Mandrakelinux install server (via NFS and http)") . "\n\n" . N("Easily configure a Mandrakelinux server installation directory, with NFS and HTTP access."),
			   no_back => 1,
			   next => 'install_srv',
			  },
	       install_srv => {
			       name => N("Install server configuration") . "\n\n" . N("Path to data: specify your source directory, should be base of an Mandrakelinux installation.") . "\n\n" . N("Destination directory: copy file in which directory?"),
			       pre => sub {
				 $o->{var}{wiz_nfs} ||= 1;
				 $o->{var}{wiz_http} ||= 1;
			       },
			       data => [
					{ label => "Path to data:", val => \$o->{var}{SOURCEDIR} },
					{ label => "Destination directory:", val => \$o->{var}{DESTDIR} },
#					{ label => N("Enable NFS install server:"), type => 'bool', val => \$o->{var}{wiz_nfs} },
#					{ label => N("Enable HTTP  install server:"), type => 'bool', val => \$o->{var}{wiz_http} },
				       ],
			       post => \&test_data,
			       next => 'summary_srv',
			      },
	       error_dir_dest => {
				  name => N("The destination directory could not be '/var/install/'") . "\n\n" . N("ie use: /var/install/mdk-release"),
				  next => 'install_srv',
				 },
	       error_dir => {
			     name => N("Error, the source path must be a directory with full Mandrakelinux installation directory."),
			     next => 'install_srv',
			    },
	       dir_already_use => {
				   name => N("The destination directory already in use, please choose another one."),
				   next => 'install_srv',
				  },
	       summary_srv => {
			       name => N("Your install server will be configured with these parameters"),
			       pre => sub {
				 $o->{var}{nfs} = $o->{var}{wiz_nfs} ? N("enabled") : N("disabled");
				 $o->{var}{http} = $o->{var}{wiz_http} ? N("enabled") : N("disabled");
			       },
			       data => [
					{ label => "Path to data:", fixed_val => \$o->{var}{SOURCEDIR} },
					{ label => "Destination directory:", fixed_val => \$o->{var}{DESTDIR} },
					{ label => N("Enable NFS install server:"), fixed_val => \$o->{var}{nfs} },
					{ label => N("Enable HTTP install server:"), fixed_val => \$o->{var}{http} },
                                       ],
			       complete => \&do_it,
                               next => 'wait',
			      },
	       wait => {
			name => N("Configuring your system, please wait..."),
			next => 'end',
		       },
	       end => {
		       name => N("Congratulations, Mandrakelinux Install server is now ready. You can now configure a DHCP server with PXE support, and a PXE server. So it will be very easy to install Mandrakelinux through a network."),
		       end => 1,
		       no_back => 1,
		       next => 0
		      },
	      };


sub add_install_dir {
  if (any { /$o->{var}{DESTDIR}/ } cat_($NFSEXPORTS)) {
    print " - " . $NFSEXPORTS . " ready\n";
  } else {
    append_to_file($NFSEXPORTS, "$->{var}{DESTDIR}       *(async,rw,no_root_squash)\n");
    check_started($_) foreach qw(nfs nfsd);
  }
}

sub test_data {
  -d $o->{var}{SOURCEDIR} && -f "$o->{var}{SOURCEDIR}/VERSION" or return 'error_dir';
  if ($o->{var}{DESTDIR} eq $INSTALLDIR) { return 'error_dir_dest' }
  if (-e $o->{var}{DESTDIR}) { return 'dir_already_use' }
}

sub add_ftpuser {
    system("/usr/sbin/useradd -u 12383 -d install -r -s /bin/bash install");
}

sub add_http_link {
  my ($PATH) = @_;
  my $LINK = $WWWDIR . '/' . basename($PATH);
  if (! -f $LINK) {
    symlink $PATH, $LINK;
  }
  check_started("httpd")
}

sub cp_data {
  my ($SRCDIR, $DEST) = @_;
  mkdir_p($DEST);
  system("cp -av $SRCDIR/* $DEST");
}

sub do_it {
  return if $::testing;
  my $S = $o->{var}{SOURCEDIR};
  my $D = $o->{var}{DESTDIR};
  if (! -d $D) { mkdir_p($D) }
  run_command_and_log("cp -avf $S/* $D", "Copying data $S/* $D");
  add_install_dir();
  add_http_link($o->{var}{DESTDIR});
  return 0;
}

sub new {
    my ($class) = @_;
    bless {
            o   => $o,
       }, $class;
}

1;