#!/usr/bin/env perl

use warnings;
use strict;
use File::Basename;
use v5.16;

my $hostname = `hostname`;
chomp $hostname;
$hostname =~ s/[.]fi[.]muni[.]cz//;

if ( !$hostname || $hostname =~ /iso/ || $hostname !~ /^[a-z0-9-]+$/ ) {
    say STDERR "Invalid hostname $hostname";
    exit 1;
}

my $key = $hostname =~ s/^([a-z]+)[0-9]*$/$1/r;
my $dirname = dirname(__FILE__);

chdir "$dirname/_debpkgs";

my $file = "$hostname.sh";
$file = "$key.sh" if not -f $file;
if ( not -f $file ) {
    say STDERR "Did not find install script for $hostname";
    exit 2;
}

exec { '/usr/bin/env' } "env", "bash", $file;
die "Exec failed";
