3 # InspIRCd -- Internet Relay Chat Daemon
5 # Copyright (C) 2020 Sadie Powell <sadie@witchery.services>
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.
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
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/>.
23 unless (-f 'configure') {
24 print "Error: $0 must be run from the main source directory!\n";
31 use warnings FATAL => qw(all);
33 use File::Basename qw(basename dirname);
34 use File::Copy qw(move);
35 use File::Spec::Functions qw(abs2rel catdir catfile);
36 use File::Temp qw(tempdir);
37 use FindBin qw($RealDir);
38 use POSIX qw(strftime);
39 use TOML qw(from_toml);
41 use lib dirname $RealDir;
45 my $config = catfile $RealDir, 'update.toml';
46 open(my $fh, $config) or print_error "unable to read $config: $!";
47 my $contents = do { local $/; <$fh> };
50 my ($data, $error) = from_toml $contents;
51 print_error "unable to parse $config: $!" if $error;
53 while (my ($name, $info) = each %{$data}) {
54 print_format "Updating <|GREEN $name|> ...\n";
56 my $unpackdir = File::Temp->newdir;
57 my $vendordir = catdir $RealDir, $name;
59 if (defined $info->{git}) {
60 $success ||= execute 'git', 'clone', $info->{git}, $unpackdir;
61 chomp(my $tag = `git -C $unpackdir describe --abbrev=0 --tags HEAD 2>/dev/null`) unless $success;
62 $success ||= execute 'git', '-C', $unpackdir, 'checkout', $tag if $tag;
63 chomp($info->{version} = `git -C $unpackdir describe --always --tags HEAD 2>/dev/null`);
64 } elsif (defined $info->{tarball}) {
65 my $tarball = catfile $unpackdir, basename $info->{tarball};
66 $success ||= execute 'wget', '--output-document', $tarball, $info->{tarball};
67 $success ||= execute 'tar', 'fx', $tarball, '-C', $unpackdir, '--strip-components', 1;
69 print_error "unable to update $name; no git or tarball specified!";
71 print_error "unable to update $name: download failed!" if $success;
74 my $glob = $info->{files} or print_error "unable to update $name: no file glob specified!";
75 for my $file (glob catfile $unpackdir, $glob) {
76 my $pathname = abs2rel $file, $unpackdir;
77 for (my $i = 0; $i < ($info->{depth} // 0); ++$i) {
78 $pathname =~ s/[^\/]+\///;
80 my $filename = catfile $vendordir, $pathname;
81 my $dirname = dirname $filename;
82 create_directory $dirname, 0750;
83 move $file, $filename;
87 my $readme = catfile $RealDir, 'README.md';
88 open($fh, $readme) or print_error "unable to read $readme: $!";
89 $contents = do { local $/; <$fh> };
92 open($fh, '>', $readme) or print_error "unable to write $readme: $!";
93 print $fh $contents =~ s/\n\#\#.*//rs;
94 for my $name (sort keys %{$data}) {
95 my $info = $data->{$name};
96 printf $fh "\n## %s\n\n", $name;
97 printf $fh "**Author** — [%s](mailto:%s)\n\n", $info->{author}, $info->{email} if $info->{email};
98 printf $fh "**Author** — %s\n\n", $info->{author} unless $info->{email};
99 printf $fh "**License** — %s\n\n", $info->{license};
100 printf $fh "**Version** — %s\n\n", $info->{version};
101 my $website = $info->{website} // $info->{git};
102 printf $fh "**Website** — [%s](%s)\n", $website, $website;