| 1 | # -*- perl -*- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Author: Slaven Rezic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # Copyright (C) 2017,2018,2020 Slaven Rezic. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # This package is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # Mail: slaven@rezic.de | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # WWW: http://www.rezic.de/eserte/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | package Doit::Locale; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | our $VERSION = '0.024'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use Doit::Log; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | sub new { bless {}, shift } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | sub functions { qw(locale_enable_locale) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
functions: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | sub locale_enable_locale { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | my($self, $locale) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
locale_enable_locale: not called CC=21 SCAR=61.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | my %locale; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | if (ref $locale eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | %locale = map{($_,1)} @$locale; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | %locale = ($locale => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # Is locale already present? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | my $is_locale_present = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | open my $fh, '-|', 'locale', '-a' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | or error "Error while running 'locale -a': $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | while(<$fh>) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | chomp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ($locale{$_}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | close $fh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | or error "Error while running 'locale -a': $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if ($is_locale_present->()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | return 0; # no change | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # locale-gen (e.g. Ubuntu 12.03) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if (-x "/usr/sbin/locale-gen" && !-e "/etc/locale.gen") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-x "/usr/sbin/locale-gen" and not -e "/etc/locale.gen"
MC/DC0%0/2
-x "/usr/sbin/locale-gen" and not -e "/etc/locale.gen"
-x "/usr/sbin/locale-gen"
not -e "/etc/locale.gen"
Truth table0%0/3
A and not(B)
A= -x "/usr/sbin/locale-gen"B= not -e "/etc/locale.gen"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | $self->system('locale-gen', $locale->[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # /etc/locale.gen (e.g. Debian and Debian-like) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if (-e "/etc/locale.gen") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $all_locales = '(' . join('|', map { quotemeta $_ } keys %locale) . ')'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | my $changes = $self->change_file("/etc/locale.gen", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | {match => qr{^#\s+$all_locales(\s|$)}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | action => sub { $_[0] =~ s{^#\s+}{}; }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if (!$changes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | error "Cannot find prepared locale '$locale' in /etc/locale.gen"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $self->system('locale-gen'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # localedef (e.g RedHat, CentOS) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if (-x "/usr/bin/localedef" && -e "/etc/redhat-release") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-x "/usr/bin/localedef" and -e "/etc/redhat-release"
MC/DC0%0/2
-x "/usr/bin/localedef" and -e "/etc/redhat-release"
-x "/usr/bin/localedef"
-e "/etc/redhat-release"
Truth table0%0/3
A and B
A= -x "/usr/bin/localedef"B= -e "/etc/redhat-release"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # It also exists on Debian-based systems, but works differently there. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my $use_glibc_langpack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if (open my $fh, "/etc/redhat-release") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my $line = <$fh>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$line =~ /^Fedora release (\d+) / and $1 >= 28 or $line =~ /^CentOS Linux release (\d+)/ and $1 >= 8
$line =~ /^Fedora release (\d+) / and $1 >= 28
$line =~ /^CentOS Linux release (\d+)/ and $1 >= 8
MC/DC0%0/4
$line =~ /^Fedora release (\d+) / and $1 >= 28 or $line =~ /^CentOS Linux release (\d+)/ and $1 >= 8
$line =~ /^Fedora release (\d+) /
$1 >= 28
$line =~ /^CentOS Linux release (\d+)/
$1 >= 8
Truth table0%0/7
A and B or C and D
A= $line =~ /^Fedora release (\d+) /B= $1 >= 28C= $line =~ /^CentOS Linux release (\d+)/D= $1 >= 8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | ($line =~ /^Fedora release (\d+) / && $1 >= 28) # XXX since when we should take this path? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | || ($line =~ /^CentOS Linux release (\d+)/ && $1 >= 8) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $use_glibc_langpack = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | TRY_LOCALE: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if ($use_glibc_langpack) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if ((keys(%locale))[0] =~ m{^([^_]+)}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $lang = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # XXX requires a previous add_component("rpm"); should be done automatically! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $package = 'glibc-langpack-'.$lang; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | eval { $self->rpm_install_packages($package) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if (!$@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | last TRY_LOCALE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | push @errors, "Installing $package failed: $@"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | for my $try_locale (sort keys %locale) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if (my($lang_country, $charset) = $try_locale =~ m{^(.*)\.(.*)$}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | my $stderr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | eval { $self->open3({errref => \$stderr}, '/usr/bin/localedef', '-c', '-i', $lang_country, '-f', $charset, $try_locale) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if (!$@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | last TRY_LOCALE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # an error, but maybe successful? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | if ($is_locale_present->()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | last TRY_LOCALE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | push @errors, "Can't add '$try_locale': $stderr"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | push @errors, "Can't parse '$try_locale' as lang_COUNTRY.charset"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | error "Can't install locale. Errors:\n" . join("\n", @errors); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # not implemented elsewhere | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | error "Don't know how to enable locales on this system"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||