Skip to content

Commit

Permalink
Use LC_ALL=C
Browse files Browse the repository at this point in the history
  • Loading branch information
juniorsysadmin committed Dec 15, 2014
1 parent 2447a5c commit 9a7f570
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
11 changes: 4 additions & 7 deletions manifests/force.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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}'"
}
}

Expand Down
6 changes: 3 additions & 3 deletions spec/defines/force_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

0 comments on commit 9a7f570

Please sign in to comment.