extras/breakpad_upload_crash
author Vincent Tondellier <tonton+hg@team1664.org>
Sun, 18 Dec 2016 21:53:46 +0100
changeset 123 56f9cb30ded9
parent 111 f827f3c50dcf
permissions -rwxr-xr-x
Also display search box on the index page
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
111
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     1
#!/usr/bin/env perl
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     2
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     3
use strict;
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     4
use warnings;
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     5
use Mojo::UserAgent;
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     6
use Mojo::Util qw/slurp dumper/;
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     7
use File::Basename;
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     8
use v5.10;
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     9
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    10
my $ua = Mojo::UserAgent->new;
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    11
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    12
my $url = shift @ARGV;
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    13
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    14
foreach my $extra(@ARGV) {
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    15
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    16
    my ($filename, $dirs, $suffix) = fileparse($extra, ".extra");
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    17
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    18
    my $hash = { upload_file_minidump => { file => "$dirs$filename.dmp" } };
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    19
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    20
    open(my $fh, "<", $extra);
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    21
    foreach my $l(<$fh>) {
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    22
        my ($k, $v) = split('=', $l, 2);
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    23
        chomp $k;
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    24
        chomp $v;
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    25
        $hash->{$k} = $v;
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    26
    }
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    27
    close $fh;
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    28
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    29
    my $tx = $ua->post($url => form => $hash);
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    30
    if(my $res = $tx->success) {
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    31
        say $res->body;
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    32
    } else {
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    33
        my $err = $tx->error;
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    34
        if($err->{code}) {
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    35
            warn "$err->{code} response for $extra: $err->{message}\n" . dumper $hash;
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    36
        } else {
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    37
            warn "Connection error: $err->{message}";
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    38
        }
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    39
    }
f827f3c50dcf Add examples (config, systemd and uploader)
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    40
}