1 |
#!/usr/bin/perl |
2 |
################################################################################ |
3 |
# Mgaupdate # |
4 |
# # |
5 |
# Copyright (C) 2002-2006 Mandriva # |
6 |
# # |
7 |
# Daouda Lo # |
8 |
# Thierry Vignaud <tvignaud at mandriva dot com> # |
9 |
# # |
10 |
# This program is free software; you can redistribute it and/or modify # |
11 |
# it under the terms of the GNU General Public License Version 2 as # |
12 |
# published by the Free Software Foundation. # |
13 |
# # |
14 |
# This program is distributed in the hope that it will be useful, # |
15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
17 |
# GNU General Public License for more details. # |
18 |
# # |
19 |
# You should have received a copy of the GNU General Public License # |
20 |
# along with this program; if not, write to the Free Software # |
21 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # |
22 |
################################################################################ |
23 |
|
24 |
# workaround standalone.pm eating "--auto" from @ARGV: |
25 |
BEGIN { $::no_global_argv_parsing = 1 } |
26 |
|
27 |
use strict; |
28 |
use POSIX; |
29 |
use lib qw(/usr/lib/libDrakX /usr/lib/libDrakX/drakfirsttime); |
30 |
use standalone; # for explanations |
31 |
use common; |
32 |
use interactive; |
33 |
use URI::Escape; |
34 |
use run_program; |
35 |
|
36 |
use mgaonline; |
37 |
|
38 |
use Getopt::Long; |
39 |
|
40 |
BEGIN { unshift @::textdomains, 'mgaupdate' } |
41 |
|
42 |
require_root_capability(); |
43 |
|
44 |
my $confdir = '/root/.MdkOnline'; |
45 |
my $conffile = "$confdir/mgaupdate"; |
46 |
|
47 |
my $logfile = '/var/tmp/mgaupdate.log'; |
48 |
|
49 |
|
50 |
my $CLIENT_VERSION = "4"; |
51 |
my $YEARS = "2002-2006"; |
52 |
my $MGA_YEARS = "2010-2011"; |
53 |
|
54 |
#for compatibilities with former versions |
55 |
mkdir_p($confdir) if !-d $confdir; |
56 |
-e '/root/.mgaupdate' and system "/bin/mv", "/root/.mgaupdate", $conffile; |
57 |
|
58 |
|
59 |
sub usage() { |
60 |
print STDERR N("mgaupdate version %s |
61 |
Copyright (C) %s Mandriva. |
62 |
Copyright (C) %s Mageia. |
63 |
This is free software and may be redistributed under the terms of the GNU GPL. |
64 |
|
65 |
usage: |
66 |
", $CLIENT_VERSION, $YEARS, $MGA_YEARS) . N(" --help - print this help message. |
67 |
") . N(" --auto - Mageia Update launched automatically. |
68 |
") . N(" --mnf - launch mnf specific scripts. |
69 |
") . N(" --noX - text mode version of Mageia Update. |
70 |
") . N(" --debug - log what is done |
71 |
"); |
72 |
exit(0); |
73 |
} |
74 |
|
75 |
my ($auto, $mnf, $noX, $debug); |
76 |
my %options = ( |
77 |
'auto' => \$auto, |
78 |
'mnf' => \$mnf, |
79 |
'noX' => \$noX, |
80 |
'd|debug' => \$debug, |
81 |
'h|help' => \&usage, |
82 |
); |
83 |
|
84 |
GetOptions(%options); |
85 |
|
86 |
-e $logfile and rm_rf($logfile); |
87 |
|
88 |
my $ret = update_pkgs(); |
89 |
if ($ret != 1) { |
90 |
output_p($logfile, "[mgaupdate] Error 100: Packages failed to upgrade"); |
91 |
log::explanations("[mgaupdate] Error 100: Packages failed to upgrade"); |
92 |
} |
93 |
clean_dir(); |
94 |
|
95 |
|
96 |
sub update_pkgs { |
97 |
my (@pkgs) = @_; |
98 |
eval { |
99 |
run_program::raw({ timeout => 'never' }, '/usr/sbin/urpmi', '--auto-update', '--auto', '--keep', '--update', map { if_(/(.*)-[^-]*-[^-]*\.[^-.]*?\.rpm$/, $1) } @pkgs); |
100 |
$? == 0 or die N("Unable to update packages from update_source medium.\n"); |
101 |
}; |
102 |
$@ and output_p($logfile, "[mgaupdate] Error 99: $@"), return 0; |
103 |
return 1; |
104 |
} |
105 |
|
106 |
sub clean_dir() { |
107 |
mgaonline::clean_confdir(); |
108 |
output_p($logfile, 'OK'); |
109 |
} |