From 9a7f570b6d6f605b1a7c1f49b841e8a62a7bb1d8 Mon Sep 17 00:00:00 2001 From: juniorsysadmin Date: Mon, 15 Dec 2014 21:58:54 +1100 Subject: [PATCH] Use LC_ALL=C --- manifests/force.pp | 11 ++++------- spec/defines/force_spec.rb | 6 +++--- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/manifests/force.pp b/manifests/force.pp index 0ac48b5215..44b84536d6 100644 --- a/manifests/force.pp +++ b/manifests/force.pp @@ -41,18 +41,15 @@ $install_check = "/usr/bin/dpkg -s ${name} | grep -q 'Status: install'" } else { # If the installed version and candidate version differ, this check - # returns 1 (false). When the package exists, the first three lines of - # the apt-cache policy command have package name, installed version and - # candidate version in that order. We cannot simply grep for the words - # Installed and Candidate because non-English locales will have - # different equivalents. - $install_check = "/usr/bin/test \$(/usr/bin/apt-cache policy -t ${release} ${name} | /bin/sed -n 2,3p | /usr/bin/awk '{ print \$2 }' | /usr/bin/uniq | /usr/bin/wc -l) -eq 1" + # returns 1 (false). We must set LC_ALL to C because non-English locales + # will have different equivalents for the words Installed and Candidate. + $install_check = "LC_ALL=C /usr/bin/test \$(/usr/bin/apt-cache policy -t ${release} ${name} | /bin/grep -E 'Installed|Candidate' | /usr/bin/uniq -s 14 | /usr/bin/wc -l) -eq 1" } } else { if $release == false { $install_check = "/usr/bin/dpkg -s ${name} | grep -q 'Version: ${version}'" } else { - $install_check = "/usr/bin/apt-cache policy -t ${release} ${name} | /bin/sed '2!d' | /usr/bin/awk '{ print \$2 }' | /bin/grep -q '${version}'" + $install_check = "LC_ALL=C /usr/bin/apt-cache policy -t ${release} ${name} | /bin/grep -q 'Installed: ${version}'" } } diff --git a/spec/defines/force_spec.rb b/spec/defines/force_spec.rb index 333771010d..ad0b7f816d 100644 --- a/spec/defines/force_spec.rb +++ b/spec/defines/force_spec.rb @@ -31,7 +31,7 @@ default_params.merge(:release => 'testing') end it { should contain_exec("/usr/bin/apt-get -y -t #{params[:release]} install #{title}").with( - :unless => "/usr/bin/test \$(/usr/bin/apt-cache policy -t #{params[:release]} #{title} | /bin/sed -n 2,3p | /usr/bin/awk '{ print \$2 }' | /usr/bin/uniq | /usr/bin/wc -l) -eq 1" + :unless => "LC_ALL=C /usr/bin/test \$(/usr/bin/apt-cache policy -t #{params[:release]} #{title} | /bin/grep -E 'Installed|Candidate' | /usr/bin/uniq -s 14 | /usr/bin/wc -l) -eq 1" ) } end @@ -82,7 +82,7 @@ ) end it { should contain_exec("/usr/bin/apt-get -y -t #{params[:release]} install #{title}=1").with( - :unless => "/usr/bin/apt-cache policy -t #{params[:release]} #{title} | /bin/sed '2!d' | /usr/bin/awk '{ print \$2 }' | /bin/grep -q '#{params[:version]}'" + :unless => "LC_ALL=C /usr/bin/apt-cache policy -t #{params[:release]} #{title} | /bin/grep -q 'Installed: #{params[:version]}'" ) } end @@ -96,7 +96,7 @@ ) end it { should contain_exec('/usr/bin/apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confmiss" -t testing install my_package=1').with( - :unless => "/usr/bin/apt-cache policy -t #{params[:release]} #{title} | /bin/sed '2!d' | /usr/bin/awk '{ print \$2 }' | /bin/grep -q '#{params[:version]}'" + :unless => "LC_ALL=C /usr/bin/apt-cache policy -t #{params[:release]} #{title} | /bin/grep -q 'Installed: #{params[:version]}'" ) } end end