1 | #!/usr/bin/perl |
---|
2 | #------------------------------------------------------------------------------- |
---|
3 | # Copyright (C) 2006-2021 British Crown (Met Office) & Contributors. |
---|
4 | # |
---|
5 | # This file is part of FCM, tools for managing and building source code. |
---|
6 | # |
---|
7 | # FCM is free software: you can redistribute it and/or modify |
---|
8 | # it under the terms of the GNU General Public License as published by |
---|
9 | # the Free Software Foundation, either version 3 of the License, or |
---|
10 | # (at your option) any later version. |
---|
11 | # |
---|
12 | # FCM is distributed in the hope that it will be useful, |
---|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | # GNU General Public License for more details. |
---|
16 | # |
---|
17 | # You should have received a copy of the GNU General Public License |
---|
18 | # along with FCM. If not, see <http://www.gnu.org/licenses/>. |
---|
19 | #------------------------------------------------------------------------------- |
---|
20 | |
---|
21 | # This is a simplified version of fcm-daily-update which |
---|
22 | # a) doesn't create a log file |
---|
23 | # b) doesn't send an email notification |
---|
24 | # c) sets the exit code to the number of errors |
---|
25 | |
---|
26 | use strict; |
---|
27 | use warnings; |
---|
28 | |
---|
29 | use FindBin; |
---|
30 | use lib "$FindBin::Bin/../lib"; |
---|
31 | use File::Basename qw{basename}; |
---|
32 | |
---|
33 | use FCM::Admin::Config; |
---|
34 | use FCM::Admin::Runner; |
---|
35 | use FCM::Admin::System qw{ |
---|
36 | backup_svn_repository |
---|
37 | backup_trac_environment |
---|
38 | backup_trac_files |
---|
39 | get_projects_from_svn_live |
---|
40 | get_projects_from_trac_live |
---|
41 | get_users |
---|
42 | housekeep_svn_hook_logs |
---|
43 | manage_users_in_svn_passwd |
---|
44 | manage_users_in_trac_passwd |
---|
45 | manage_users_in_trac_db_of |
---|
46 | }; |
---|
47 | |
---|
48 | my $THIS = basename($0); |
---|
49 | my $CONFIG = FCM::Admin::Config->instance(); |
---|
50 | my $UTIL = $FCM::Admin::Config::UTIL; |
---|
51 | |
---|
52 | if (!caller()) { |
---|
53 | main(@ARGV); |
---|
54 | } |
---|
55 | |
---|
56 | sub main { |
---|
57 | local(@ARGV) = @_; |
---|
58 | |
---|
59 | do_tasks(); |
---|
60 | my @exceptions = FCM::Admin::Runner->instance()->get_exceptions(); |
---|
61 | printf(qq{$THIS finished with %d error(s) \n}, scalar(@exceptions)); |
---|
62 | exit(scalar(@exceptions)); |
---|
63 | } |
---|
64 | |
---|
65 | # ------------------------------------------------------------------------------ |
---|
66 | # Performs the daily update tasks. |
---|
67 | sub do_tasks { |
---|
68 | # (no argument) |
---|
69 | my $RUNNER = FCM::Admin::Runner->instance(); |
---|
70 | my @svn_projects = get_projects_from_svn_live(); |
---|
71 | my @trac_projects = get_projects_from_trac_live(); |
---|
72 | my $user_ref = undef; |
---|
73 | $RUNNER->run_continue( |
---|
74 | "retrieving user accounts", |
---|
75 | sub {$user_ref = get_users(); 1;}, |
---|
76 | ); |
---|
77 | if (defined($user_ref)) { |
---|
78 | if ($CONFIG->get_svn_passwd_file()) { |
---|
79 | $RUNNER->run_continue( |
---|
80 | "updating SVN user accounts", |
---|
81 | sub {manage_users_in_svn_passwd($user_ref)}, |
---|
82 | ); |
---|
83 | } |
---|
84 | if ($CONFIG->get_trac_passwd_file()) { |
---|
85 | $RUNNER->run_continue( |
---|
86 | "updating Trac user accounts", |
---|
87 | sub {manage_users_in_trac_passwd($user_ref)}, |
---|
88 | ); |
---|
89 | } |
---|
90 | for my $project (@trac_projects) { |
---|
91 | $RUNNER->run_continue( |
---|
92 | "updating Trac accounts in $project", |
---|
93 | sub {manage_users_in_trac_db_of($project, $user_ref)}, |
---|
94 | ); |
---|
95 | } |
---|
96 | } |
---|
97 | for my $project (@svn_projects) { |
---|
98 | $RUNNER->run_continue( |
---|
99 | "housekeep SVN repository logs for $project", |
---|
100 | sub {housekeep_svn_hook_logs($project)}, |
---|
101 | ); |
---|
102 | $RUNNER->run_continue( |
---|
103 | "backing up SVN repository for $project", |
---|
104 | sub {backup_svn_repository({}, $project)}, |
---|
105 | ); |
---|
106 | } |
---|
107 | for my $project (@trac_projects) { |
---|
108 | $RUNNER->run_continue( |
---|
109 | "backing up Trac environment for $project", |
---|
110 | sub {backup_trac_environment({}, $project)}, |
---|
111 | ); |
---|
112 | } |
---|
113 | $RUNNER->run_continue("backing up Trac files", \&backup_trac_files); |
---|
114 | } |
---|
115 | |
---|
116 | __END__ |
---|
117 | |
---|
118 | =head1 NAME |
---|
119 | |
---|
120 | fcm-daily-update |
---|
121 | |
---|
122 | =head1 SYNOPSIS |
---|
123 | |
---|
124 | fcm-daily-update |
---|
125 | |
---|
126 | =head1 DESCRIPTION |
---|
127 | |
---|
128 | This program performs the daily update for the FCM system. |
---|
129 | |
---|
130 | =head1 COPYRIGHT |
---|
131 | |
---|
132 | Copyright (C) 2006-2021 British Crown (Met Office) & Contributors. |
---|
133 | |
---|
134 | =cut |
---|