HashUtil.pm: reverse order of hmac_sha1 arguments
[girocco/readme.git] / toolbox / create_projects_bom.pl
blob8abcd0878954c70603db832658321fcef73d5cbe
1 #!/usr/bin/perl
3 # create_projects_bom.pl - generate list of files to backup
4 # Copyright (C) 2020 Kyle J. McKay. All rights reserved.
5 # License GPLv2+: GNU GPL version 2 or later.
6 # www.gnu.org/licenses/gpl-2.0.html
7 # This is free software: you are free to change and redistribute it.
8 # There is NO WARRANTY, to the extent permitted by law.
10 use strict;
11 use warnings;
12 use vars qw($VERSION);
13 BEGIN {*VERSION = \'1.0.0'}
14 use lib "__BASEDIR__";
15 use Girocco::Config;
16 use Girocco::CLIUtil;
17 use Girocco::Project;
19 exit(&main(@ARGV)||0);
21 my @projparts;
22 BEGIN {@projparts = qw(
23 .bypass
24 .bypass_fetch
25 .last_refresh
26 .no_blob_plain
27 .noconfig
28 .nofetch
29 .nogc
30 .nohooks
31 HEAD
32 README.html
33 config
34 ctags
35 description
36 info
37 info/lastactivity
38 mob
39 mob/HEAD
40 mob/config
41 mob/description
42 mob/hooks
43 mob/info
44 mob/objects
45 mob/packed-refs
46 mob/refs
47 mob/refs/heads
48 mob/refs/mob
49 objects
50 objects/info
51 objects/info/alternates
52 packed-refs
53 private
54 private/HEAD
55 private/config
56 private/gc.pid
57 private/objects
58 private/refs
59 refs
62 sub list_files($$) {
63 my ($rdir, $pdir) = @_;
64 my $odir = "$rdir/$pdir";
65 opendir LISTDIR, "$odir" or return;
66 my @tags = grep { !/^\./ && !/[,\s\/\\]/ && ! -l "$odir/$_" && -f "$odir/$_" } readdir(LISTDIR);
67 closedir LISTDIR;
68 print "$pdir/$_\n" foreach sort({lc($a) cmp lc($b) || $a cmp $b} @tags);
71 sub bom_for_project($) {
72 my $rroot = $Girocco::Config::reporoot;
73 my $proj = shift;
74 print "$proj.git\n";
75 -l "$rroot/$proj.git" and return;
77 # For each entry from @projparts that exists, output
78 # a line. BUT, if it exists AND it's a symlink, SKIP
79 # outputting a line for anything beneath it that's also
80 # in @projparts.
82 my %links = ();
83 my $test = "$rroot/$proj.git";
84 foreach (@projparts) {
85 my $idx = index($_, "/");
86 next if $idx > 0 && $links{substr($_, 0, $idx)};
87 if (-l "$test/$_") {
88 $links{$_} = 1;
89 print "$proj.git/$_\n";
90 next;
91 } elsif ($_ eq "packed-refs") {
92 next;
93 } elsif (-e "$test/$_") {
94 print "$proj.git/$_\n";
95 list_files($rroot, "$proj.git/$_") if $_ eq "ctags";
100 sub main {
101 local *ARGV = \@_;
102 my %projects = map({$_ => 1} Girocco::Project::get_full_list());
103 my @names;
104 my $rroot = $Girocco::Config::reporoot;
105 if (@ARGV) {
106 my @list = ();
107 foreach (@ARGV) {
108 s/\.git$//i;
109 $_ ne "" or next;
110 $projects{$_} || (-l "$rroot/$_.git" && -d "$rroot/$_.git") or
111 die "no such project: $_\n";
112 push(@list, $_);
114 my %list = map({$_ => 1} @list);
115 @names = sort({lc($a) cmp lc($b) || $a cmp $b} keys(%list));
116 } else {
117 if (opendir REPOROOT, $rroot) {
118 my @links = grep {
119 /^[^._]/ && s/\.git$//i &&
120 -l "$rroot/$_.git" && -d "$rroot/$_.git"
121 } readdir(REPOROOT);
122 closedir REPOROOT;
123 $projects{$_} = 1 foreach @links;
125 @names = sort({lc($a) cmp lc($b) || $a cmp $b} keys(%projects));
127 @names or die "no projects specified\n";
128 #print map("$_\n", @names);
129 bom_for_project($_) foreach @names;
130 exit 0;