version 1.95, 2024/08/05 13:36:59
|
version 1.96, 2024/11/26 22:08:36
|
Line 2979 sub check_systemd_update {
|
Line 2979 sub check_systemd_update {
|
if (-d '/etc/systemd/system/'.$service.'.d') { |
if (-d '/etc/systemd/system/'.$service.'.d') { |
if (-e '/etc/systemd/system/'.$service.'.d/override.conf') { |
if (-e '/etc/systemd/system/'.$service.'.d/override.conf') { |
if (open(my $fh,'<','/etc/systemd/system/'.$service.'.d/override.conf')) { |
if (open(my $fh,'<','/etc/systemd/system/'.$service.'.d/override.conf')) { |
my ($inservice,$addservice,$protectoff,$linenum,$change,@lines); |
my ($category,$addservice,$protectoff,$linenum,$change, |
|
%lines,@move,@nocat,@ordered); |
|
$linenum = 0; |
while (my $entry = <$fh>) { |
while (my $entry = <$fh>) { |
$linenum ++; |
$linenum ++; |
chomp($entry); |
chomp($entry); |
if ($entry eq '[Service]') { |
if ($entry =~ /^\s*\[([^\]]+)\]\s*$/) { |
if (!$protectoff) { |
$category = $1; |
$inservice = $linenum; |
if ($category =~ /^Service$/i) { |
push(@lines,$entry); |
push(@ordered,'Service'); |
} else { |
} else { |
$addservice = 1; |
push(@ordered,$category); |
next; |
|
} |
} |
} |
} elsif ($entry =~ /^ProtectHome\s*=\s*([\w-]+)\s*$/) { |
if ($entry =~ /^ProtectHome\s*=\s*([\w-]+)\s*$/) { |
|
my $value = $1; |
my $value = $1; |
if ($protectoff) { |
next if ($protectoff); |
next; |
if (lc($value) eq 'no') { |
if (lc($value) eq 'no') { |
if ($category =~ /^Service$/i) { |
$protectoff = $linenum; |
push(@{$lines{'Service'}},$entry); |
push(@lines,$entry); |
|
} else { |
} else { |
if ($protectoff) { |
push(@move,$entry); |
next; |
$change = $linenum; |
} else { |
|
push(@lines,'ProtectHome=no'); |
|
$protectoff = $linenum; |
|
$change = $linenum; |
|
} |
|
} |
} |
|
} else { |
|
if ($category =~ /^Service$/i) { |
|
push(@{$lines{'Service'}},'ProtectHome=no'); |
|
} else { |
|
push(@move,'ProtectHome=no'); |
|
} |
|
$change = $linenum; |
|
} |
|
$protectoff = $linenum; |
|
} else { |
|
next if ($entry =~ /^\s*$/); |
|
if ($category =~ /^Service$/i) { |
|
push(@{$lines{'Service'}},$entry); |
|
} elsif ($category ne '') { |
|
push(@{$lines{$category}},$entry); |
|
} else { |
|
push(@nocat,$entry); |
} |
} |
} |
} |
} |
} |
close($fh); |
close($fh); |
|
unless (grep(/^Service$/,@ordered)) { |
|
$addservice = 1; |
|
unshift(@ordered,'Service'); |
|
} |
|
if (!$protectoff) { |
|
push(@{$lines{'Service'}},'ProtectHome=no'); |
|
} |
if ($addservice || $change || !$protectoff) { |
if ($addservice || $change || !$protectoff) { |
if (open(my $fh,'>','/etc/systemd/system/'.$service.'.d/override.conf')) { |
if (open(my $fh,'>','/etc/systemd/system/'.$service.'.d/override.conf')) { |
if ($addservice) { |
if (@ordered) { |
print $fh "[Service]\n"; |
foreach my $category (@ordered) { |
|
print $fh "[$category]\n"; |
|
if (ref($lines{$category}) eq 'ARRAY') { |
|
foreach my $item (@{$lines{$category}}) { |
|
print $fh "$item\n"; |
|
} |
|
} |
|
if ($category eq 'Service') { |
|
if (@move) { |
|
foreach my $item (@move) { |
|
if ($item =~ /^ProtectHome\s*=\s*no\s*$/i) { |
|
unless (grep/^ProtectHome\s*=\s*no\s*$/i,@{$lines{$category}}) { |
|
print $fh "$item\n"; |
|
} |
|
} else { |
|
print $fh "$item\n"; |
|
} |
|
} |
|
} |
|
} |
|
print $fh "\n"; |
|
} |
} |
} |
foreach my $entry (@lines) { |
if (@nocat) { |
print $fh "$entry\n"; |
foreach my $item (@nocat) { |
|
print $fh "$item\n"; |
|
} |
} |
} |
close($fh); |
close($fh); |
print_and_log('Updated /etc/systemd/system/'.$service.'.d/override.conf'); |
print_and_log('Updated /etc/systemd/system/'.$service.'.d/override.conf'); |