summaryrefslogtreecommitdiffstats
path: root/drakwizard.pl
blob: ad735e1b3eeba142e4093b67115cefef22caefe9 (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
#!/usr/bin/perl

# Drakwizard

# Copyright (C) 2003 Mandrakesoft 
#
# Author: Florent Villard <warly@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.

use lib qw(/usr/lib/libDrakX);
use strict;

use standalone;
use interactive;
use common;

#- I18N.
push @::textdomains, 'drakwizard';

$::isWizard = 1;
$::Wizard_no_previous = 1;
$::Wizard_title = "Drakwizard";
$::Wiz_dir = '/usr/share/wizards/';
my $in = interactive->vnew;
my $standalone = 1;
		
my %wiz = (
       apache => ['Apache', "Apache web server"],
       dhcp => ['Dhcp', "Dhcp server"],
       bind => ['Bind', "Dns (configuration)"],
       bind_client => ['Bind_client', "Dns (add client)"],
       inn => ['Inn', "News server"],
       nfs => ['NFS', "NFS server"],
       postfix => ['Postfix', "Mail server"],
       proftpd => ['Proftpd', "Ftp server"],
       samba => ['Samba', "Samba server"],
       squid => ['Squid', "Proxy"],
       ntp => ['Ntp', "Time server"],
       apache2 => ['Apache', "Apache2 web server", { ver => 2 }]
      );

if (!defined($wiz{$ARGV[0]})) {
    $in->ask_from(
		  N("Drakwizard wizard selection"),
		  N("Please select a wizard"),
		  [{ val => \$ARGV[0], list => [sort { $wiz{$a}[1] cmp $wiz{$b}[1] } keys %wiz], format => sub { $wiz{$_[0]}[1] }}]
		 );
    push @ARGV, @{$wiz{$ARGV[0]}}[0,2];
}

require "MDK/Wizard/$wiz{$ARGV[0]}[0].pm";

my ($wiz, $err) = "MDK::Wizard::$wiz{$ARGV[0]}[0]"->new($wiz{$ARGV[0]}[2]);
if ($err) {
    $::Wizard_finished = 1;
    $in->ask_okcancel("error", N($err));
    $in->exit;
}
wizard($wiz->{o});

$in->exit;

sub wizard {
    my ($o) = @_;
    my $page = $o->{pages}{welcome};
    $::Wizard_title = $o->{name};
    $::Wizard_pix_up = $o->{defaultimage};
    if ($> && !$o->{allow_user} && !$::testing) {
	require_root_capability();
    } 
    check_rpm($o->{needed_rpm}) if $o->{needed_rpm};
    if (defined $o->{init}) {
	my ($res, $msg) = &{$o->{init}};
	if (!$res) {
	    $in->ask_okcancel("error", $msg);
	    exit if ! $::testing
	}
    }
    
    my $next = 'welcome';
    my @steps;
    while (1) {
	undef $::Wizard_no_previous; 
        undef $::Wizard_no_cancel;
	$::Wizard_no_previous = $page->{no_back};
	$::Wizard_finished = $page->{end};
	$::Wizard_no_cancel = $page->{no_cancel} || $page->{end};
	defined $page->{pre} and $page->{pre}();
	# FIXME or the displaying fails
	my $data = defined $page->{data} ? ref $page->{data} ? $page->{data} : [ { label => '' } ] : [ { label => '' } ];
	my $data2;
	foreach my $d (@$data) {
	    $d->{fixed_val} and $d->{val} = ${$d->{fixed_val}};
	    if ($d->{fixed_list}) {
		$d->{list} = $d->{fixed_list}; 
	    }
	    if (ref $d->{boolean_list} && ref ${$d->{boolean_list}}) { 
		my $i;
		foreach (@{${$d->{boolean_list}}}){ 
		    push @{$data2},  { text => $_, type => 'bool', val => \${$d->{val}}->[$i], disabled => $d->{disabled} };
		    $i++
		}
	    } else {
		push @{$data2}, $d
	    }
	}
	my $a = $in->ask_from($o->{name}, $page->{name}, $data2);
	if ($a) {
	    push @steps, $next if !$page->{ignore} && $steps[$#steps] ne $next;
	    $next = defined $page->{post} ? $page->{post}() : 0;
	    defined $o->{pages}{$next} or $next = $page->{next};
	} else {
	   $next = pop @steps
        }
	$next or return;
	$page = $o->{pages}{$next}
    }
}

sub check_rpm {
    my ($rpms) = @_;
    foreach my $rpm (@$rpms) {
	if (!$in->do_pkgs->is_installed($rpm)) {
	    if ($in->ask_okcancel("error", N("%s is not installed\nClick \"Next\" to install or \"Cancel\" to quit", c::from_utf8($rpm)))) {
		$::testing and next;
		if (!$in->do_pkgs->install($rpm)) {
		    $::Wizard_finished = 1;
		    $in->ask_okcancel("error", N("installation failed"));
		    $in->exit;
		}
	    }
	    else { $in->exit }
	}
    }
}