summaryrefslogtreecommitdiffstats
path: root/mdvonline_agent.pl
blob: 04709444aeffda8deef9b17e57da02fea60582f5 (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 -w
################################################################################
# mdvonline_agent                                                              # 
#                                                                              #
# Copyright (C) 2005 Mandriva                                                  #
#                                                                              #
# Romain d'Alverny <rdalverny at mandriva 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, write to the Free Software                  #
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.   #
################################################################################

# $Id$

use strict;
use POSIX;
use lib qw(/usr/lib/libDrakX /usr/lib/libDrakX/drakfirsttime);
use common;
use mdkonline;
use Data::Dumper;

# DNS service discovery
use Discover;

# logging
use Log::Agent;
require Log::Agent::Driver::File;  # logging made to file
logconfig(
	-driver => Log::Agent::Driver::File->make(
        -prefix  => $0,
        -showpid => 1,
        -file    => 'mdvonline.log',
    ),
    #-caller => [ -display => '($sub/$line)', -postfix => 1 ],
    -priority => [ -display => '[$priority]' ],
);

# TODO set this in mdkonline.pm ?
my $conffile = '/etc/sysconfig/mdkonline';
my $service  = 'https://localhost/~romain/online3/htdocs/service';

# script starts here
mdkonline::is_running('mdvonline_agent')
	and die "mdvonline_agent already running\n";

#require_root_capability();

my %conf;
my $ret = 0;

# 1. check configuration (local) or set from dns if any
if( ( -e $conffile ) && ( -s $conffile ) ) {
	%conf = getVarsFromSh($conffile);

	if( defined $conf{MACHINE} && ! defined $conf{VERSION} ) { #|| $conf{VERSION} lt 3 ) {
		logsay "old configuration detected: trying to migrate to new scheme";
		$ret = mdkonline::upgrade_to_v3();
		if( $ret eq 1 ) { logsay "succeeded"; }
		else { logsay "failed"; }
	}
	else {
		if( defined $conf{MOBILE} && $conf{MOBILE} eq 'TRUE' ) {
			# TODO check dns service for a specific update server
			# if there is one, it may supersedes default conf update server
			# or the one provided by the Online server?
		}
		$ret = 1;
	}
}
else {
	logsay "no configuration file found";
	logsay "starting dns service discovery";
	my $sd          = new Discover;
	my $serviceinfo = $sd->search();
	if ( $serviceinfo ) {
		logsay "found service with info";
		print Dumper($serviceinfo);		
		# TODO check service certificate
		# TODO register to service
		# TODO set config file
		$ret = 0;
	}
	else {
		#print Dumper($sd);
		logsay "no service found";
		$ret = 0;
	}	
	$ret = 0;
}

if( $ret eq 1 ) {
	# 2. now check and run task
	print "checking for somethign to do.\n";
	my $task = mdkonline::soap_get_task( $conf{HOST_ID}, $conf{HOST_KEY} );
	print Dumper($task);
}

logsay "done";
$ret;