File: clean-mr-repos

package info (click to toggle)
pkg-perl-tools 0.82
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 796 kB
  • sloc: sh: 3,255; perl: 3,239; makefile: 142; python: 18
file content (114 lines) | stat: -rwxr-xr-x 2,793 bytes parent folder | download | duplicates (2)
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
110
111
112
113
114
#!/usr/bin/perl

use strict;
use warnings;
use autodie;
use File::Path 'remove_tree';
use File::Spec;
use Getopt::Long;
use feature 'say';

my ($help, $force);
GetOptions(
    'help|h'  => \$help,
    'force|f' => \$force,
) or usage();

sub usage {
    say "dpt-clean-mr-repos: find repos in packages/ not included in .mrconfig.packages";
    say "  --force: remove obsolete repos";
    say "  --help:  this text";
    exit !$help;
}

usage() if $help;

my $dpt_packages = $ENV{'DPT_PACKAGES'};
die "Required configuration variable DPT_PACKAGES is not set
in ~/.dpt.conf or ~/.config/dpt.conf or in your environment.\n" unless $dpt_packages;
$dpt_packages =~ s/~/$ENV{'HOME'}/;
die "No directory called '$dpt_packages' found: $!" unless -d $dpt_packages;

my $mrconfig = File::Spec->catfile("$dpt_packages", '..', '.mrconfig.packages');
die "Cannot find your $mrconfig, exiting.\nTry to run 'dpt salsa mrconfig'.\n" unless -e $mrconfig;

# read in known packages from .mrconfig.packages
my %cfg;
open my $fh, '<', $mrconfig;
while (<$fh>) {
    next unless /^\[packages\/(.*)\]$/;
    $cfg{$1} = 1;
}
close $fh;

# walk through packages/, identify extra ones
opendir (my $dh, $dpt_packages);
while (my $pkg = readdir $dh) {
    # skip non-directories, like tarballs, build logs etc
    next unless -d "$dpt_packages/$pkg";
    # skip dotfiles
    next if $pkg =~ /^\./;

    unless ( -d "$dpt_packages/$pkg/.git" ) {
        say "Skipping '$dpt_packages/$pkg' -- not a Git repository";
        next;
    }

    if (!exists $cfg{$pkg}) {
        if ($force) {
            say "REMOVING $pkg";
            remove_tree("$dpt_packages/$pkg");
        } else {
            say $pkg;
        }
    }
}
closedir $dh;

__END__

=head1 NAME

dpt-clean-mr-repos - remove local repos which are gone from salsa.debian.org

=head1 SYNOPSIS

B<dpt clean-mr-repos> I<[--force]> I<[--help]>

=head1 DESCRIPTION

B<dpt clean-mr-repos> checks which repos are locally in the I<DPT_PACKAGES>
directory that do no longer exist in F<.mrconfig.packages>, i.e. which are
no longer on salsa.debian.org in the group with active packages. The script
needs B<dpt salsa mrconfig> to be run beforehand as this creates
F<.mrconfig.packages>. Removal of obsolete repos happens only with
I<--force>.

=head1 OPTIONS

=over

=item B<--help>

Show this help.

=item B<--force>

Actually remove the local repositories. Without I<--force> they are just
listed.

=back

=head1 CONFIGURATION

B<dpt clean-mr-repos> uses the C<DPT_PACKAGES> environment variable.

See L<dpt-config(5)> for details.

=head1 COPYRIGHT AND LICENSE

    Copyright 2017, Florian Schlichting <fsfs@debian.org>
              2018, Damyan Ivanov <dmn@debian.org>
              2018-2024, gregor herrmann <gregoa@debian.org>

    License: Artistic or GPL-1+