source: LMDZ6/branches/Amaury_dev/tools/fcm/sbin/fcm-commit-update @ 5099

Last change on this file since 5099 was 5095, checked in by abarral, 4 months ago

Revert cosp*/ from the trunk, as it's external code
Add missing bits from FCM2 source

  • Property svn:executable set to *
File size: 4.1 KB
RevLine 
[5095]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
21use strict;
22use warnings;
23
24use FindBin;
25use lib "$FindBin::Bin/../lib";
26use File::Basename qw{basename};
27use File::Spec;
28
29use FCM::Admin::Config;
30use FCM::Admin::Runner;
31use FCM::Admin::System qw{
32    distribute_wc
33    filter_projects
34    get_projects_from_svn_live
35    install_svn_hook
36};
37use FCM::Admin::Util qw{
38    run_mkpath
39    run_rmtree
40    run_svn_info
41    run_svn_update
42    write_file
43};
44use Getopt::Long qw{GetOptions};
45use Pod::Usage qw{pod2usage};
46use Text::ParseWords qw{shellwords};
47
48# ------------------------------------------------------------------------------
49my $CONFIG = FCM::Admin::Config->instance();
50my %PATTERN_OF = (
51    q{}      => qr{.*}xms,
52    SRC_HOOK => qr{svn-hooks/}xms,
53);
54
55if (!caller()) {
56    main(@ARGV);
57}
58
59# ------------------------------------------------------------------------------
60# The main logic.
61sub main {
62    local(@ARGV) = @_;
63    my %option;
64    my $result = GetOptions(
65        \%option,
66        q{help|usage|h},
67        q{force},
68    );
69    if (!$result) {
70        pod2usage(1);
71    }
72    if (exists($option{help})) {
73        pod2usage(q{-verbose} => 1);
74    }
75    create_lock() || return;
76    my $RUNNER = FCM::Admin::Runner->instance();
77    my $is_force = $option{'force'};
78    UPDATE:
79    while (1) {
80        my @updates;
81        for my $source_key (shellwords($CONFIG->get_mirror_keys())) {
82            my $method = "get_$source_key";
83            push(@updates, run_svn_update($CONFIG->$method()));
84        }
85        if (!$is_force && !@updates) {
86            last UPDATE;
87        }
88        if ($is_force || grep {$_ =~ $PATTERN_OF{'SRC_HOOK'}} @updates) {
89            $RUNNER->run(
90                '(re-)installing hook scripts',
91                sub {
92                    for my $project (get_projects_from_svn_live()) {
93                        install_svn_hook($project);
94                    }
95                    return 1;
96                }
97            );
98        }
99        if ($is_force || grep {$_ =~ $PATTERN_OF{q{}}} @updates) {
100            $RUNNER->run(
101                'distributing FCM to standard locations', \&distribute_wc);
102        }
103        $is_force = 0;
104    }
105}
106
107# ------------------------------------------------------------------------------
108# Creates a lock. Returns true on success. Removes lock when program finishes.
109our $LOCK;
110sub create_lock {
111    my $home = (getpwuid($<))[7];
112    $LOCK = File::Spec->catfile($home, sprintf(".%s.lock", basename($0)));
113    if (-e $LOCK) {
114        $LOCK = undef;
115        return;
116    }
117    return run_mkpath($LOCK);
118    END {
119        if ($LOCK) {
120            run_rmtree($LOCK);
121        }
122    }
123}
124
125__END__
126
127=head1 NAME
128
129fcm-commit-update
130
131=head1 SYNOPSIS
132
133    fcm-commit-update
134
135=head1 DESCRIPTION
136
137This program performs the post-commit update for the FCM system. It runs
138continuously until no more update is available. It prevent another copy from
139running by creating a lock. If another copy detects a lock, it exits without
140doing anything.
141
142=head1 OPTIONS
143
144=over 4
145
146=item --force
147
148Force an update.
149
150=back
151
152=head1 ARGUMENTS
153
154=over 4
155
156=item REPOS-NAME
157
158The name of the repository invoking this program.
159
160=item LOG-DIR-PATH
161
162The path to the log directory.
163
164=back
165
166=head1 COPYRIGHT
167
168Copyright (C) 2006-2021 British Crown (Met Office) & Contributors.
169
170=cut
Note: See TracBrowser for help on using the repository browser.