aboutsummaryrefslogtreecommitdiffstats
path: root/Rpmdrake/init.pm
blob: e4d12a39bbd0bed324d0fe79bf89fbff245e4b2b (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
165
166
167
168
169
170
171
172
173
174
175
176
177
package Rpmdrake::init;
#*****************************************************************************
#
#  Copyright (c) 2002 Guillaume Cottenceau
#  Copyright (c) 2002-2007 Thierry Vignaud <tvignaud@mandriva.com>
#  Copyright (c) 2003, 2004, 2005 MandrakeSoft SA
#  Copyright (c) 2005-2007 Mandriva SA
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License version 2, as
#  published by the Free Software Foundation.
#
#  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.
#
#*****************************************************************************
#
# $Id$

use strict;
use MDK::Common::Func 'any';
use lib qw(/usr/lib/libDrakX);
use common;
BEGIN { $::no_global_argv_parsing = 1 }

use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(init warn_about_user_mode $changelog_first $default_list_mode %options $MODE);

BEGIN {  #- we want to run this code before the Gtk->init of the use-my_gtk
    my $basename = sub { local $_ = shift; s|/*\s*$||; s|.*/||; $_ };
    any { /^--?h/ } @ARGV and do {
	printf join("\n", N("Usage: %s [OPTION]...", $basename->($0)),
N("  --changelog-first      display changelog before filelist in the description window"),
N("  --media=medium1,..     limit to given media"),
N("  --merge-all-rpmnew     propose to merge all .rpmnew/.rpmsave files found"),
N("  --mode=MODE            set mode (install (default), remove, update)"),
N("  --no-confirmation      don't ask first confirmation question in update mode"),
N("  --no-media-update      don't update media at startup"),
N("  --no-verify-rpm        don't verify packages signatures"),
N("  --parallel=alias,host  be in parallel mode, use \"alias\" group, use \"host\" machine to show needed deps"),
N("  --pkg-nosel=pkg1,..    show only these packages"),
N("  --pkg-sel=pkg1,..      preselect these packages"),
N("  --root                 force to run as root"),
N("  --search=pkg           run search for \"pkg\""),
chomp_(N("  --version      - print this tool's version number.
")),
""
);
	exit 0;
    };
}

BEGIN { #- for mcc
    if ("@ARGV" =~ /--embedded (\w+)/) {
	$::XID = $1;
	$::isEmbedded = 1;
    }
}

use rpmdrake;

#- This is needed because text printed by Gtk2 will always be encoded
#- in UTF-8; we first check if LC_ALL is defined, because if it is,
#- changing only LC_COLLATE will have no effect.
use POSIX qw(setlocale LC_ALL LC_COLLATE strftime);
use locale;
my $collation_locale = $ENV{LC_ALL};
if ($collation_locale) {
  $collation_locale =~ /UTF-8/ or setlocale(LC_ALL, "$collation_locale.UTF-8");
} else {
  $collation_locale = setlocale(LC_COLLATE);
  $collation_locale =~ /UTF-8/ or setlocale(LC_COLLATE, "$collation_locale.UTF-8");
}

my $version = 1;
our %options;
foreach (@ARGV) {
    /^-?-(\S+)$/ or next;
    my $val = $1;
    if ($val =~ /=/) {
        my ($name, $values) = split /=/, $val;
        my @values = split /,/, $values;
        $options{$name} = \@values if @values;
    } else {
        if ($val eq 'version') {
            print "$0 $version\n";
            exit(0);
       }
        $options{$val} = 1;
    }
}

foreach my $option (qw(media mode parallel pkg-nosel pkg-sel search)) {
    if (defined $options{$option} && !ref($options{$option})) {
        warn "wrong usage of \"$option\" option!\n";
        exit(-1); # too early for my_exit()
    }
}

our $MODE = ref $options{mode} ? $options{mode}[0] : undef;
unless ($MODE) {
    $MODE = 'install';
    $0 =~ m|remove$|  and $MODE = 'remove';
    $0 =~ m|update$|i and $MODE = 'update';
}

our $default_list_mode;
$default_list_mode = 'all' if $MODE eq 'install';
if ($MODE eq 'remove') {
    $default_list_mode = 'installed';
} elsif ($MODE eq 'update') {
    $default_list_mode = 'all_updates';
}

$MODE eq 'update' || $options{root} and require_root_capability();
$::noborderWhenEmbedded = 1;

our $changelog_first = $changelog_first_config->[0];
$changelog_first = 1 if $options{'changelog-first'};

sub warn_about_user_mode() {
    $> and (interactive_msg(N("Running in user mode"),
                            N("You are launching this program as a normal user.
You will not be able to perform modifications on the system,
but you may still browse the existing database."), yesno => 1, text => { no => N("Cancel"), yes => N("Ok") }) or myexit(0));
}

sub init() {
    if (!$> && !member($MODE, @$already_splashed)) {
        interactive_msg(N("Welcome"),
                        N("%s

Is it ok to continue?",
                          $MODE eq 'remove' ?
                            N("Welcome to the software removal tool!

This tool will help you choose which software you want to remove from
your computer.")
                              : $MODE eq 'update' ?
                                N("Welcome to %s!

This tool will help you choose the updates you want to install on your
computer.", $rpmdrake::myname_update)
                                  :
                                    ($rpmdrake::branded ? N("Welcome to the software installation tool!")
                                       : N("Welcome to the software installation tool!

Your Mandriva Linux system comes with several thousands of software
packages on CDROM or DVD. This tool will help you choose which software
you want to install on your computer.")))
                          , yesno => 1) or myexit(-1);
        push @$already_splashed, $MODE;
    }
    if (!$> && !$offered_to_add_sources->[0]) {
        if (interactive_msg(N("Welcome"),
                            join("\n\n",
                                 N("The software installation tool can set up media sources."),
                                 N("Do you want to add media sources now?"),
                                 ),
                            yesno => 1,
                        )
        ) {
            require Rpmdrake::edit_urpm_sources;
            Rpmdrake::edit_urpm_sources::easy_add_callback();
        }
        $offered_to_add_sources->[0] = 1;
    }
}

1;