2020-01-17 22:45:56 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
#
|
|
|
|
# InspIRCd -- Internet Relay Chat Daemon
|
|
|
|
#
|
|
|
|
# Copyright (C) 2020 Sadie Powell <sadie@witchery.services>
|
|
|
|
#
|
|
|
|
# This file is part of InspIRCd. InspIRCd is free software: you can
|
|
|
|
# redistribute it and/or modify it under the terms of the GNU General Public
|
|
|
|
# License as published by the Free Software Foundation, version 2.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
|
2021-02-28 19:20:08 +00:00
|
|
|
use v5.26.0;
|
2020-01-17 22:45:56 +00:00
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
|
|
|
|
use File::Basename qw(basename dirname);
|
|
|
|
use File::Copy qw(move);
|
|
|
|
use File::Spec::Functions qw(abs2rel catdir catfile);
|
|
|
|
use File::Temp qw(tempdir);
|
|
|
|
use FindBin qw($RealDir);
|
|
|
|
use POSIX qw(strftime);
|
|
|
|
use TOML qw(from_toml);
|
|
|
|
|
|
|
|
use lib dirname $RealDir;
|
|
|
|
use make::common;
|
|
|
|
use make::console;
|
|
|
|
|
|
|
|
my $config = catfile $RealDir, 'update.toml';
|
|
|
|
open(my $fh, $config) or print_error "unable to read $config: $!";
|
|
|
|
my $contents = do { local $/; <$fh> };
|
|
|
|
close $fh;
|
|
|
|
|
|
|
|
my ($data, $error) = from_toml $contents;
|
|
|
|
print_error "unable to parse $config: $!" if $error;
|
|
|
|
|
2020-07-30 14:29:11 +01:00
|
|
|
while (my ($name, $info) = each %{$data}) {
|
2021-01-27 16:47:08 +00:00
|
|
|
say console_format "Updating <|GREEN $name|> ...";
|
2020-01-17 22:45:56 +00:00
|
|
|
|
|
|
|
my $unpackdir = File::Temp->newdir;
|
|
|
|
my $vendordir = catdir $RealDir, $name;
|
|
|
|
my $success = 0;
|
|
|
|
if (defined $info->{git}) {
|
2022-11-16 18:10:18 +00:00
|
|
|
my @extra_args;
|
|
|
|
push @extra_args, '--branch', $info->{branch} if defined $info->{branch};
|
|
|
|
$success ||= execute 'git', 'clone', @extra_args, $info->{git}, $unpackdir;
|
2020-01-17 22:45:56 +00:00
|
|
|
chomp(my $tag = `git -C $unpackdir describe --abbrev=0 --tags HEAD 2>/dev/null`) unless $success;
|
2020-01-18 14:03:18 +00:00
|
|
|
$success ||= execute 'git', '-C', $unpackdir, 'checkout', $tag if $tag;
|
2020-01-17 22:45:56 +00:00
|
|
|
chomp($info->{version} = `git -C $unpackdir describe --always --tags HEAD 2>/dev/null`);
|
2023-02-21 17:17:50 +00:00
|
|
|
if (defined $info->{patches}) {
|
|
|
|
my $patches = catfile($unpackdir, $info->{patches});
|
|
|
|
for my $patch (glob $patches) {
|
|
|
|
$success |= execute 'git', '-C', $unpackdir, 'apply', $patch;
|
|
|
|
}
|
|
|
|
}
|
2020-01-17 22:45:56 +00:00
|
|
|
} elsif (defined $info->{tarball}) {
|
|
|
|
my $tarball = catfile $unpackdir, basename $info->{tarball};
|
2020-01-18 14:03:18 +00:00
|
|
|
$success ||= execute 'wget', '--output-document', $tarball, $info->{tarball};
|
|
|
|
$success ||= execute 'tar', 'fx', $tarball, '-C', $unpackdir, '--strip-components', 1;
|
2020-01-17 22:45:56 +00:00
|
|
|
} else {
|
|
|
|
print_error "unable to update $name; no git or tarball specified!";
|
|
|
|
}
|
|
|
|
print_error "unable to update $name: download failed!" if $success;
|
|
|
|
|
|
|
|
unlink $vendordir;
|
|
|
|
my $glob = $info->{files} or print_error "unable to update $name: no file glob specified!";
|
|
|
|
for my $file (glob catfile $unpackdir, $glob) {
|
|
|
|
my $pathname = abs2rel $file, $unpackdir;
|
|
|
|
for (my $i = 0; $i < ($info->{depth} // 0); ++$i) {
|
|
|
|
$pathname =~ s/[^\/]+\///;
|
|
|
|
}
|
|
|
|
my $filename = catfile $vendordir, $pathname;
|
|
|
|
my $dirname = dirname $filename;
|
|
|
|
create_directory $dirname, 0750;
|
|
|
|
move $file, $filename;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my $readme = catfile $RealDir, 'README.md';
|
|
|
|
open($fh, $readme) or print_error "unable to read $readme: $!";
|
|
|
|
$contents = do { local $/; <$fh> };
|
|
|
|
close $fh;
|
|
|
|
|
|
|
|
open($fh, '>', $readme) or print_error "unable to write $readme: $!";
|
|
|
|
print $fh $contents =~ s/\n\#\#.*//rs;
|
2020-07-30 14:29:11 +01:00
|
|
|
for my $name (sort keys %{$data}) {
|
2020-01-17 22:45:56 +00:00
|
|
|
my $info = $data->{$name};
|
|
|
|
printf $fh "\n## %s\n\n", $name;
|
|
|
|
printf $fh "**Author** — [%s](mailto:%s)\n\n", $info->{author}, $info->{email} if $info->{email};
|
|
|
|
printf $fh "**Author** — %s\n\n", $info->{author} unless $info->{email};
|
|
|
|
printf $fh "**License** — %s\n\n", $info->{license};
|
|
|
|
printf $fh "**Version** — %s\n\n", $info->{version};
|
|
|
|
my $website = $info->{website} // $info->{git};
|
|
|
|
printf $fh "**Website** — [%s](%s)\n", $website, $website;
|
|
|
|
}
|
2020-07-30 14:29:11 +01:00
|
|
|
close $fh;
|