summaryrefslogtreecommitdiffstats
path: root/mgaupdate
blob: 4678bf0b0f8533fa8dc34008078e8fb354352bc7 (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
#!/usr/bin/perl
################################################################################
# Mgaupdate                                                                    #
#                                                                              #
# Copyright (C) 2002-2010 Mandriva                                             #
#               2010-2015 Mageia                                               #
#                                                                              #
# Daouda Lo                                                                    #
# Thierry Vignaud <thierry.vignaud at gmail dot com>                           #
#                                                                              #
# 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,  see <http://www.gnu.org/licenses/>.        #
################################################################################

# workaround standalone.pm eating "--auto" from @ARGV:
BEGIN { $::no_global_argv_parsing = 1 }

use strict;
use POSIX;
use lib qw(/usr/lib/libDrakX /usr/lib/libDrakX/drakfirsttime);
use standalone; # for explanations
use common;
use interactive;
use URI::Escape;
use run_program;

use mgaonline;

use Getopt::Long;

BEGIN { unshift @::textdomains, 'mgaupdate' }

require_root_capability();

my $confdir = '/root/.MdkOnline';
my $conffile = "$confdir/mgaupdate";

my $logfile = '/var/tmp/mgaupdate.log';


my $CLIENT_VERSION = "4";
my $YEARS = "2002-2006";
my $MGA_YEARS = "2010-2012";

#for compatibilities with former versions
mkdir_p($confdir) if !-d $confdir;
-e '/root/.mgaupdate' and system "/bin/mv", "/root/.mgaupdate", $conffile;


sub usage() {
    print STDERR N("mgaupdate version %s
%s
This is free software and may be redistributed under the terms of the GNU GPL.

usage:
", $CLIENT_VERSION,
N("Copyright (C) %s %s", $YEARS, 'Mandriva') . N("Copyright (C) %s %s", $MGA_YEARS, 'Mageia')) . N("  --help		- print this help message.
") . N("  --auto		- Mageia Update launched automatically.
") . N("  --mnf			- launch mnf specific scripts.
") . N("  --noX			- text mode version of Mageia Update.
") . N("  --debug			- log what is done
");
    exit(0);
}

my ($auto, $mnf, $noX, $debug);
my %options = (
	       'auto'	    => \$auto,
	       'mnf'	    => \$mnf,
	       'noX'	    => \$noX,
            'd|debug'   => \$debug,
	       'h|help'    => \&usage,
	      );

GetOptions(%options);

-e $logfile and rm_rf($logfile);

my $ret = update_pkgs();
if ($ret != 1) {
    output_p($logfile, "[mgaupdate] Error 100: Packages failed to upgrade");
    log::explanations("[mgaupdate] Error 100: Packages failed to upgrade");
}
clean_dir();


sub update_pkgs {
    my (@pkgs) = @_;
    eval {
	run_program::raw({ timeout => 'never' }, '/usr/sbin/urpmi', '--auto-update', '--auto', '--keep', '--update', map { if_(/(.*)-[^-]*-[^-]*\.[^-.]*?\.rpm$/, $1) } @pkgs);
	$? == 0 or die N("Unable to update packages from update_source medium.\n");
    };
    $@ and output_p($logfile, "[mgaupdate] Error 99: $@"), return 0;
    return 1;
}

sub clean_dir() {
    mgaonline::clean_confdir();
    output_p($logfile, 'OK');
}