move update_db_config to util

This commit is contained in:
2026-04-19 13:05:32 +02:00
parent 10bffc0fbc
commit 31d2b422cb
2 changed files with 43 additions and 43 deletions

View File

@ -15,6 +15,8 @@ sub notify {
system( 'curl', '-H', "Authorization: Bearer $ntfy_token",
'-d', $msg, "$ntfy_url/$ntfy_topic" );
sleep(1);
}
sub notify_file {
@ -25,6 +27,40 @@ sub notify_file {
'-T', $file, '-H', "Filename: $file",
"$ntfy_url/$ntfy_topic"
);
sleep(1);
}
sub rewrite_file {
my ( $file, $matches, $replacement ) = @_;
open( my $readhandle, '<', $file ) or die "failed to open $file: $!";
my @lines;
my $found = 0;
while ( my $line = <$readhandle> ) {
if ( index( $line, $matches ) != -1 ) {
$line = $replacement;
$found = 1;
}
push @lines, $line;
}
close($readhandle) or die "failed to close $file: $!";
die "no line containing $matches found in $file" unless $found;
open( my $writehandle, '>', $file ) or die "failed to open $file: $!";
print $writehandle @lines or die "failed to write $file: $!";
close($writehandle) or die "failed to close $file: $!";
say "Updated $file with $replacement";
}
sub cpu_count {
open( my $handle, '/proc/cpuinfo' ) or die "Can't open cpuinfo: $!\n";
my $count = scalar( map /^processor/, <$handle> );
close $handle;
return $count;
}
sub find_files {