2024-07-16 23:49:24 +02:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use v5.38.2;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use File::Basename qw/dirname/;
|
|
|
|
use Cwd 'abs_path';
|
|
|
|
|
|
|
|
if ($> != 0) {
|
|
|
|
die 'You must be root.';
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
eval {
|
2024-07-19 20:01:15 +02:00
|
|
|
# install_if_new_wireguard();
|
|
|
|
install_if_new_whitelist();
|
2024-07-16 23:49:24 +02:00
|
|
|
sleep 15;
|
|
|
|
};
|
|
|
|
if ($@) {
|
|
|
|
warn $@;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-19 20:01:15 +02:00
|
|
|
sub install_from_script($script, $output_file) {
|
|
|
|
my $script_abs = abs_path(dirname(__FILE__). '/'. $script);
|
|
|
|
my $user = 'sergio';
|
|
|
|
open my $fh, '-|', 'sudo', '-i', '-u', $user, 'perl', $script_abs;
|
2024-07-16 23:49:24 +02:00
|
|
|
my $contents = join '', <$fh>;
|
|
|
|
my $output_exists;
|
|
|
|
open $fh, '<', $output_file and ($output_exists = 1);
|
|
|
|
my $contents_output_file = '';
|
|
|
|
$contents_output_file = join '', <$fh> if $output_exists;
|
|
|
|
if ($contents ne $contents_output_file) {
|
|
|
|
say 'Writting new file';
|
2024-07-19 20:01:15 +02:00
|
|
|
say "Writting new file for $script -> $output_file";;
|
|
|
|
system 'mkdir', '-p', dirname($output_file);
|
2024-07-16 23:49:24 +02:00
|
|
|
open $fh, '>', $output_file;
|
|
|
|
print $fh $contents;
|
2024-07-19 20:01:15 +02:00
|
|
|
return 1;
|
2024-07-16 23:49:24 +02:00
|
|
|
}
|
2024-07-19 20:01:15 +02:00
|
|
|
say "Files equal for $script -> $output_file";;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub install_if_new_wireguard {
|
|
|
|
system 'systemctl', 'restart', 'wg-quick@wg0' if install_from_script('get_wg_config.pl', '/etc/wireguard/wg5.conf');
|
|
|
|
}
|
|
|
|
|
|
|
|
sub install_if_new_whitelist {
|
|
|
|
install_from_script('get_whitelist_json.pl', '/etc/geyser-console/whitelist.json');
|
2024-07-16 23:49:24 +02:00
|
|
|
}
|