]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - vendor/update
Sync helpop chmodes s and p with docs
[user/henk/code/inspircd.git] / vendor / update
1 #!/usr/bin/env perl
2 #
3 # InspIRCd -- Internet Relay Chat Daemon
4 #
5 #   Copyright (C) 2020 Sadie Powell <sadie@witchery.services>
6 #
7 # This file is part of InspIRCd.  InspIRCd is free software: you can
8 # redistribute it and/or modify it under the terms of the GNU General Public
9 # License as published by the Free Software Foundation, version 2.
10 #
11 # This program is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14 # details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19
20
21 use v5.10.0;
22 use strict;
23 use warnings FATAL => qw(all);
24
25 use File::Basename        qw(basename dirname);
26 use File::Copy            qw(move);
27 use File::Spec::Functions qw(abs2rel catdir catfile);
28 use File::Temp            qw(tempdir);
29 use FindBin               qw($RealDir);
30 use POSIX                 qw(strftime);
31 use TOML                  qw(from_toml);
32
33 use lib dirname $RealDir;
34 use make::common;
35 use make::console;
36
37 my $config = catfile $RealDir, 'update.toml';
38 open(my $fh, $config) or print_error "unable to read $config: $!";
39 my $contents = do { local $/; <$fh> };
40 close $fh;
41
42 my ($data, $error) = from_toml $contents;
43 print_error "unable to parse $config: $!" if $error;
44
45 while (my ($name, $info) = each %{$data}) {
46         say console_format "Updating <|GREEN $name|> ...";
47
48         my $unpackdir = File::Temp->newdir;
49         my $vendordir = catdir $RealDir, $name;
50         my $success = 0;
51         if (defined $info->{git}) {
52                 $success ||= execute 'git', 'clone', $info->{git}, $unpackdir;
53                 chomp(my $tag = `git -C $unpackdir describe --abbrev=0 --tags HEAD 2>/dev/null`) unless $success;
54                 $success ||= execute 'git', '-C', $unpackdir, 'checkout', $tag if $tag;
55                 chomp($info->{version} = `git -C $unpackdir describe --always --tags HEAD 2>/dev/null`);
56         } elsif (defined $info->{tarball}) {
57                 my $tarball = catfile $unpackdir, basename $info->{tarball};
58                 $success ||= execute 'wget', '--output-document', $tarball, $info->{tarball};
59                 $success ||= execute 'tar', 'fx', $tarball, '-C', $unpackdir, '--strip-components', 1;
60         } else {
61                 print_error "unable to update $name; no git or tarball specified!";
62         }
63         print_error "unable to update $name: download failed!" if $success;
64
65         unlink $vendordir;
66         my $glob = $info->{files} or print_error "unable to update $name: no file glob specified!";
67         for my $file (glob catfile $unpackdir, $glob) {
68                 my $pathname = abs2rel $file, $unpackdir;
69                 for (my $i = 0; $i < ($info->{depth} // 0); ++$i) {
70                         $pathname =~ s/[^\/]+\///;
71                 }
72                 my $filename = catfile $vendordir, $pathname;
73                 my $dirname = dirname $filename;
74                 create_directory $dirname, 0750;
75                 move $file, $filename;
76         }
77 }
78
79 my $readme = catfile $RealDir, 'README.md';
80 open($fh, $readme) or print_error "unable to read $readme: $!";
81 $contents = do { local $/; <$fh> };
82 close $fh;
83
84 open($fh, '>', $readme) or print_error "unable to write $readme: $!";
85 print $fh $contents =~ s/\n\#\#.*//rs;
86 for my $name (sort keys %{$data}) {
87         my $info = $data->{$name};
88         printf $fh "\n## %s\n\n", $name;
89         printf $fh "**Author** &mdash; [%s](mailto:%s)\n\n", $info->{author}, $info->{email} if $info->{email};
90         printf $fh "**Author** &mdash; %s\n\n", $info->{author} unless $info->{email};
91         printf $fh "**License** &mdash; %s\n\n", $info->{license};
92         printf $fh "**Version** &mdash; %s\n\n", $info->{version};
93         my $website = $info->{website} // $info->{git};
94         printf $fh "**Website** &mdash; [%s](%s)\n", $website, $website;
95 }
96 close $fh;