Skip to content

Commit ff489a6

Browse files
committed
Try to ensure LANG is valid
If Ruby starts without a LANG env var, it will assume locale "C". This is a non-UTF-8 locale, and usually not the system default. If commands print UTF-8 characters, Ruby will fail to correctly parse them if it wasn't started with a valid locale. The main scenario we want to account for is when a privilege escalation command such as sudo or powerbroker has elevated a shell, but stripped all environment variables out of it. If that happened, we want to try and set the default system locale, which should be in /etc/default/locale.
1 parent e21d954 commit ff489a6

6 files changed

+16
-4
lines changed

tasks/agent_upgrade.sh

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3+
# Try and ensure locale is correctly configured
4+
[ -z "${LANG}" ] && export LANG=$(localectl status | sed -n 's/.* LANG=\(.*\)/\1/p')
5+
36
export USER=$(id -un)
47
export HOME=$(getent passwd "$USER" | cut -d : -f 6)
58
export PATH="/opt/puppetlabs/bin:${PATH}"

tasks/enable_replica.sh

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3+
# Try and ensure locale is correctly configured
4+
[ -z "${LANG}" ] && export LANG=$(localectl status | sed -n 's/.* LANG=\(.*\)/\1/p')
5+
36
USER=$(id -un)
47
HOME=$(getent passwd "$USER" | cut -d : -f 6)
58

tasks/pe_install.sh

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3+
# Try and ensure locale is correctly configured
4+
[ -z "${LANG}" ] && export LANG=$(localectl status | sed -n 's/.* LANG=\(.*\)/\1/p')
5+
36
# This stanza configures PuppetDB to quickly fail on start. This is desirable
47
# in situations where PuppetDB WILL fail, such as when PostgreSQL is not yet
58
# configured, and we don't want to let PuppetDB wait five minutes before
@@ -20,10 +23,6 @@ pedir=$(tar -tf "$PT_tarball" | head -n 1 | xargs dirname)
2023

2124
tar -C "$tgzdir" -xzf "$PT_tarball"
2225

23-
export LANG=en_US.UTF-8
24-
export LANGUAGE=en_US.UTF-8
25-
export LC_ALL=en_US.UTF-8
26-
2726
if [ ! -z "$PT_peconf" ]; then
2827
/bin/bash "${tgzdir}/${pedir}/puppet-enterprise-installer" -y -c "$PT_peconf"
2928
else

tasks/provision_replica.sh

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3+
# Try and ensure locale is correctly configured
4+
[ -z "${LANG}" ] && export LANG=$(localectl status | sed -n 's/.* LANG=\(.*\)/\1/p')
5+
36
export USER=$(id -un)
47
export HOME=$(getent passwd "$USER" | cut -d : -f 6)
58
export PATH="/opt/puppetlabs/bin:${PATH}"

tasks/puppet_runonce.sh

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/bin/bash
22

3+
# Try and ensure locale is correctly configured
4+
[ -z "${LANG}" ] && export LANG=$(localectl status | sed -n 's/.* LANG=\(.*\)/\1/p')
5+
6+
# Parse noop parameter
37
[ "$PT_noop" = "true" ] && NOOP_FLAG="--noop" || unset NOOP_FLAG
48

59
# Wait for up to five minutes for an in-progress Puppet agent run to complete

tasks/wait_until_service_ready.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)