[BACK]Return to post_dmesg_to_nycbug CVS log [TXT][DIR] Up to [local] / openbsd / update_openbsd

File: [local] / openbsd / update_openbsd / post_dmesg_to_nycbug (download)

Revision 1.11, Sun Dec 16 23:49:03 2018 UTC (5 years, 4 months ago) by andrew
Branch: MAIN
CVS Tags: HEAD
Changes since 1.10: +1 -1 lines

Mention email and nick that will be posted to nycbug

#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
use feature 'signatures';
no warnings 'experimental::signatures';

use Sys::Hostname;
use HTTP::Tiny;

# This script posts your OpenBSD dmesg to the NYC*BUG dmesg archive.

sub sysctl (@s) {
    open my $de, '-|', qw( sysctl -n ), @s or die $!;
    my $s = join ' ', split /\s+/s,
        do { local $/ = undef; readline $de };
    close $de or die $!;
    return $s;
}

my $nickname = "$ENV{USER}";
my $email    = "$ENV{USER}\@" . hostname();

my @sysctls = (
    [qw( hw.vendor hw.product hw.version  )],
    [qw( hw.model )],
);

my $description = "@ARGV";

unless ($description) {
    while ( @sysctls and not $description ) {
        $description = sysctl @{ shift @sysctls };
    }

    if (my $version = sysctl qw( kern.version )) {
	my $machine = sysctl qw( hw.machine );
        $version =~ s/\)\K.*/ $machine/;
        $description = "$version on $description";
    }
}

print "'$description'\nAbout to post as $email ($nickname), OK? ";
readline STDIN;

open my $dm, '<', '/var/run/dmesg.boot' or die $!;
my $dmesg = do { local $/ = undef; readline $dm };
close $dm;

# Remove leftover cruft from previous boots
$dmesg =~ s/^.*\n(OpenBSD )/$1/s;

my $res = HTTP::Tiny->new->post_form(
    'http://dmesgd.nycbug.org/index.cgi',
    {   action      => 'dmesgd',
        do          => 'addd',
        nickname    => $nickname,
        email       => $email,
        description => $description,
        dmesg       => $dmesg,
    }
);

say $res->{success}
    ? 'Sent dmesg'
    : "Unable to send dmesg: $res->{status} $res->{reason}";

say $res->{content};