summaryrefslogtreecommitdiffstats
path: root/installsrv_wizard/Installsrv.pm
blob: 9494f9e0b90f61d2118fbcaf79b6eac3da3873cb (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
# 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 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 $o = {
	 name => 'MDK Install Server Wizard',
	 var => {
		 DESTDIR => '/var/install/cooker',
		 SOURCEDIR => '/mnt/nfs/cooker',
		},
	 needed_rpm => [ 'nfs-utils', 'apache' ],
	 defaultimage => "/usr/share/wizards/installsrv_wizard/images/Install.png"
	};

$o->{pages} = {
	       welcome => {
			   name => N("Configure a MDK install server (via NFS and http)") . "\n\n" . N("Easily configure a Mandrake 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 Mandrake installation.") . "\n\n" . N("Destination directory: copy file in wich 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("Destination directory could not be '/var/install/'") . "\n\n" . N("ie use: /var/install/mdk-release"),
				  next => 'install_srv',
				 },
	       error_dir => {
			     name => N("Error, source directory must be a directory with full Mandrake installation directory."),
			     next => 'install_srv',
			    },
	       dir_already_use => {
				   name => N("Destination directory already in use, please choose another one."),
				   next => 'install_srv',
				  },
	       summary_srv => {
			       name => N("I Will configure your install server with those 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} },
                                       ],
                               post => \&do_it,
                               next => 'end',
			      },
	       end => {
		       name => N("Congratulations, Mandrake Install server is now ready."),
		       end => 1,
		       no_back => 1,
		       next => 0
		      },
	      };


sub add_install_dir {
  if (any { /$INSTALLDIR/ } cat_($NFSEXPORTS)) {
    print " - " . $NFSEXPORTS . " ready\n";
  } else {
    append_to_file($NFSEXPORTS, "$INSTALLDIR       *(async,rw,no_root_squash)\n");
    system("service nfs reload");
  }
}

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;
  }
  system("service httpd restart");
}

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

sub do_it {
  return if $::testing;
  my $in = 'interactive'->vnew('su', 'Install server');
  my $w = $in->wait_message(N("Install Server"), N("Copying data to destination directory, can take a while...."));
  cp_data($o->{var}{SOURCEDIR}, $o->{var}{DESTDIR});
  add_install_dir();
  add_http_link($o->{var}{DESTDIR});
  undef $w;
}

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

1;